-
Notifications
You must be signed in to change notification settings - Fork 0
/
Toggle.tsx
54 lines (52 loc) · 1.47 KB
/
Toggle.tsx
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
import clsx from 'clsx/lite';
export default function Toggle({
checked,
onCheckChange,
}: {
readonly checked: boolean;
readonly onCheckChange: () => void;
}) {
// Inspired from https://codepen.io/lhermann/pen/EBGZRZ
return (
<div className="flex items-center justify-center w-full">
<label htmlFor="toggleB" className="flex items-center cursor-pointer">
<div className="mr-3 font-medium">
local <div className="i-tabler-device-laptop ml-2" />
</div>
{/* <!-- toggle --> */}
<div className="relative">
{/* <!-- input --> */}
<input
checked={checked}
type="checkbox"
id="toggleB"
className="sr-only"
onChange={(event) => {
console.log(event);
onCheckChange();
}}
/>
{/* <!-- line --> */}
<div
className={clsx(
'block w-14 h-8 rounded-full',
checked ? 'bg-blue-700' : 'bg-green-700',
)}
/>
{/* <!-- dot --> */}
<div
className={clsx(
'absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition',
checked && 'translate-x-full bg-gray-7',
)}
/>
</div>
{/* <!-- label --> */}
<div className="ml-3 font-medium">
<div className="i-tabler-world mr-2" />
internet
</div>
</label>
</div>
);
}