1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/components/ascribe_forms/input_checkbox.js
diminator 3031fcdbe1 Merge remote-tracking branch 'remotes/origin/AD-606-login-returns-this-field-may-not-' into AD-435-hash-locally-for-when-a-artist-do
Conflicts:
	js/components/ascribe_forms/input_checkbox.js
	js/components/ascribe_forms/property.js
2015-07-28 12:11:48 +02:00

62 lines
1.4 KiB
JavaScript

'use strict';
import React from 'react';
let InputCheckbox = React.createClass({
propTypes: {
required: React.PropTypes.bool,
defaultChecked: React.PropTypes.bool,
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
]).isRequired
},
getDefaultProps() {
return {
defaultValue: false
};
},
getInitialState() {
return {
value: this.props.defaultChecked
};
},
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
}
});
},
render() {
return (
<span
onClick={this.onChange}>
<input
type="checkbox"
ref="checkbox"
onChange={this.onChange}
checked={this.state.value}
defaultChecked={this.props.defaultChecked}/>
<span className="checkbox">
{this.props.children}
</span>
</span>
);
}
});
export default InputCheckbox;