mirror of
https://github.com/ascribe/onion.git
synced 2024-06-30 21:52:08 +02:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
import React from 'react';
|
|
|
|
let InputCheckbox = React.createClass({
|
|
propTypes: {
|
|
defaultValue: React.PropTypes.bool,
|
|
children: React.PropTypes.oneOfType([
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
React.PropTypes.element
|
|
]).isRequired
|
|
},
|
|
getDefaultProps() {
|
|
return {
|
|
defaultValue: false
|
|
};
|
|
},
|
|
|
|
getInitialState() {
|
|
return {
|
|
//show: false
|
|
value: this.props.defaultValue
|
|
};
|
|
},
|
|
|
|
onChange: function(event) {
|
|
let newValue = !this.state.value;
|
|
event.target.value = newValue;
|
|
this.props.onChange(event);
|
|
event.stopPropagation();
|
|
this.setState({value: newValue});
|
|
},
|
|
|
|
render() {
|
|
return (
|
|
<span
|
|
onClick={this.onChange}>
|
|
<input
|
|
type="checkbox"
|
|
ref="checkbox"
|
|
onChange={this.onChange}
|
|
checked={this.state.value}/>
|
|
<span className="checkbox">
|
|
{this.props.children}
|
|
</span>
|
|
</span>
|
|
);
|
|
}
|
|
});
|
|
|
|
export default InputCheckbox; |