"use client" import * as React from "react" import { useRouter } from "next/navigation" import { DialogProps } from "@radix-ui/react-alert-dialog" import { CircleIcon, FileIcon, LaptopIcon, MoonIcon, SunIcon, } from "@radix-ui/react-icons" import { useTheme } from "next-themes" import { docsConfig } from "@/config/docs" import { cn } from "@/lib/utils" import { Button } from "@/registry/new-york/ui/button" import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/registry/new-york/ui/command" export function CommandMenu({ ...props }: DialogProps) { const router = useRouter() const [open, setOpen] = React.useState(false) const { setTheme } = useTheme() React.useEffect(() => { const down = (e: KeyboardEvent) => { if ((e.key === "k" && (e.metaKey || e.ctrlKey)) || e.key === "/") { if ( (e.target instanceof HTMLElement && e.target.isContentEditable) || e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement ) { return } e.preventDefault() setOpen((open) => !open) } } document.addEventListener("keydown", down) return () => document.removeEventListener("keydown", down) }, []) const runCommand = React.useCallback((command: () => unknown) => { setOpen(false) command() }, []) return ( <> No results found. {docsConfig.mainNav .filter((navitem) => !navitem.external) .map((navItem) => ( { runCommand(() => router.push(navItem.href as string)) }} > {navItem.title} ))} {docsConfig.sidebarNav.map((group) => ( {group.items.map((navItem) => ( { runCommand(() => router.push(navItem.href as string)) }} >
{navItem.title}
))}
))} runCommand(() => setTheme("light"))}> Light runCommand(() => setTheme("dark"))}> Dark runCommand(() => setTheme("system"))}> System
) }