all files / src/explore/components/controls/ CheckboxControl.jsx

93.75% Statements 15/16
100% Branches 0/0
33.33% Functions 1/3
93.33% Lines 14/15
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 42 43                                                          
import React from 'react';
import PropTypes from 'prop-types';
import ControlHeader from '../ControlHeader';
import Checkbox from '../../../components/Checkbox';
 
const propTypes = {
  name: PropTypes.string.isRequired,
  value: PropTypes.bool,
  label: PropTypes.string,
  description: PropTypes.string,
  onChange: PropTypes.func,
};
 
const defaultProps = {
  value: false,
  onChange: () => {},
};
 
const checkboxStyle = { paddingRight: '5px' };
 
export default class CheckboxControl extends React.Component {
  onChange() {
    this.props.onChange(!this.props.value);
  }
  render() {
    return (
      <ControlHeader
        {...this.props}
        leftNode={
          <Checkbox
            onChange={this.onChange.bind(this)}
            style={checkboxStyle}
            checked={!!this.props.value}
          />
        }
      />
    );
  }
}
 
CheckboxControl.propTypes = propTypes;
CheckboxControl.defaultProps = defaultProps;