forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeToggle.tsx
More file actions
55 lines (49 loc) · 1.63 KB
/
Copy pathThemeToggle.tsx
File metadata and controls
55 lines (49 loc) · 1.63 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
"use client";
import { useEffect } from "react";
import { IconButton, useColorMode } from "@chakra-ui/react";
function SunMoonIcon({ isDark }: { isDark: boolean }) {
return (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M20.5 14.5A8.5 8.5 0 1 1 9.5 3.5a7 7 0 0 0 11 11Z"
fill="currentColor"
opacity={isDark ? 1 : 0}
style={{ transition: "opacity 0.25s ease" }}
/>
<g opacity={isDark ? 0 : 1} style={{ transition: "opacity 0.25s ease" }}>
<circle cx="12" cy="12" r="4.5" fill="currentColor" />
<path
d="M12 2v2.5M12 19.5V22M22 12h-2.5M4.5 12H2M19.07 4.93l-1.77 1.77M6.7 17.3l-1.77 1.77M19.07 19.07l-1.77-1.77M6.7 6.7 4.93 4.93"
stroke="currentColor"
strokeWidth="1.75"
strokeLinecap="round"
/>
</g>
</svg>
);
}
export default function ThemeToggle() {
const { colorMode, toggleColorMode } = useColorMode();
const isDark = colorMode === "dark";
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.code === "KeyD") {
e.preventDefault();
toggleColorMode();
}
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [toggleColorMode]);
return (
<IconButton
aria-label="Toggle colour mode"
icon={<SunMoonIcon isDark={isDark} />}
onClick={toggleColorMode}
variant="ghost"
size="sm"
color="app.text"
_hover={{ bg: "app.surfaceHover", color: "app.accent" }}
/>
);
}