forked from recodehive/recode-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
87 lines (83 loc) · 3.37 KB
/
Copy pathindex.tsx
File metadata and controls
87 lines (83 loc) · 3.37 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
87
import React from "react";
import { useSafeColorMode } from "@site/src/utils/useSafeColorMode";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
export default function ColorModeToggle(): JSX.Element {
const { colorMode } = useSafeColorMode();
// Safe setColorMode that works with DOM
const setColorMode = (mode: "light" | "dark") => {
if (!ExecutionEnvironment.canUseDOM) return;
document.documentElement.setAttribute("data-theme", mode);
// Also trigger Docusaurus's internal theme change if available
try {
const { setColorMode: docusaurusSetColorMode } = require("@docusaurus/theme-common");
docusaurusSetColorMode(mode);
} catch (e) {
// Fallback: just set the DOM attribute
}
};
const toggleColorMode = () => {
const newMode = colorMode === "dark" ? "light" : "dark";
// Only use Docusaurus's setColorMode - it handles everything properly
setColorMode(newMode);
};
return (
<button
onClick={toggleColorMode}
aria-label={`Switch to ${colorMode === "dark" ? "light" : "dark"} mode`}
style={{
background: "none",
border: "none",
cursor: "pointer",
padding: "8px",
borderRadius: "6px",
display: "flex",
alignItems: "center",
justifyContent: "center",
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
transform: "scale(1)",
}}
onMouseEnter={(e) => {
e.currentTarget.style.transform = "scale(1.1)";
}}
onMouseLeave={(e) => {
e.currentTarget.style.transform = "scale(1)";
}}
>
<div
style={{
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
opacity: 1,
transform: "rotate(0deg)",
}}
>
{colorMode === "dark" ? (
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="currentColor"
style={{
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
filter: "drop-shadow(0 0 4px rgba(255, 193, 7, 0.3))",
}}
>
<path d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z" />
</svg>
) : (
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="currentColor"
style={{
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
filter: "drop-shadow(0 0 4px rgba(99, 102, 241, 0.3))",
}}
>
<path d="M9.528 1.718a.75.75 0 01.162.819A8.97 8.97 0 009 6a9 9 0 009 9 8.97 8.97 0 003.463-.69.75.75 0 01.981.98 10.503 10.503 0 01-9.694 6.46c-5.799 0-10.5-4.701-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 01.818.162z" />
</svg>
)}
</div>
</button>
);
}