-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathCheckbox.js
More file actions
44 lines (38 loc) · 1.24 KB
/
Copy pathCheckbox.js
File metadata and controls
44 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const blacklist = require('blacklist');
const classNames = require('classnames');
const React = require('react');
const Checkbox = React.createClass({
propTypes: {
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
autoFocus: React.PropTypes.bool,
indeterminate: React.PropTypes.bool,
inline: React.PropTypes.bool,
label: React.PropTypes.string,
style: React.PropTypes.object,
title: React.PropTypes.string,
},
componentDidMount () {
this.setIndeterminate(this.props.indeterminate);
},
componentWillReceiveProps (nextProps) {
this.setIndeterminate(nextProps.indeterminate);
},
setIndeterminate (value) {
this.refs.target.indeterminate = value;
},
render() {
let componentClass = classNames('Checkbox', {
'Checkbox--disabled': this.props.disabled,
'Checkbox--inline': this.props.inline,
}, this.props.className);
let props = blacklist(this.props, 'className', 'label', 'style', 'title');
return (
<label className={componentClass} style={this.props.style} title={this.props.title}>
<input ref="target" type="checkbox" className="Checkbox__input" {...props} />
{this.props.label && <span className="Checkbox__label">{this.props.label}</span>}
</label>
);
}
});
module.exports = Checkbox;