forked from sjoerdapp/styleguide2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch.js
More file actions
50 lines (42 loc) · 1.01 KB
/
Copy pathSwitch.js
File metadata and controls
50 lines (42 loc) · 1.01 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
50
var React = require('react');
import classNames from 'classnames/bind';
import styles from './Switch.styl';
const cx = classNames.bind(styles);
var blacklist = require('blacklist');
module.exports = React.createClass({
getDefaultProps () {
return {
disabled: false,
checked: false,
};
},
getInitialState: function() {
return {
isChecked: this.props.checked
};
},
handleChange: function(event) {
this.setState({
isChecked: !this.state.isChecked // flip boolean value
}, function() {
console.log(this.state);
}.bind(this));
},
render () {
// classes
var componentClass = cx(
'switch',
'switch-' + this.props.size,
this.props.className
);
// props
var props = blacklist(this.props,'size', 'className');
props.className = componentClass;
return (
<div className={componentClass}>
<input type="checkbox" {...props} checked={this.state.isChecked} onChange={this.handleChange}></input>
<label></label>
</div>
)
},
});