File size: 2,004 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { translatable } from 'react-instantsearch-core';
import { createClassNames } from '../core/utils';

const cx = createClassNames('CurrentRefinements');

export const CurrentRefinements = ({
  items,
  canRefine,
  refine,
  translate,
  className,
}) => (
  <div className={classNames(cx('', !canRefine && '-noRefinement'), className)}>
    <ul className={cx('list', !canRefine && 'list--noRefinement')}>
      {items.map((item) => (
        <li key={item.label} className={cx('item')}>
          <span className={cx('label')}>{item.label}</span>
          {item.items ? (
            item.items.map((nest) => (
              <span key={nest.label} className={cx('category')}>
                <span className={cx('categoryLabel')}>{nest.label}</span>
                <button
                  className={cx('delete')}
                  onClick={() => refine(nest.value)}
                >
                  {translate('clearFilter', nest)}
                </button>
              </span>
            ))
          ) : (
            <span className={cx('category')}>
              <button
                className={cx('delete')}
                onClick={() => refine(item.value)}
              >
                {translate('clearFilter', item)}
              </button>
            </span>
          )}
        </li>
      ))}
    </ul>
  </div>
);

const itemPropTypes = PropTypes.arrayOf(
  PropTypes.shape({
    label: PropTypes.string.isRequired,
    value: PropTypes.func.isRequired,
    items: (...args) => itemPropTypes(...args),
  })
);

CurrentRefinements.propTypes = {
  items: itemPropTypes.isRequired,
  canRefine: PropTypes.bool.isRequired,
  refine: PropTypes.func.isRequired,
  translate: PropTypes.func.isRequired,
  className: PropTypes.string,
};

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

export default translatable({
  clearFilter: '✕',
})(CurrentRefinements);