'use client' import { LaptopIcon, MoonIcon, SunIcon } from 'lucide-react' import { useTheme } from 'next-themes' import { useRouter } from 'next/navigation' import * as React from 'react' import { Button, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, DialogDescription, DialogProps, DialogTitle, } from 'ui' import { gettingStarted } from '@/config/docs' import { getLibraryBlockHref, libraryBlocks, libraryCategories } from '@/config/library' import { useFramework } from '@/context/framework-context' import { cn } from '@/lib/utils' export function CommandMenu({ ...props }: DialogProps) { const router = useRouter() const { framework } = useFramework() 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 ( <> Search the library Find guides, blocks, starter apps, and theme settings. No results found. {gettingStarted.items.map((navItem) => ( runCommand(() => router.push(navItem.href as string))} > {navItem.title} ))} {libraryCategories.map((category) => ( {libraryBlocks .filter((block) => block.category === category.name) .map((block) => ( runCommand(() => { const href = getLibraryBlockHref(block, framework) if (block.external) window.location.assign(href) else router.push(href) }) } > {block.title} ))} ))} runCommand(() => setTheme('light'))}> Light runCommand(() => setTheme('dark'))}> Dark runCommand(() => setTheme('system'))}> System ) }