Spaces:
Configuration error
Configuration error
File size: 1,069 Bytes
bcce530 | 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 | "use client"
import * as React from "react"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
export function ThemeToggle() {
const { theme, setTheme } = useTheme()
const [mounted, setMounted] = React.useState(false)
React.useEffect(() => {
setMounted(true)
}, [])
if (!mounted) {
return (
<button className="h-9 w-9 rounded-lg border border-border bg-background flex items-center justify-center">
<span className="sr-only">Toggle theme</span>
</button>
)
}
return (
<button
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
className="h-9 w-9 rounded-lg border border-border bg-background hover:bg-muted flex items-center justify-center transition-colors focus-ring"
aria-label="Toggle theme"
>
{theme === "dark" ? (
<Sun className="h-4 w-4" />
) : (
<Moon className="h-4 w-4" />
)}
</button>
)
}
|