{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-menu",
  "title": "Command Menu",
  "description": "Primitives for a command menu: a search dialog of pages, actions and records that filters as you type or shows results you fetch, with descriptions, shortcuts and a searching state, a search button with ⌘K, and a shortcut hook.",
  "registryDependencies": [
    "button",
    "command",
    "kbd"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/command-menu.tsx",
      "content": "'use client'\n\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type ReactNode, useEffect, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  Command,\n  CommandDialog,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  CommandShortcut,\n} from '@/components/ui/command'\nimport { Kbd } from '@/components/ui/kbd'\n\nimport { cn } from '@/lib/utils'\n\ninterface CommandMenuItem {\n  description?: string\n  href?: string\n  icon?: ReactNode\n  /** Unique across every group. */\n  id: string\n  keywords?: string[]\n  /** Leaves the menu open when picked, for an item that changes what the menu shows. */\n  keepOpen?: boolean\n  label: string\n  /** Shown at the end of the row, such as an order's total. */\n  meta?: string\n  onSelect?: () => void\n  shortcut?: string\n}\n\ninterface CommandMenuGroup {\n  heading: string\n  items: CommandMenuItem[]\n}\n\nconst PANEL_KEYS = new Set(['ArrowDown', 'ArrowUp', 'End', 'Enter', 'Home'])\n\nfunction filterCommandGroups(groups: CommandMenuGroup[], query: string) {\n  const needle = query.trim().toLowerCase()\n  if (!needle) return groups\n  return groups\n    .map((group) => ({\n      ...group,\n      items: group.items.filter((item) =>\n        [item.label, item.description, ...(item.keywords ?? [])].some((text) =>\n          text?.toLowerCase().includes(needle),\n        ),\n      ),\n    }))\n    .filter((group) => group.items.length > 0)\n}\n\nfunction useCommandMenuShortcut(onOpen: () => void, key = 'k') {\n  useEffect(() => {\n    const onKeyDown = (event: KeyboardEvent) => {\n      // Chrome's autofill sends keydown events without a key.\n      if (event.key?.toLowerCase() === key && (event.metaKey || event.ctrlKey)) {\n        event.preventDefault()\n        onOpen()\n      }\n    }\n    window.addEventListener('keydown', onKeyDown, { capture: true })\n    return () => window.removeEventListener('keydown', onKeyDown, { capture: true })\n  }, [key, onOpen])\n}\n\ninterface CommandMenuProps {\n  /** Defaults to a sentence that quotes the search text. */\n  emptyMessage?: string\n  groups: CommandMenuGroup[]\n  loading?: boolean\n  onNavigate?: (href: string) => void\n  onOpenChange: (open: boolean) => void\n  /** Fetch results yourself: the menu shows `groups` as they are, without filtering. */\n  onQueryChange?: (query: string) => void\n  open: boolean\n  /** Shown between the search field and the results, such as an answer to what was typed. The empty message is left out while it's there. */\n  panel?: ReactNode\n  /** @default 'Search' */\n  placeholder?: string\n  /** The search text, when you pass `onQueryChange`. */\n  query?: string\n  title?: string\n}\n\nfunction CommandMenu({\n  emptyMessage,\n  groups,\n  loading = false,\n  onNavigate = (href) => window.location.assign(href),\n  onOpenChange,\n  onQueryChange,\n  open,\n  panel,\n  placeholder = 'Search',\n  query: controlledQuery,\n  title = 'Search',\n}: CommandMenuProps) {\n  const [ownQuery, setOwnQuery] = useState('')\n  const query = controlledQuery ?? ownQuery\n  const setQuery = onQueryChange ?? setOwnQuery\n  const results = onQueryChange ? groups : filterCommandGroups(groups, query)\n  // cmdk picks the first item only when the text changes, so results that arrive later, above\n  // the item it picked, would leave Enter on that item.\n  const first = results[0]?.items[0]?.id ?? ''\n  const [picked, setPicked] = useState({ first, value: first })\n  if (picked.first !== first) setPicked({ first, value: first })\n  const empty =\n    emptyMessage ??\n    (query.trim() ? `No results for “${query.trim()}”.` : 'Nothing here yet.')\n\n  function changeOpen(next: boolean) {\n    onOpenChange(next)\n    if (!next) setQuery('')\n  }\n\n  function select(item: CommandMenuItem) {\n    if (!item.keepOpen) changeOpen(false)\n    if (item.onSelect) item.onSelect()\n    else if (item.href) onNavigate(item.href)\n  }\n\n  return (\n    <CommandDialog\n      open={open}\n      onOpenChange={changeOpen}\n      title={title}\n      description={placeholder}\n    >\n      <Command\n        shouldFilter={false}\n        className='max-h-[calc(66dvh-1rem)]'\n        value={picked.value}\n        onValueChange={(value) => setPicked({ first, value })}\n      >\n        <CommandInput value={query} onValueChange={setQuery} placeholder={placeholder} />\n        {panel !== undefined && (\n          <div\n            data-slot='command-menu-panel'\n            role='presentation'\n            className='overflow-y-auto [scrollbar-width:thin]'\n            onKeyDown={(event) => {\n              if (PANEL_KEYS.has(event.key)) event.stopPropagation()\n            }}\n          >\n            {panel}\n          </div>\n        )}\n        <CommandList>\n          {loading ? (\n            <p role='status' className='text-muted-foreground py-6 text-center text-sm'>\n              Searching…\n            </p>\n          ) : (\n            panel === undefined && <CommandEmpty>{empty}</CommandEmpty>\n          )}\n          {results.map((group) => (\n            <CommandGroup key={group.heading} heading={group.heading}>\n              {group.items.map((item) => (\n                <CommandItem\n                  key={item.id}\n                  value={item.id}\n                  onMouseDown={(event) => {\n                    if (item.keepOpen) event.preventDefault()\n                  }}\n                  onSelect={() => select(item)}\n                >\n                  {item.icon}\n                  <span className='flex min-w-0 flex-1 flex-col'>\n                    <span className='truncate'>{item.label}</span>\n                    {item.description && (\n                      <span className='text-muted-foreground truncate text-xs'>\n                        {item.description}\n                      </span>\n                    )}\n                  </span>\n                  {item.meta && (\n                    <span className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n                      {item.meta}\n                    </span>\n                  )}\n                  {item.shortcut && <CommandShortcut>{item.shortcut}</CommandShortcut>}\n                </CommandItem>\n              ))}\n            </CommandGroup>\n          ))}\n        </CommandList>\n        <CommandMenuKeys />\n      </Command>\n    </CommandDialog>\n  )\n}\n\nfunction CommandMenuKeys() {\n  return (\n    <div\n      aria-hidden\n      className='text-muted-foreground flex items-center gap-4 border-t px-3 py-2 text-xs max-sm:hidden'\n    >\n      <span className='flex items-center gap-1.5'>\n        <Kbd>↑</Kbd>\n        <Kbd>↓</Kbd>\n        to move\n      </span>\n      <span className='flex items-center gap-1.5'>\n        <Kbd>↵</Kbd>\n        to choose\n      </span>\n      <span className='ms-auto flex items-center gap-1.5'>\n        <Kbd>Esc</Kbd>\n        to close\n      </span>\n    </div>\n  )\n}\n\nfunction CommandMenuTrigger({\n  className,\n  onClick,\n  placeholder = 'Search',\n  shortcut = '⌘K',\n}: {\n  className?: string\n  onClick: () => void\n  /** @default 'Search' */\n  placeholder?: string\n  shortcut?: string | null\n}) {\n  return (\n    <Button\n      variant='outline'\n      onClick={onClick}\n      className={cn(\n        'max-sm:aspect-square max-sm:px-0 sm:w-64 sm:justify-start',\n        className,\n      )}\n    >\n      <IconPlaceholder\n        lucide='SearchIcon'\n        tabler='IconSearch'\n        hugeicons='SearchIcon'\n        phosphor='MagnifyingGlassIcon'\n        remixicon='RiSearchLine'\n      />\n      <span className='truncate max-sm:sr-only'>{placeholder}</span>\n      {shortcut && (\n        <Kbd aria-hidden className='ml-auto max-sm:hidden'>\n          {shortcut}\n        </Kbd>\n      )}\n    </Button>\n  )\n}\n\nexport { CommandMenu, CommandMenuTrigger, filterCommandGroups, useCommandMenuShortcut }\n\nexport type { CommandMenuGroup, CommandMenuItem, CommandMenuProps }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/command-menu.tsx"
    }
  ],
  "type": "registry:component"
}
