-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathToggleField.jsx
More file actions
75 lines (69 loc) · 4.57 KB
/
ToggleField.jsx
File metadata and controls
75 lines (69 loc) · 4.57 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { useState, useRef } from "react";
import FilterEnableCheckbox from "./FilterEnableCheckbox";
import Tooltip from "./ToolTip";
export default function ToggleField(props) {
let paramFieldType = "toggle";
const [filterEnabled, setFilterEnabled] = useState(props.filterEnable);
//eslint-disable-next-line @typescript-eslint/no-unused-vars
const [prop1Set, setprop1Set] = useState((props.initialValues == "both") || (props.initialValues == String(props.fields[0]).charAt(0).toLowerCase() + String(props.fields[0]).slice(1)));
//eslint-disable-next-line @typescript-eslint/no-unused-vars
const [prop2Set, setprop2Set] = useState((props.initialValues=="both") || (props.initialValues==String(props.fields[1]).charAt(0).toLowerCase() + String(props.fields[1]).slice(1)));
const checkboxRef = useRef(null);
return (
<div className="m-2">
<div className="mb-2 text-white flex items-center justify-between">
<div className="flex-none items-center">
<h3>{String(props.filterName).charAt(0).toUpperCase() + String(props.filterName).slice(1)}</h3>
</div>
<div className="flex-auto pl-3 pt-2">
<Tooltip
text={props.description}
position={"right"}
/>
</div>
<FilterEnableCheckbox
ref={checkboxRef}
initialValue={filterEnabled}
onToggle={() => { setFilterEnabled(!filterEnabled); props.HandleFilterEnable([props.filterName, !filterEnabled]); }}
/>
</div>
<div className={`${filterEnabled ? "opacity-100" : "opacity-50"}`} onClick={() => {
if (!filterEnabled && checkboxRef.current) {
checkboxRef.current.click();
}
}}>
<div className="flex sm:flex-row rounded-lg shadow-2xs w-full items-center
font-medium text-white bg-[#aba8e0] ">
<label className="flex-auto py-3 px-4 inline-flex gap-x-2 -mt-px -ms-px
first:rounded-t-md last:rounded-b-md sm:first:rounded-s-md sm:mt-0 sm:first:ms-0 s
m:first:rounded-se-none sm:last:rounded-es-none sm:last:rounded-e-md text-sm font-medium
focus:z-10 border border-gray-200 shadow-2xs cursor-pointer">
<input type="checkbox" defaultChecked={prop1Set} className="sr-only peer" onChange={() => props.HandleFilterChange([paramFieldType, props.filterName, props.fields[0]])} />
<div className="relative w-11 h-6 bg-gray-200 peer-focus:outline-none
peer-focus:ring-4 peer-focus:ring-blue-300
rounded-full peer peer-checked:after:translate-x-full
rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-['']
after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border
after:rounded-full after:h-5 after:w-5 after:transition-all
peer-checked:bg-violet-500 "></div>
<span>{props.fields[0]}</span>
</label>
<label className="flex-auto py-3 px-4 inline-flex gap-x-2 -mt-px -ms-px
first:rounded-t-md last:rounded-b-md sm:first:rounded-s-md sm:mt-0 sm:first:ms-0 s
m:first:rounded-se-none sm:last:rounded-es-none sm:last:rounded-e-md text-sm font-medium
focus:z-10 border border-gray-200 shadow-2xs cursor-pointer">
<input type="checkbox" defaultChecked={prop2Set} className="sr-only peer" onChange={() => props.HandleFilterChange([paramFieldType, props.filterName, props.fields[1]])} />
<div className="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4
peer-focus:ring-blue-300 rounded-full peer
peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full
peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px]
after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full
after:h-5 after:w-5 after:transition-all peer-checked:bg-violet-500
"></div>
<span>{props.fields[1]}</span>
</label>
</div>
</div>
</div>
);
}