{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-menu-02",
  "description": "A command palette that shows recent records, then searches customers and orders as you type.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/command-menu.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/command-menu/command-menu-02.tsx",
      "content": "'use client'\n\nimport {\n  CommandMenu,\n  type CommandMenuGroup,\n  CommandMenuTrigger,\n} from '@/registry/components/dashboardblocks/command-menu'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { useRef, useState } from 'react'\n\ninterface CommandMenu2Props {\n  recent: CommandMenuGroup\n  search?: (query: string) => Promise<CommandMenuGroup[]>\n  onNavigate?: (href: string) => void\n}\n\nconst customerIcon = (\n  <IconPlaceholder\n    lucide='CircleUserRoundIcon'\n    tabler='IconUserCircle'\n    hugeicons='UserCircle02Icon'\n    phosphor='UserCircleIcon'\n    remixicon='RiUserLine'\n  />\n)\n\nconst orderIcon = (\n  <IconPlaceholder\n    lucide='ShoppingCartIcon'\n    tabler='IconShoppingCart'\n    hugeicons='ShoppingCart01Icon'\n    phosphor='ShoppingCartIcon'\n    remixicon='RiShoppingCartLine'\n  />\n)\n\nconst customers = [\n  { email: 'jonas@northwind.io', id: 'c1', name: 'Jonas Weber' },\n  { email: 'priya@lumen.dev', id: 'c2', name: 'Priya Nair' },\n  { email: 'mateo@fieldnote.co', id: 'c3', name: 'Mateo Silva' },\n  { email: 'priya@relay.dev', id: 'c4', name: 'Priya Nair' },\n  { email: 'lena@northwind.io', id: 'c5', name: 'Lena Fischer' },\n]\n\nconst orders = [\n  { customer: 'Jonas Weber', id: '1042', total: '$652.22' },\n  { customer: 'Priya Nair', id: '1041', total: '$89.00' },\n  { customer: 'Priya Nair', id: '1038', total: '$1,210.00' },\n  { customer: 'Mateo Silva', id: '1031', total: '$94.50' },\n]\n\nconst exampleProps: CommandMenu2Props = {\n  recent: {\n    heading: 'Recently viewed',\n    items: [\n      {\n        description: 'jonas@northwind.io',\n        href: '/customers/c1',\n        icon: customerIcon,\n        id: 'recent-c1',\n        label: 'Jonas Weber',\n      },\n      {\n        description: 'Priya Nair',\n        href: '/orders/1041',\n        icon: orderIcon,\n        id: 'recent-1041',\n        label: 'Order #1041',\n        meta: '$89.00',\n      },\n    ],\n  },\n}\n\nasync function searchRecords(query: string): Promise<CommandMenuGroup[]> {\n  await new Promise((resolve) => setTimeout(resolve, 400))\n  const needle = query.toLowerCase()\n  const groups: CommandMenuGroup[] = [\n    {\n      heading: 'Customers',\n      items: customers\n        .filter((customer) =>\n          `${customer.name} ${customer.email}`.toLowerCase().includes(needle),\n        )\n        .map((customer) => ({\n          description: customer.email,\n          href: `/customers/${customer.id}`,\n          icon: customerIcon,\n          id: customer.id,\n          label: customer.name,\n        })),\n    },\n    {\n      heading: 'Orders',\n      items: orders\n        .filter((order) =>\n          `#${order.id} ${order.customer}`.toLowerCase().includes(needle),\n        )\n        .map((order) => ({\n          description: order.customer,\n          href: `/orders/${order.id}`,\n          icon: orderIcon,\n          id: `order-${order.id}`,\n          label: `Order #${order.id}`,\n          meta: order.total,\n        })),\n    },\n  ]\n  return groups.filter((group) => group.items.length > 0)\n}\n\nconst CommandMenu2 = (props: CommandMenu2Props) => {\n  const [opened, setOpened] = useState<string | null>(null)\n  const {\n    onNavigate = (href: string) => setOpened(href),\n    recent,\n    search = searchRecords,\n  } = props\n  const [open, setOpen] = useState(false)\n  const [query, setQuery] = useState('')\n  const [results, setResults] = useState<CommandMenuGroup[]>([])\n  const [loading, setLoading] = useState(false)\n  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n  const latest = useRef(0)\n\n  function changeQuery(next: string) {\n    setQuery(next)\n    clearTimeout(timer.current)\n    const request = ++latest.current\n    if (!next.trim()) {\n      setLoading(false)\n      setResults([])\n      return\n    }\n    setLoading(true)\n    timer.current = setTimeout(() => {\n      void search(next.trim()).then((groups) => {\n        if (request !== latest.current) return\n        setResults(groups)\n        setLoading(false)\n      })\n    }, 250)\n  }\n\n  return (\n    <section className='@container flex flex-col items-center gap-3'>\n      <CommandMenuTrigger\n        onClick={() => setOpen(true)}\n        placeholder='Search customers and orders'\n        shortcut={null}\n      />\n      <p role='status' className='text-muted-foreground min-h-5 text-sm'>\n        {opened && `Opened ${opened}`}\n      </p>\n      <CommandMenu\n        open={open}\n        onOpenChange={setOpen}\n        query={query}\n        onQueryChange={changeQuery}\n        groups={query.trim() ? results : [recent]}\n        loading={loading}\n        onNavigate={onNavigate}\n        placeholder='Search customers and orders'\n      />\n    </section>\n  )\n}\n\nexport { CommandMenu2, exampleProps as commandMenu2ExampleProps, type CommandMenu2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/command-menu/command-menu-02.tsx"
    }
  ],
  "meta": {
    "shows": "A command palette that shows recent records, then searches customers and orders as you type.",
    "size": "half",
    "usedWith": [
      "command-menu-01",
      "data-table-02"
    ],
    "component": "CommandMenu2",
    "props": "{ recent: { heading: string; items: { description?: string; href?: string; icon?: ReactNode; id: string; keywords?: string[]; keepOpen?: boolean; label: string; meta?: string; onSelect?: () => void; shortcut?: string }[] }; search?: (query: string) => Promise<{ heading: string; items: { description?: string; href?: string; icon?: ReactNode; id: string; keywords?: string[]; keepOpen?: boolean; label: string; meta?: string; onSelect?: () => void; shortcut?: string }[] }[]>; onNavigate?: (href: string) => void }"
  },
  "type": "registry:component"
}
