-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathThemeSwitcher.tsx
More file actions
86 lines (80 loc) · 2.41 KB
/
ThemeSwitcher.tsx
File metadata and controls
86 lines (80 loc) · 2.41 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
76
77
78
79
80
81
82
83
84
85
86
import { faPaintBrush } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { memo, useEffect, useState } from "react";
import { useLocation } from "react-router";
import store2 from "store2";
import { THEME_KEY } from "../localStoreConsts.js";
import DialogDropdown from "./DialogDropdown.js";
const ALL_THEMES = [
"", // "Default"
"Light",
"Dark",
"Abyss",
"Acid",
"Aqua",
"Autumn",
"Black",
"Bumblebee",
"Business",
"Caramellatte",
"Cmyk",
"Coffee",
"Corporate",
"Cupcake",
"Cyberpunk",
"Dim",
"Dracula",
"Emerald",
"Fantasy",
"Forest",
"Garden",
"Halloween",
"Lemonade",
"Lofi",
"Luxury",
"Night",
"Nord",
"Pastel",
"Retro",
"Silk",
"Sunset",
"Synthwave",
"Valentine",
"Winter",
"Wireframe",
];
const ThemeSwitcher = memo(() => {
const routerLocation = useLocation();
const [currentTheme, setCurrentTheme] = useState<string>(store2.get(THEME_KEY, ""));
useEffect(() => {
store2.set(THEME_KEY, currentTheme);
// system-derived theme (currentTheme === "") should not set "data-theme" attr
if (currentTheme) {
document.documentElement.setAttribute("data-theme", currentTheme);
} else {
document.documentElement.removeAttribute("data-theme");
}
}, [currentTheme]);
return (
<DialogDropdown
buttonChildren={<FontAwesomeIcon icon={faPaintBrush} />}
buttonStyle="btn-outline btn-primary"
// do not allow theme-switching while on network page due to rendering of reagraph
buttonDisabled={routerLocation.pathname.startsWith("/network")}
>
{ALL_THEMES.map((theme) => (
<li key={theme || "default"}>
<input
type="radio"
name="theme-dropdown"
className={`theme-controller w-full font-normal btn btn-block ${currentTheme === theme.toLowerCase() ? "btn-primary" : "btn-ghost"}`}
aria-label={theme || "Default"}
value={theme.toLowerCase()}
onChange={() => setCurrentTheme(theme.toLowerCase())}
/>
</li>
))}
</DialogDropdown>
);
});
export default ThemeSwitcher;