1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_forms/input_checkbox.js

52 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: {
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-01 13:02:53 +02:00
getInitialState() {
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-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;