File size: 994 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { createClassNames } from '../core/utils';

const cx = createClassNames('ToggleRefinement');

const ToggleRefinement = ({
  currentRefinement,
  label,
  canRefine,
  refine,
  className,
}) => (
  <div className={classNames(cx('', !canRefine && '-noRefinement'), className)}>
    <label className={cx('label')}>
      <input
        className={cx('checkbox')}
        type="checkbox"
        checked={currentRefinement}
        onChange={(event) => refine(event.target.checked)}
      />
      <span className={cx('labelText')}>{label}</span>
    </label>
  </div>
);

ToggleRefinement.propTypes = {
  currentRefinement: PropTypes.bool.isRequired,
  label: PropTypes.string.isRequired,
  canRefine: PropTypes.bool.isRequired,
  refine: PropTypes.func.isRequired,
  className: PropTypes.string,
};

ToggleRefinement.defaultProps = {
  className: '',
};

export default ToggleRefinement;