-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.js
More file actions
49 lines (44 loc) · 1.03 KB
/
Checkbox.js
File metadata and controls
49 lines (44 loc) · 1.03 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
45
46
47
48
49
import React, { PropTypes } from 'react';
import classNames from 'classnames';
import Icon from '../Utils/Icon';
import './Checkbox.scss';
const Checkbox = React.createClass({
propTypes: {
value: PropTypes.bool,
onChange: PropTypes.func,
label: PropTypes.string,
},
toggle(event) {
if (this.props.onChange) {
this.props.onChange({
target: {
value: !this.props.value,
},
});
event.preventDefault();
event.stopPropagation();
}
},
render() {
const className = classNames('Checkbox', {
'Checkbox--checked': this.props.value,
});
let label;
if (this.props.label) {
label = (
<label className="Checkbox-label">
{this.props.label}
</label>
);
}
return (
<div className={className} onClick={this.toggle} onKeyPress={this.toggle} tabIndex="0">
<div className="Checkbox-inner">
<Icon name="checkmark" />
</div>
{label}
</div>
);
},
});
export default Checkbox;