-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureSwitch.tsx
More file actions
32 lines (26 loc) · 1.09 KB
/
TemperatureSwitch.tsx
File metadata and controls
32 lines (26 loc) · 1.09 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
import { useState } from "react";
const TemperatureSwitch = () => {
const [isCelsius, setIsCelsius] = useState(true);
const handleSwitch = () => {
setIsCelsius(!isCelsius);
};
return (
<div className="flex items-center">
<span className={`${isCelsius ? 'mr-2' : 'mr-2'}`}>{isCelsius ? 'C°' : 'F°'}</span>
<label htmlFor="toggle" className="flex items-center cursor-pointer">
<div className="relative">
<input
type="checkbox"
id="toggle"
className="sr-only"
checked={isCelsius}
onChange={handleSwitch}
/>
<div className="block bg-gray-600 w-10 h-6 rounded-full"></div>
<div className={`dot absolute left-1 top-1 bg-white w-4 h-4 rounded-full transition transform duration-300 ${isCelsius ? 'translate-x-0' : 'translate-x-4'}`}></div>
</div>
</label>
</div>
)
}
export default TemperatureSwitch