All files / src/container/todo/component CheckboxWithLabel.jsx

100% Statements 5/5
100% Branches 2/2
100% Functions 3/3
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31          1x 1x       1x       1x       2x                        
import React from 'react';
 
export default class CheckboxWithLabel extends React.Component {
 
  constructor(props) {
    super(props);
    this.state = {isChecked: false};
 
    // bind manually because React class components don't auto-bind
    // http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
    this.onChange = this.onChange.bind(this);
  }
 
  onChange() {
    this.setState({isChecked: !this.state.isChecked});
  }
 
  render() {
    return (
      <label>
        <input
          type="checkbox"
          checked={this.state.isChecked}
          onChange={this.onChange}
        />
        {this.state.isChecked ? this.props.labelOn : this.props.labelOff}
      </label>
    )
  }
}