All files / checkbox index.js

75% Statements 6/8
100% Branches 4/4
33.33% Functions 1/3
100% Lines 4/4
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64  1x         1x                     1x               42x                                                                            
 
import React from 'react'
 
/**
 * Check box - ic_check_box_24px.svg
 */
const IconCheckbox = () => (
  <svg width='24' height='24' viewBox='0 0 24 24'>
    <path
      d='M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'
    />
  </svg>
)
 
/**
 * Check box outline blank - ic_check_box_outline_blank_24px.svg
 */
const IconCheckboxOutline = () => (
  <svg width='24' height='24' viewBox='0 0 24 24'>
    <path
      d='M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z'
    />
  </svg>
)
 
const Checkbox = ({checked, disabled, label, onChange, name, defaultChecked}) => (
  <label className='Checkbox' title={label}>
    <input
      checked={checked}
      className='Checkbox-input'
      defaultChecked={defaultChecked}
      disabled={disabled}
      name={name}
      onChange={onChange}
      type='checkbox'
    />
    <div className='Checkbox-focus' />
    <div className='Checkbox-icon'>
      {checked || defaultChecked
        ? <IconCheckbox />
        : <IconCheckboxOutline />
      }
    </div>
    <span className='Checkbox-label'>
      {label}
    </span>
  </label>
)
 
Checkbox.propTypes = {
  checked: React.PropTypes.bool,
  defaultChecked: React.PropTypes.bool,
  disabled: React.PropTypes.bool,
  label: React.PropTypes.string,
  onChange: React.PropTypes.func
}
 
Checkbox.defaultProps = {
  disabled: false,
  label: 'Label'
}
 
export default Checkbox