2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-01 13:02:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
let InputCheckbox = React.createClass({
|
2015-06-09 16:10:38 +02:00
|
|
|
propTypes: {
|
|
|
|
required: React.PropTypes.string.isRequired,
|
2015-07-14 19:53:49 +02:00
|
|
|
children: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element
|
|
|
|
]).isRequired
|
2015-06-09 16:10:38 +02:00
|
|
|
},
|
2015-06-01 13:02:53 +02:00
|
|
|
|
|
|
|
getInitialState() {
|
2015-06-05 11:06:36 +02:00
|
|
|
return {
|
2015-07-10 15:56:54 +02:00
|
|
|
show: false
|
2015-06-01 13:02:53 +02:00
|
|
|
};
|
|
|
|
},
|
2015-07-10 15:56:54 +02:00
|
|
|
|
2015-07-14 20:35:16 +02:00
|
|
|
handleFocus(event) {
|
2015-07-10 15:56:54 +02:00
|
|
|
this.refs.checkbox.getDOMNode().checked = !this.refs.checkbox.getDOMNode().checked;
|
2015-07-14 20:35:16 +02:00
|
|
|
|
|
|
|
// This is calling property.js's method handleChange which
|
|
|
|
// expects an event object
|
|
|
|
// Since we don't have a valid one, we'll just manipulate the one we get and send
|
|
|
|
// it to handleChange
|
|
|
|
event.target.value = this.refs.checkbox.getDOMNode().checked;
|
|
|
|
this.props.onChange(event);
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2015-07-10 15:56:54 +02:00
|
|
|
this.setState({
|
2015-07-10 18:51:35 +02:00
|
|
|
show: this.refs.checkbox.getDOMNode().checked,
|
|
|
|
value: this.refs.checkbox.getDOMNode().checked
|
2015-07-10 15:56:54 +02:00
|
|
|
});
|
2015-07-14 20:35:16 +02:00
|
|
|
|
2015-06-01 13:02:53 +02:00
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-06-01 13:02:53 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2015-07-10 15:56:54 +02:00
|
|
|
<span
|
|
|
|
onClick={this.handleFocus}
|
|
|
|
onFocus={this.handleFocus}>
|
|
|
|
<input type="checkbox" ref="checkbox"/>
|
|
|
|
<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;
|