-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththeme.jsx
More file actions
41 lines (37 loc) · 1.11 KB
/
theme.jsx
File metadata and controls
41 lines (37 loc) · 1.11 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
import { useState, useEffect } from "react";
import { IoSunny, IoMoon } from "react-icons/io5";
import "./src/theme.css";
const Theme = () => {
const [theme, setTheme] = useState(() => {
return localStorage.getItem("theme") || "light";
});
useEffect(() => {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("theme", theme);
}, [theme]);
return (
<div className="theme-wrapper">
<div
className={`theme-switch ${theme}`}
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
>
<div className="theme-labels w-screen">
<span className={`label ${theme === "light" ? "active pl-[2rem]" : "hidden"}`}>
DAY
</span>
<span className={`label ${theme === "dark" ? "active" : "hidden"}`}>
NIGHT
</span>
</div>
<div className="slider">
{theme === "light" ? (
<IoSunny className="slider-icon" />
) : (
<IoMoon className="slider-icon" />
)}
</div>
</div>
</div>
);
};
export default Theme;