All files / src/components/Checkbox index.jsx

0% Statements 0/49
0% Branches 0/39
0% Functions 0/11
0% Lines 0/14
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 32 33 34 35 36 37 38 39 40 41                                                                                 
import styles from './style.postcss';
 
import React, { PureComponent } from 'react';
import is from 'is_js';
import PropTypes from 'prop-types';
 
class Checkbox extends PureComponent {
  constructor(props) {
    super(props);
    this._handleCheck = this._handleCheck.bind(this);
  }
 
  _handleCheck(e) {
    this.props.onChange(e.target.checked);
  }
 
  render() {
    const { checked, onChange } = this.props;
    return <div className={styles.Checkbox}>
      <input type="checkbox"
          id={this.props.id}
          name={this.props.name}
          value={this.props.value || this.props.id}
          checked={is.existy(checked) ? !! checked : undefined}
          className={styles.Checkbox_input}
          onChange={onChange ? this._handleCheck : null} />
      <label className={styles.Checkbox_label} htmlFor={this.props.id} />
    </div>;
  }
}
 
Checkbox.propTypes = {
  id: PropTypes.string.isRequired,
  name: PropTypes.string,
  value: PropTypes.string,
  checked: PropTypes.bool,
  onChange: PropTypes.func,
};
 
export default Checkbox;