import { Laptop, Moon, Sun } from "lucide-react" import * as React from "react" import { useTheme } from "../theme-provider" import { Button } from "../ui/button" const options = [ { value: "system" as const, label: "System", icon: Laptop }, { value: "light" as const, label: "Light", icon: Sun }, { value: "dark" as const, label: "Dark", icon: Moon }, ] export function ThemeMenu() { const { appearance, setAppearance, inherited } = useTheme() const [open, setOpen] = React.useState(false) const rootRef = React.useRef(null) const firstItemRef = React.useRef(null) const menuId = React.useId() const ActiveIcon = options.find((item) => item.value === appearance)?.icon ?? Laptop React.useEffect(() => { if (!open) return firstItemRef.current?.focus() const closeOnOutsidePointer = (event: PointerEvent) => { if (!rootRef.current?.contains(event.target as Node)) setOpen(false) } const closeOnEscape = (event: KeyboardEvent) => { if (event.key === "Escape") setOpen(false) } document.addEventListener("pointerdown", closeOnOutsidePointer) document.addEventListener("keydown", closeOnEscape) return () => { document.removeEventListener("pointerdown", closeOnOutsidePointer) document.removeEventListener("keydown", closeOnEscape) } }, [open]) if (inherited) return null const label = appearance === "system" ? "System" : appearance === "light" ? "Light" : "Dark" return (
{open ? ( ) : null}
) }