Files
nextjs-startup/components/layout/theme-toggle.tsx
T
Rami Bitar 6376bb3d82 Organize Vertex starter into reusable sections
Use remote logos and avatars, refine landing copy, and document the template structure.
2026-09-15 10:49:07 -04:00

30 lines
1.0 KiB
TypeScript

"use client"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
import { useSyncExternalStore } from "react"
const emptySubscribe = () => () => {}
export function ThemeToggle() {
const mounted = useSyncExternalStore(emptySubscribe, () => true, () => false)
const { resolvedTheme, setTheme } = useTheme()
const isDark = mounted && resolvedTheme === "dark"
return (
<button
type="button"
aria-label={mounted ? `Switch to ${isDark ? "light" : "dark"} theme` : "Toggle theme"}
className="inline-flex size-9 items-center justify-center rounded-sm border bg-background/80 text-muted-foreground transition-colors hover:border-foreground/20 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60"
onClick={() => setTheme(isDark ? "light" : "dark")}
>
{mounted ? (
isDark ? <Sun className="size-4" /> : <Moon className="size-4" />
) : (
<span className="size-4" aria-hidden="true" />
)}
</button>
)
}