forked from sqlchat/sqlchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDarkModeSwitch.tsx
More file actions
29 lines (24 loc) · 765 Bytes
/
DarkModeSwitch.tsx
File metadata and controls
29 lines (24 loc) · 765 Bytes
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
import { useSettingStore } from "@/store";
import useDarkMode from "@/hooks/useDarkmode";
import Icon from "./Icon";
const DarkModeSwitch = () => {
const settingStore = useSettingStore();
const isDarkMode = useDarkMode();
const switchDarkMode = () => {
if (isDarkMode) {
settingStore.setTheme("light");
} else {
settingStore.setTheme("dark");
}
};
const ModeIcon = isDarkMode ? Icon.IoMdMoon : Icon.IoMdSunny;
return (
<button
className="w-10 h-10 p-1 rounded-full flex flex-row justify-center items-center hover:bg-gray-100 dark:hover:bg-zinc-700"
onClick={switchDarkMode}
>
<ModeIcon className="text-gray-600 dark:text-gray-300 w-6 h-auto" />
</button>
);
};
export default DarkModeSwitch;