open-prompt / src /components /ui /theme-toggle.tsx
GitHub Action
Automated sync to Hugging Face
bcce530
"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>
)
}