{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-palette-demo",
  "title": "Command Palette Demo",
  "description": "A worked example of Command Palette: A search dialog over anything you can list, opened from a keyboard shortcut, with ranked matches and hidden keywords.",
  "dependencies": [
    "lucide-react@^1.31.0"
  ],
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/command-palette.json"
  ],
  "files": [
    {
      "path": "components/demos/command-palette-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Search } from \"lucide-react\"\n\nimport { componentDocs } from \"@/lib/component-docs\"\nimport { CommandPalette } from \"@/registry/default/command-palette/command-palette\"\nimport { Kbd } from \"@/registry/default/kbd/kbd\"\n\nconst items = componentDocs.slice(0, 12).map((component) => ({\n  id: component.slug,\n  label: component.name,\n  description: component.summary,\n  group: component.family,\n}))\n\nexport function CommandPaletteDemo() {\n  const [open, setOpen] = React.useState(false)\n  const [chosen, setChosen] = React.useState<string>()\n  const [query, setQuery] = React.useState(\"\")\n  const [applied, setApplied] = React.useState({ query: \"\", hits: items })\n\n  // Loading is the gap between what was typed and what has been answered, so\n  // nothing has to be set at the moment the effect runs.\n  const loading = open && query.trim() !== applied.query\n\n  // Stands in for a search endpoint: the wait is real, the results are local.\n  React.useEffect(() => {\n    if (!open) return\n\n    const needle = query.trim().toLowerCase()\n    const timer = setTimeout(() => {\n      setApplied({\n        query: query.trim(),\n        hits: needle\n          ? items.filter((item) => item.label.toLowerCase().includes(needle))\n          : items,\n      })\n    }, 350)\n\n    return () => clearTimeout(timer)\n  }, [query, open])\n\n  return (\n    <div className=\"grid w-full max-w-sm justify-items-center gap-3\">\n      <button\n        type=\"button\"\n        className=\"border-border hover:bg-muted focus-visible:ring-ring inline-flex min-h-11 items-center gap-2 rounded-full border px-4 text-sm font-semibold transition-colors duration-150 focus-visible:ring-2 focus-visible:outline-none motion-reduce:transition-none\"\n        onClick={() => setOpen(true)}\n      >\n        <Search aria-hidden=\"true\" size={14} />\n        Open the palette\n        <Kbd keys=\"Mod+J\" />\n      </button>\n\n      <p className=\"text-muted-foreground text-center text-xs\">\n        {chosen\n          ? `Chose ${chosen}.`\n          : \"Type to filter, arrows to move, Enter to pick.\"}\n      </p>\n\n      {/* The site's own search already owns Mod+K, so this one takes its\n          own chord rather than fighting for it. */}\n      {/* The results arrive from somewhere else, so the palette does not\n          rank them again and says it is searching while they are in flight. */}\n      <CommandPalette\n        items={applied.hits}\n        filter={false}\n        label=\"Search components\"\n        loading={loading}\n        open={open}\n        placeholder=\"Search components…\"\n        shortcut=\"j\"\n        onOpenChange={setOpen}\n        onQueryChange={setQuery}\n        onSelect={(item) => setChosen(item.label)}\n      />\n    </div>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}