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

62 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
2015-06-01 13:02:53 +02:00
import React from 'react';
let InputCheckbox = React.createClass({
propTypes: {
2015-07-28 12:03:45 +02:00
required: React.PropTypes.bool,
defaultChecked: React.PropTypes.bool,
2015-07-14 19:53:49 +02:00
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
]).isRequired
},
2015-07-27 14:39:19 +02:00
getDefaultProps() {
return {
2015-07-28 11:32:16 +02:00
defaultValue: false
2015-07-27 14:39:19 +02:00
};
},
2015-06-01 13:02:53 +02:00
getInitialState() {
return {
2015-07-28 12:03:45 +02:00
value: this.props.defaultChecked
2015-06-01 13:02:53 +02:00
};
},
2015-07-10 15:56:54 +02:00
2015-07-28 12:03:45 +02:00
componentDidMount() {
this.props.onChange({
target: {
value: this.state.value
}
});
},
onChange() {
let value = !this.refs.checkbox.getDOMNode().checked;
this.setState({value: value});
this.props.onChange({
target: {
value: value
}
});
2015-06-01 13:02:53 +02:00
},
2015-06-01 13:02:53 +02:00
render() {
return (
2015-07-10 15:56:54 +02:00
<span
2015-07-27 14:39:19 +02:00
onClick={this.onChange}>
<input
type="checkbox"
ref="checkbox"
onChange={this.onChange}
2015-07-28 12:03:45 +02:00
checked={this.state.value}
defaultChecked={this.props.defaultChecked}/>
2015-07-10 15:56:54 +02:00
<span className="checkbox">
2015-07-14 19:53:49 +02:00
{this.props.children}
2015-07-10 15:56:54 +02:00
</span>
</span>
2015-06-01 13:02:53 +02:00
);
}
});
export default InputCheckbox;