forked from elastic/search-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiCheckboxFacet.js
99 lines (92 loc) · 2.84 KB
/
MultiCheckboxFacet.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import PropTypes from "prop-types";
import React from "react";
import { FacetValue } from "./types";
import { appendClassName, getFilterValueDisplay } from "./view-helpers";
function MultiCheckboxFacet({
className,
label,
onMoreClick,
onRemove,
onSelect,
options,
showMore,
showSearch,
onSearch,
searchPlaceholder
}) {
return (
<fieldset className={appendClassName("sui-facet", className)}>
<legend className="sui-facet__title">{label}</legend>
{showSearch && (
<div className="sui-facet-search">
<input
className="sui-facet-search__text-input"
type="search"
placeholder={searchPlaceholder || "Search"}
onChange={e => {
onSearch(e.target.value);
}}
/>
</div>
)}
<div className="sui-multi-checkbox-facet">
{options.length < 1 && <div>No matching options</div>}
{options.map(option => {
const checked = option.selected;
return (
<label
key={`${getFilterValueDisplay(option.value)}`}
htmlFor={`example_facet_${label}${getFilterValueDisplay(
option.value
)}`}
className="sui-multi-checkbox-facet__option-label"
>
<div className="sui-multi-checkbox-facet__option-input-wrapper">
<input
id={`example_facet_${label}${getFilterValueDisplay(
option.value
)}`}
type="checkbox"
className="sui-multi-checkbox-facet__checkbox"
checked={checked}
onChange={() =>
checked ? onRemove(option.value) : onSelect(option.value)
}
/>
<span className="sui-multi-checkbox-facet__input-text">
{getFilterValueDisplay(option.value)}
</span>
</div>
<span className="sui-multi-checkbox-facet__option-count">
{option.count.toLocaleString("en")}
</span>
</label>
);
})}
</div>
{showMore && (
<button
type="button"
className="sui-facet-view-more"
onClick={onMoreClick}
aria-label="Show more options"
>
+ More
</button>
)}
</fieldset>
);
}
MultiCheckboxFacet.propTypes = {
label: PropTypes.string.isRequired,
onMoreClick: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired,
onSelect: PropTypes.func.isRequired,
onSearch: PropTypes.func.isRequired,
options: PropTypes.arrayOf(FacetValue).isRequired,
showMore: PropTypes.bool.isRequired,
className: PropTypes.string,
showSearch: PropTypes.bool,
searchPlaceholder: PropTypes.string
};
export default MultiCheckboxFacet;