MCPcopy Create free account
hub / github.com/9d8dev/directory / ThemeToggle

Function ThemeToggle

components/theme-toggle.tsx:10–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { Button } from "@/components/ui/button";
9
10export function ThemeToggle() {
11 const { theme, setTheme } = useTheme();
12
13 const toggleTheme = () => {
14 setTheme(theme === "dark" ? "light" : "dark");
15 };
16
17 return (
18 <Button variant="outline" size="icon" onClick={toggleTheme}>
19 <motion.div
20 initial={false}
21 animate={{
22 rotate: theme === "dark" ? -90 : 0,
23 scale: theme === "dark" ? 0 : 1,
24 }}
25 transition={{ duration: 0.3 }}
26 >
27 <Sun className="h-[1.2rem] w-[1.2rem]" />
28 </motion.div>
29 <motion.div
30 initial={false}
31 animate={{
32 rotate: theme === "dark" ? 0 : 90,
33 scale: theme === "dark" ? 1 : 0,
34 }}
35 transition={{ duration: 0.3 }}
36 style={{ position: "absolute" }}
37 >
38 <Moon className="h-[1.2rem] w-[1.2rem]" />
39 </motion.div>
40 <span className="sr-only">Toggle theme</span>
41 </Button>
42 );
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected