forked from elastic/search-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooleanFacet.js
More file actions
58 lines (52 loc) · 1.66 KB
/
Copy pathBooleanFacet.js
File metadata and controls
58 lines (52 loc) · 1.66 KB
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
import PropTypes from "prop-types";
import React from "react";
import { FacetValue, FilterValue } from "./types";
import { appendClassName } from "./view-helpers";
function BooleanFacet({
className,
label,
options,
onChange,
onRemove,
values
}) {
const trueOptions = options.find(option => option.value === "true");
if (!trueOptions) return null;
const isSelected = values.includes("true");
const apply = () => onChange("true");
const remove = () => onRemove("true");
const toggle = () => {
isSelected ? remove() : apply();
};
return (
<fieldset className={appendClassName("sui-facet", className)}>
<legend className="sui-facet__title">{label}</legend>
<div className="sui-boolean-facet">
<div className={"sui-boolean-facet__option-input-wrapper"}>
<label className="sui-boolean-facet__option-label">
<div className="sui-boolean-facet__option-input-wrapper">
<input
className="sui-boolean-facet__checkbox"
type="checkbox"
onChange={toggle}
/>
<span className="sui-boolean-facet__input-text">{label}</span>
</div>
<span className="sui-boolean-facet__option-count">
{trueOptions.count}
</span>
</label>
</div>
</div>
</fieldset>
);
}
BooleanFacet.propTypes = {
className: PropTypes.string,
label: PropTypes.string.isRequired,
onRemove: PropTypes.func.isRequired,
options: PropTypes.arrayOf(FacetValue).isRequired,
values: PropTypes.arrayOf(FilterValue).isRequired,
onChange: PropTypes.func.isRequired
};
export default BooleanFacet;