| 21 | } from "@/components/ui/command"; |
| 22 | |
| 23 | export function CommandMenu({ ...props }: DialogProps) { |
| 24 | const _router = useRouter(); |
| 25 | const [open, setOpen] = React.useState(false); |
| 26 | const { setTheme } = useTheme(); |
| 27 | |
| 28 | React.useEffect(() => { |
| 29 | const down = (e: KeyboardEvent) => { |
| 30 | if (e.key === "k" && (e.metaKey || e.ctrlKey)) { |
| 31 | e.preventDefault(); |
| 32 | setOpen((open) => !open); |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | document.addEventListener("keydown", down); |
| 37 | return () => document.removeEventListener("keydown", down); |
| 38 | }, []); |
| 39 | |
| 40 | const runCommand = React.useCallback((command: () => unknown) => { |
| 41 | setOpen(false); |
| 42 | command(); |
| 43 | }, []); |
| 44 | |
| 45 | return ( |
| 46 | <> |
| 47 | <Button |
| 48 | variant="outline" |
| 49 | className={cn( |
| 50 | "relative h-9 w-full justify-start text-sm text-zinc-500 dark:text-zinc-400 sm:pr-12 md:w-40 lg:w-64", |
| 51 | )} |
| 52 | onClick={() => setOpen(true)} |
| 53 | {...props} |
| 54 | > |
| 55 | <span className="hidden lg:inline-flex">Search documentation...</span> |
| 56 | <span className="inline-flex lg:hidden">Search...</span> |
| 57 | <kbd className="pointer-events-none absolute top-2 right-1.5 hidden h-5 select-none items-center gap-1 rounded border border-zinc-100 bg-zinc-100 px-1.5 font-mono text-[10px] font-medium text-zinc-600 opacity-100 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-400 sm:flex"> |
| 58 | <span className="text-xs">⌘</span>K |
| 59 | </kbd> |
| 60 | </Button> |
| 61 | <CommandDialog open={open} onOpenChange={setOpen}> |
| 62 | <CommandInput placeholder="Type a command or search..." /> |
| 63 | <CommandList> |
| 64 | <CommandEmpty>No results found.</CommandEmpty> |
| 65 | {/* <CommandGroup heading="Links"> |
| 66 | {docsConfig.mainNav |
| 67 | .filter((navitem) => !navitem.external) |
| 68 | .map((navItem) => ( |
| 69 | <CommandItem |
| 70 | key={navItem.href} |
| 71 | onSelect={() => { |
| 72 | runCommand(() => router.push(navItem.href as string)) |
| 73 | }} |
| 74 | > |
| 75 | <File className="w-4 h-4 mr-2" /> |
| 76 | {navItem.title} |
| 77 | </CommandItem> |
| 78 | ))} |
| 79 | </CommandGroup> |
| 80 | <CommandGroup heading="Components"> |