1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 21:52:08 +02:00
onion/js/components/ascribe_forms/input_checkbox.js
2015-07-27 14:39:19 +02:00

52 lines
1.3 KiB
JavaScript

'use strict';
import React from 'react';
let InputCheckbox = React.createClass({
propTypes: {
required: React.PropTypes.string.isRequired,
defaultValue: React.PropTypes.bool,
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
]).isRequired
},
getDefaultProps() {
return {
required: 'required'
};
},
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;