{
  "schemaVersion": 1,
  "target": "react",
  "name": "command",
  "version": "0.1.0",
  "category": "overlays",
  "title": "Command",
  "description": "A command palette with a search field, grouped results that filter word by word, full keyboard navigation, an empty state, a loading row for slower results, and a Cmd+K dialog variant, built on Base UI Autocomplete and Dialog.",
  "tags": [
    "overlay",
    "command-palette",
    "search",
    "keyboard",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "agent-state",
      "version": "0.1.0"
    }
  ],
  "docsPath": "/components/command",
  "props": [
    {
      "name": "Command items",
      "type": "Item[] | { label, items }[]",
      "description": "The commands, flat or grouped. Items shaped { value, label, keywords? } work with the default filter; extra fields are passed to your render function."
    },
    {
      "name": "Command filter",
      "type": "(item, query, itemToString) => boolean | null",
      "default": "defaultCommandFilter",
      "description": "Replaces the default filter, which needs every query word in the label or keywords and ignores case and accents. null leaves filtering to you."
    },
    {
      "name": "Command value / defaultValue / onValueChange",
      "type": "string / string / (value) => void",
      "description": "The query."
    },
    {
      "name": "Command loopFocus",
      "type": "boolean",
      "default": "true",
      "description": "Wraps the highlight from the last command to the first."
    },
    {
      "name": "CommandInput placeholder / end",
      "type": "string / ReactNode",
      "default": "\"Search commands\"",
      "description": "Placeholder, also used as the accessible name, and content at the end of the field such as an Esc hint."
    },
    {
      "name": "CommandList children",
      "type": "(itemOrGroup) => ReactNode",
      "description": "Renders each matching item, or each group when items are grouped."
    },
    {
      "name": "CommandGroup heading / items",
      "type": "ReactNode / Item[]",
      "description": "A titled section; pass a function child to render each of its matching items. Empty groups are left out."
    },
    {
      "name": "CommandItem value / onSelect / destructive / disabled",
      "type": "Item / (event) => void / boolean / boolean",
      "description": "One command. onSelect runs on click or Enter; inside CommandDialog the dialog then closes unless the event is prevented."
    },
    {
      "name": "CommandShortcut / CommandItemMeta",
      "type": "ComponentProps<\"span\">",
      "description": "Key caps at the end of a row (one cap per array entry) and secondary text after the label."
    },
    {
      "name": "CommandEmpty children",
      "type": "ReactNode | (query) => ReactNode",
      "description": "Shown only when nothing matches. Defaults to a message naming the query."
    },
    {
      "name": "CommandLoading loading / label",
      "type": "boolean / ReactNode",
      "default": "true / \"Searching\"",
      "description": "A row with the agent searching mark while slower results arrive, announced politely."
    },
    {
      "name": "CommandDialog open / defaultOpen / onOpenChange",
      "type": "boolean / boolean / (open) => void",
      "description": "Dialog state."
    },
    {
      "name": "CommandDialog shortcut",
      "type": "string | null",
      "default": "\"k\"",
      "description": "Key that toggles the palette with Cmd or Ctrl. null registers none."
    },
    {
      "name": "CommandDialog trigger / title",
      "type": "ReactNode / string",
      "default": "- / \"Command palette\"",
      "description": "A CommandDialogTrigger to render inside the root, and the dialog's accessible name."
    }
  ],
  "accessibility": [
    "The field is a combobox (role=\"combobox\") with aria-controls pointing at the listbox and aria-activedescendant on the highlighted option, so focus stays in the field while the arrow keys move.",
    "The first match is always highlighted, so Enter runs it; Up, Down, Home, and End move the highlight and wrap at the ends.",
    "Group headings label their groups; the empty message and the loading row are polite live regions.",
    "CommandDialog opens with Cmd+K or Ctrl+K, traps focus with the field focused, and closes on Escape, a click outside, or after a command runs, returning focus to where it was.",
    "Opening with the shortcut and closing from the keyboard appear instantly; pointer opens use the dialog entrance, and reduced motion removes all transitions.",
    "The field uses a 16px font on small screens so iOS does not zoom when it is focused."
  ],
  "states": [
    "idle",
    "filtering",
    "empty",
    "loading",
    "dialog open"
  ],
  "files": [
    {
      "path": "ui/command.tsx",
      "content": "\"use client\";\n\nimport { Autocomplete as BaseAutocomplete } from \"@base-ui/react/autocomplete\";\nimport { Dialog as BaseDialog } from \"@base-ui/react/dialog\";\nimport {\n  type ComponentProps,\n  type MouseEvent,\n  type ReactNode,\n  createContext,\n  useCallback,\n  useContext,\n  useEffect,\n  useMemo,\n  useState,\n} from \"react\";\nimport { AgentState } from \"../agent/agent-state\";\n\ntype ClassName<State> = string | ((state: State) => string | undefined) | undefined;\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\n/** Prepends base classes while keeping Base UI's state-function form of className working. */\nfunction withBase<State>(base: string, className: ClassName<State>) {\n  return typeof className === \"function\" ? (state: State) => cx(base, className(state)) : cx(base, className);\n}\n\n/** The shape the default filter understands. Any extra fields ride along to your render function. */\nexport interface CommandItemData {\n  /** Stable id for the command. */\n  value: string;\n  /** Text shown and matched. */\n  label: string;\n  /** Extra words that should also find this command, such as synonyms. */\n  keywords?: readonly string[];\n}\n\n/** A titled group of commands. Pass an array of these to `items` for a grouped list. */\nexport interface CommandGroupData<Item = CommandItemData> {\n  /** Heading shown above the group. */\n  label: string;\n  items: readonly Item[];\n}\n\n/**\n * Matches when every word of the query appears in the label or keywords, ignoring case and\n * accents, so \"dep prod\" finds \"Deploy to production\".\n */\nexport function defaultCommandFilter(item: unknown, query: string, itemToString?: (item: unknown) => string) {\n  const words = normalize(query).split(/\\s+/).filter(Boolean);\n  if (words.length === 0) return true;\n  const record = (item ?? {}) as Partial<CommandItemData>;\n  const haystack = normalize(\n    [itemToString ? itemToString(item) : (record.label ?? String(item)), ...(record.keywords ?? [])].join(\" \"),\n  );\n  return words.every((word) => haystack.includes(word));\n}\n\nfunction normalize(text: string) {\n  return text.normalize(\"NFD\").replace(/[̀-ͯ]/g, \"\").toLowerCase();\n}\n\ninterface DialogBridge {\n  close: (instant: boolean) => void;\n}\n\nconst DialogBridgeContext = createContext<DialogBridge | null>(null);\n\nexport interface CommandProps<Item = CommandItemData>\n  extends Omit<ComponentProps<\"div\">, \"children\" | \"defaultValue\" | \"onChange\"> {\n  /** The commands: a flat array, or an array of `{ label, items }` groups. */\n  items: readonly Item[] | readonly CommandGroupData<Item>[];\n  /** Replaces the default word-by-word filter. Pass `null` to filter outside, for example on a server. */\n  filter?: ((item: Item, query: string, itemToString?: (item: Item) => string) => boolean) | null;\n  /** The query. Pass with `onValueChange` to control it. */\n  value?: string;\n  /** The initial query when uncontrolled. */\n  defaultValue?: string;\n  /** Called on every keystroke with the new query. */\n  onValueChange?: (value: string) => void;\n  /** Wrap arrow-key movement from the last command to the first. */\n  loopFocus?: boolean;\n  children?: ReactNode;\n}\n\n/**\n * The palette itself: a search field over a list of commands that filters as you type. The first\n * match is always highlighted, so Enter runs it; arrow keys, Home, and End move the highlight.\n * Use it inline (for example in a sidebar) or inside CommandDialog.\n */\nexport function Command<Item = CommandItemData>({\n  items,\n  filter = defaultCommandFilter as NonNullable<CommandProps<Item>[\"filter\"]>,\n  value,\n  defaultValue,\n  onValueChange,\n  loopFocus = true,\n  className,\n  children,\n  ...props\n}: CommandProps<Item>) {\n  return (\n    <BaseAutocomplete.Root\n      open\n      inline\n      items={items as readonly Item[]}\n      filter={filter as never}\n      autoHighlight=\"always\"\n      keepHighlight\n      loopFocus={loopFocus}\n      {...(value !== undefined ? { value } : null)}\n      defaultValue={defaultValue}\n      onValueChange={(next) => onValueChange?.(next)}\n    >\n      <div\n        data-slot=\"command\"\n        className={cx(\n          \"flex min-h-0 w-full flex-col overflow-hidden text-zinc-950 dark:text-white\",\n          \"rounded-xl border border-zinc-950/10 bg-white shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:border-white/10 dark:bg-black dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\",\n          // Inside CommandDialog the dialog draws the surface.\n          \"in-data-[slot=command-dialog]:rounded-none in-data-[slot=command-dialog]:border-0 in-data-[slot=command-dialog]:bg-transparent in-data-[slot=command-dialog]:shadow-none\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </div>\n    </BaseAutocomplete.Root>\n  );\n}\n\nexport interface CommandInputProps extends Omit<BaseAutocomplete.Input.Props, \"size\"> {\n  /** Content at the end of the field, such as a CommandShortcut hint. */\n  end?: ReactNode;\n}\n\n/** The search field. Typing filters the list; the field keeps focus while the arrow keys move the highlight. */\nexport function CommandInput({ className, end, placeholder = \"Search commands\", ...props }: CommandInputProps) {\n  return (\n    <div className=\"flex h-12 shrink-0 items-center gap-2.5 border-b border-zinc-950/[0.07] px-4 dark:border-white/[0.08]\">\n      <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-4 shrink-0 text-zinc-500\">\n        <circle cx=\"7.25\" cy=\"7.25\" r=\"4.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n        <path d=\"m10.75 10.75 2.75 2.75\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n      </svg>\n      <BaseAutocomplete.Input\n        placeholder={placeholder}\n        aria-label={props[\"aria-label\"] ?? placeholder}\n        className={withBase(\n          cx(\n            // 16px on touch screens so iOS does not zoom into the field.\n            \"h-full min-w-0 flex-1 bg-transparent text-base text-zinc-950 outline-none placeholder:text-zinc-400 sm:text-sm\",\n            \"dark:text-white dark:placeholder:text-zinc-500\",\n            \"[&::-webkit-search-cancel-button]:hidden\",\n          ),\n          className,\n        )}\n        {...props}\n      />\n      {end}\n    </div>\n  );\n}\n\nexport interface CommandListProps extends BaseAutocomplete.List.Props {\n  /** Classes for the scrolling wrapper around the list. */\n  viewportClassName?: string;\n}\n\n/**\n * The scrolling list of results. Pass a function child to render each item (or each group when\n * `items` is grouped); it receives only the items that match the query.\n */\nexport function CommandList({ className, viewportClassName, ...props }: CommandListProps) {\n  return (\n    <div\n      className={cx(\n        \"max-h-[min(22rem,calc(100dvh-14rem))] min-h-0 flex-1 overflow-y-auto overscroll-contain scroll-py-1.5\",\n        viewportClassName,\n      )}\n    >\n      <BaseAutocomplete.List className={withBase(\"p-1.5 outline-none data-[empty]:p-0\", className)} {...props} />\n    </div>\n  );\n}\n\nexport interface CommandGroupProps extends Omit<BaseAutocomplete.Group.Props, \"children\"> {\n  /** Heading shown above the group and used as its accessible name. */\n  heading?: ReactNode;\n  /** The group's matching items. With these, pass a function child to render each one. */\n  items?: readonly unknown[];\n  children?: ReactNode | ((item: any, index: number) => ReactNode);\n}\n\n/** A titled section of results. Groups with no matches are left out. */\nexport function CommandGroup({ heading, items, className, children, ...props }: CommandGroupProps) {\n  return (\n    <BaseAutocomplete.Group items={items} className={withBase(\"not-first:mt-1.5\", className)} {...props}>\n      {heading ? (\n        <BaseAutocomplete.GroupLabel className=\"flex h-7 items-center px-2.5 text-xs font-medium text-zinc-500 select-none\">\n          {heading}\n        </BaseAutocomplete.GroupLabel>\n      ) : null}\n      {typeof children === \"function\" ? <BaseAutocomplete.Collection>{children}</BaseAutocomplete.Collection> : children}\n    </BaseAutocomplete.Group>\n  );\n}\n\nexport interface CommandItemProps extends Omit<BaseAutocomplete.Item.Props, \"onSelect\"> {\n  /**\n   * Runs the command, on click or Enter. Inside CommandDialog the dialog then closes; call\n   * `event.preventDefault()` to keep it open, for example to show a nested page of commands.\n   */\n  onSelect?: (event: MouseEvent<HTMLDivElement>) => void;\n  /** Styles the command for actions that delete or cannot be undone. */\n  destructive?: boolean;\n}\n\n/**\n * One command. Put an icon first and a CommandShortcut last. The highlight follows the pointer\n * and the arrow keys instantly, with no animation, so fast keyboard use never lags.\n */\nexport function CommandItem({ onSelect, onClick, destructive = false, className, ...props }: CommandItemProps) {\n  const bridge = useContext(DialogBridgeContext);\n\n  return (\n    <BaseAutocomplete.Item\n      data-destructive={destructive || undefined}\n      onClick={(event) => {\n        onClick?.(event);\n        onSelect?.(event);\n        // A click with no pointer behind it (detail 0) came from the keyboard: close without motion.\n        if (!event.defaultPrevented) bridge?.close(event.detail === 0);\n      }}\n      className={withBase(\n        cx(\n          \"flex min-h-9 cursor-default scroll-my-1.5 items-center gap-3 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none\",\n          \"[&_svg]:size-4 [&_svg]:shrink-0\",\n          \"data-[disabled]:pointer-events-none data-[disabled]:opacity-45\",\n          destructive\n            ? cx(\n                \"text-red-600 [&_svg]:text-red-600/80 data-[highlighted]:bg-red-500/[0.08] data-[highlighted]:text-red-700\",\n                \"dark:text-red-400 dark:[&_svg]:text-red-400/80 dark:data-[highlighted]:bg-red-500/[0.12] dark:data-[highlighted]:text-red-300\",\n              )\n            : cx(\n                \"text-zinc-700 [&_svg]:text-zinc-500 data-[highlighted]:bg-zinc-950/[0.05] data-[highlighted]:text-zinc-950 data-[highlighted]:[&_svg]:text-zinc-950\",\n                \"dark:text-zinc-300 dark:[&_svg]:text-zinc-500 dark:data-[highlighted]:bg-white/[0.08] dark:data-[highlighted]:text-white dark:data-[highlighted]:[&_svg]:text-white\",\n              ),\n        ),\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** Secondary text after the label, such as where a command lives. Pushes shortcuts to the end. */\nexport function CommandItemMeta({ className, ...props }: ComponentProps<\"span\">) {\n  return <span className={cx(\"min-w-0 truncate text-xs text-zinc-500\", className)} {...props} />;\n}\n\n/** Keyboard keys shown at the end of an item or the field. Pass one key per child for separate caps. */\nexport function CommandShortcut({ className, children, ...props }: ComponentProps<\"span\">) {\n  const keys = Array.isArray(children) ? children : [children];\n  return (\n    <span className={cx(\"ml-auto flex shrink-0 items-center gap-1 pl-3\", className)} {...props}>\n      {keys.map((key, index) => (\n        <kbd\n          key={index}\n          className={cx(\n            \"inline-flex h-5 min-w-5 items-center justify-center rounded-md border border-zinc-950/10 px-1 font-sans text-[11px] leading-none font-medium text-zinc-500\",\n            \"dark:border-white/15 dark:text-zinc-400\",\n          )}\n        >\n          {key}\n        </kbd>\n      ))}\n    </span>\n  );\n}\n\n/** A divider between groups of results. */\nexport function CommandSeparator({ className, ...props }: BaseAutocomplete.Separator.Props) {\n  return (\n    <BaseAutocomplete.Separator\n      className={withBase(\"-mx-1.5 my-1.5 h-px bg-zinc-950/[0.07] dark:bg-white/[0.08]\", className)}\n      {...props}\n    />\n  );\n}\n\nexport interface CommandEmptyProps extends Omit<BaseAutocomplete.Empty.Props, \"children\"> {\n  /** Replaces the message. Receives the query that found nothing. */\n  children?: ReactNode | ((query: string) => ReactNode);\n}\n\n/** Shown only when nothing matches, and announced to screen readers when it appears. */\nexport function CommandEmpty({ className, children, ...props }: CommandEmptyProps) {\n  return (\n    <BaseAutocomplete.Empty className={withBase(\"empty:hidden\", className)} {...props}>\n      <div className=\"grid justify-items-center gap-1 px-6 py-10 text-center text-sm\">\n        <BaseAutocomplete.Value>\n          {(query) =>\n            typeof children === \"function\" ? (\n              children(query)\n            ) : (\n              children ?? (\n                <>\n                  <span className=\"font-medium text-zinc-950 dark:text-white\">No commands match “{query}”</span>\n                  <span className=\"text-zinc-500\">Try fewer words, or search by what the command does.</span>\n                </>\n              )\n            )\n          }\n        </BaseAutocomplete.Value>\n      </div>\n    </BaseAutocomplete.Empty>\n  );\n}\n\nexport interface CommandLoadingProps extends Omit<BaseAutocomplete.Status.Props, \"children\"> {\n  /** Whether results are still arriving. The row disappears when false. */\n  loading?: boolean;\n  /** What is being searched, as a verb phrase. */\n  label?: ReactNode;\n}\n\n/**\n * A quiet row for results that arrive later, such as a server search or an agent looking\n * something up. Uses the shared agent mark and is announced politely to screen readers.\n */\nexport function CommandLoading({ loading = true, label = \"Searching\", className, ...props }: CommandLoadingProps) {\n  return (\n    <BaseAutocomplete.Status className={withBase(\"empty:hidden\", className)} {...props}>\n      {loading ? (\n        <div className=\"flex h-9 items-center px-2.5\">\n          <AgentState activity=\"searching\" label={label} variant=\"plain\" size=\"sm\" />\n        </div>\n      ) : null}\n    </BaseAutocomplete.Status>\n  );\n}\n\n/** A strip under the list for key hints or a status line. */\nexport function CommandFooter({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      className={cx(\n        \"flex h-10 shrink-0 items-center gap-4 border-t border-zinc-950/[0.07] px-4 text-xs text-zinc-500 dark:border-white/[0.08]\",\n        \"[&_kbd]:inline-flex [&_kbd]:h-5 [&_kbd]:min-w-5 [&_kbd]:items-center [&_kbd]:justify-center [&_kbd]:rounded-md [&_kbd]:border [&_kbd]:border-zinc-950/10 [&_kbd]:px-1 [&_kbd]:font-sans [&_kbd]:text-[11px] [&_kbd]:font-medium\",\n        \"dark:[&_kbd]:border-white/15 dark:[&_kbd]:text-zinc-400\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport interface CommandDialogProps extends Omit<BaseDialog.Root.Props, \"children\" | \"onOpenChange\"> {\n  /** Called whenever the dialog opens or closes, from the shortcut, a trigger, Escape, or a command. */\n  onOpenChange?: (open: boolean) => void;\n  /**\n   * Key that toggles the dialog together with Cmd on macOS or Ctrl elsewhere. Defaults to \"k\".\n   * Pass `null` to register no shortcut.\n   */\n  shortcut?: string | null;\n  /** Rendered inside the dialog root, so a CommandDialogTrigger placed here opens the palette. */\n  trigger?: ReactNode;\n  /** Accessible name of the dialog. Not shown. */\n  title?: string;\n  /** Element to portal into. Defaults to `document.body`. */\n  container?: BaseDialog.Portal.Props[\"container\"];\n  /** Classes for the panel. */\n  className?: string;\n  /** A Command. It is mounted fresh on every open, so the query starts empty. */\n  children?: ReactNode;\n}\n\n/**\n * A modal palette near the top of the screen. Opens with Cmd+K or Ctrl+K and closes after a\n * command runs. Opening with the shortcut and closing from the keyboard skip the animation, since\n * a keyboard user wants the palette now; pointer opens get the 220ms dialog entrance.\n */\nexport function CommandDialog({\n  shortcut = \"k\",\n  trigger,\n  title = \"Command palette\",\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  container,\n  className,\n  children,\n  ...props\n}: CommandDialogProps) {\n  const [uncontrolled, setUncontrolled] = useState(defaultOpen);\n  const open = openProp ?? uncontrolled;\n  const [instant, setInstant] = useState(false);\n\n  const setOpen = useCallback(\n    (next: boolean, fromKeyboard: boolean) => {\n      setInstant(fromKeyboard);\n      if (openProp === undefined) setUncontrolled(next);\n      onOpenChange?.(next);\n    },\n    [onOpenChange, openProp],\n  );\n\n  useEffect(() => {\n    if (!shortcut) return;\n    function onKeyDown(event: KeyboardEvent) {\n      if (event.defaultPrevented || event.repeat) return;\n      if (event.key.toLowerCase() !== shortcut?.toLowerCase() || !(event.metaKey || event.ctrlKey) || event.altKey) return;\n      event.preventDefault();\n      setOpen(!open, true);\n    }\n    window.addEventListener(\"keydown\", onKeyDown);\n    return () => window.removeEventListener(\"keydown\", onKeyDown);\n  }, [shortcut, open, setOpen]);\n\n  const bridge = useMemo<DialogBridge>(() => ({ close: (fromKeyboard) => setOpen(false, fromKeyboard) }), [setOpen]);\n\n  return (\n    <BaseDialog.Root\n      open={open}\n      onOpenChange={(next, details) => setOpen(next, details.reason === \"escape-key\")}\n      {...props}\n    >\n      {trigger}\n      <BaseDialog.Portal container={container}>\n        <BaseDialog.Backdrop\n          data-instant={instant || undefined}\n          className={cx(\n            \"fixed inset-0 z-50 bg-black/40 dark:bg-black/70\",\n            \"transition-opacity duration-220 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n            \"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 data-[ending-style]:duration-150 data-[instant]:transition-none\",\n          )}\n        />\n        <BaseDialog.Viewport className=\"fixed inset-0 z-50 flex items-start justify-center px-4 pt-[min(14dvh,8rem)] pb-4\">\n          <BaseDialog.Popup\n            data-slot=\"command-dialog\"\n            data-instant={instant || undefined}\n            aria-label={title}\n            className={cx(\n              \"flex max-h-full w-full max-w-xl flex-col overflow-hidden outline-none\",\n              \"rounded-2xl border border-zinc-950/10 bg-white shadow-[0_24px_64px_-16px_rgb(0_0_0/0.28),0_2px_6px_rgb(0_0_0/0.04)]\",\n              \"dark:border-white/15 dark:bg-black dark:shadow-[0_24px_64px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]\",\n              // Pointer opens: 220ms quint ease-out from 96% and 8px low; exits 150ms. Keyboard: instant.\n              \"transition-[opacity,scale,translate] duration-220 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none data-[instant]:transition-none\",\n              \"data-[starting-style]:opacity-0 motion-safe:data-[starting-style]:translate-y-2 motion-safe:data-[starting-style]:scale-96\",\n              \"data-[ending-style]:opacity-0 data-[ending-style]:duration-150 motion-safe:data-[ending-style]:translate-y-1 motion-safe:data-[ending-style]:scale-98\",\n              className,\n            )}\n          >\n            <DialogBridgeContext.Provider value={bridge}>{children}</DialogBridgeContext.Provider>\n          </BaseDialog.Popup>\n        </BaseDialog.Viewport>\n      </BaseDialog.Portal>\n    </BaseDialog.Root>\n  );\n}\n\n/** A button that opens the palette. Pass it to CommandDialog's `trigger`. Unstyled; pass `className` or `render`. */\nexport const CommandDialogTrigger = BaseDialog.Trigger;\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { type ReactNode, useEffect, useState } from \"react\";\nimport {\n  Command,\n  CommandDialog,\n  CommandDialogTrigger,\n  CommandEmpty,\n  CommandFooter,\n  CommandGroup,\n  type CommandGroupData,\n  CommandInput,\n  CommandItem,\n  type CommandItemData,\n  CommandItemMeta,\n  CommandList,\n  CommandLoading,\n  CommandShortcut,\n} from \"@/components/shaken/ui/command\";\n\ninterface Action extends CommandItemData {\n  icon: ReactNode;\n  meta?: string;\n  keys?: string[];\n  destructive?: boolean;\n}\n\nconst stroke = { stroke: \"currentColor\", strokeWidth: 1.5, strokeLinecap: \"round\", strokeLinejoin: \"round\" } as const;\nconst svg = (path: ReactNode) => (\n  <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\">\n    {path}\n  </svg>\n);\n\nconst play = svg(<path d=\"M5 3.5v9l7-4.5-7-4.5Z\" {...stroke} />);\nconst check = svg(<><circle cx=\"8\" cy=\"8\" r=\"5.75\" {...stroke} /><path d=\"m5.75 8.25 1.5 1.5 3-3.25\" {...stroke} /></>);\nconst trace = svg(<path d=\"M2.5 12.5h11M4.5 10V7M8 10V4M11.5 10V8.5\" {...stroke} />);\nconst arrow = svg(<path d=\"M3.5 8h9M9 4.5 12.5 8 9 11.5\" {...stroke} />);\nconst key = svg(<><circle cx=\"5.5\" cy=\"10.5\" r=\"2.5\" {...stroke} /><path d=\"m7.25 8.75 5.25-5.25M10.5 5.5l1.5 1.5\" {...stroke} /></>);\nconst run = svg(<><circle cx=\"8\" cy=\"8\" r=\"5.75\" {...stroke} /><path d=\"M8 5v3l2 1.25\" {...stroke} /></>);\n\nconst groups: CommandGroupData<Action>[] = [\n  {\n    label: \"Suggested\",\n    items: [\n      { value: \"start-run\", label: \"Start a run\", icon: play, keys: [\"⌘\", \"R\"], keywords: [\"agent\", \"new\", \"task\"] },\n      { value: \"approvals\", label: \"Review pending approvals\", icon: check, meta: \"2 waiting\", keywords: [\"approve\", \"gate\"] },\n      { value: \"trace\", label: \"Open trace for run 482\", icon: trace, keywords: [\"debug\", \"timeline\", \"spans\"] },\n    ],\n  },\n  {\n    label: \"Go to\",\n    items: [\n      { value: \"go-runs\", label: \"Runs\", icon: arrow, keys: [\"G\", \"R\"], keywords: [\"history\"] },\n      { value: \"go-tools\", label: \"Tools and integrations\", icon: arrow, keys: [\"G\", \"T\"], keywords: [\"mcp\", \"connectors\"] },\n      { value: \"go-settings\", label: \"Workspace settings\", icon: arrow, keys: [\"G\", \"S\"], keywords: [\"preferences\", \"config\"] },\n    ],\n  },\n  {\n    label: \"Danger zone\",\n    items: [{ value: \"revoke\", label: \"Revoke API key\", icon: key, destructive: true, keywords: [\"token\", \"secret\", \"delete\"] }],\n  },\n];\n\nconst pastRuns: Action[] = [\n  { value: \"run-482\", label: \"Run 482: rate limits per plan\", icon: run, meta: \"Merged\" },\n  { value: \"run-479\", label: \"Run 479: retry flaky webhook tests\", icon: run, meta: \"Failed\" },\n  { value: \"run-471\", label: \"Run 471: migrate billing to v2 API\", icon: run, meta: \"Merged\" },\n];\n\nfunction Results() {\n  return (\n    <>\n      <CommandEmpty />\n      <CommandList>\n        {(group: CommandGroupData<Action>) => (\n          <CommandGroup key={group.label} heading={group.label} items={group.items}>\n            {(item: Action) => (\n              <CommandItem key={item.value} value={item} destructive={item.destructive}>\n                {item.icon}\n                <span className=\"truncate\">{item.label}</span>\n                {item.meta ? <CommandItemMeta>{item.meta}</CommandItemMeta> : null}\n                {item.keys ? <CommandShortcut>{item.keys}</CommandShortcut> : null}\n              </CommandItem>\n            )}\n          </CommandGroup>\n        )}\n      </CommandList>\n    </>\n  );\n}\n\n/** The dialog body: searching past runs takes a moment, so a quiet loading row shows meanwhile. */\nfunction Palette() {\n  const [query, setQuery] = useState(\"\");\n  const [loaded, setLoaded] = useState(\"\");\n  const searching = query.trim().length >= 2 && loaded !== query;\n\n  useEffect(() => {\n    if (query.trim().length < 2) return;\n    const timer = setTimeout(() => setLoaded(query), 700);\n    return () => clearTimeout(timer);\n  }, [query]);\n\n  const items = loaded && loaded === query ? [...groups, { label: \"Past runs\", items: pastRuns }] : groups;\n\n  return (\n    <Command items={items} value={query} onValueChange={setQuery}>\n      <CommandInput placeholder=\"Search commands and runs\" end={<CommandShortcut>Esc</CommandShortcut>} />\n      <CommandLoading loading={searching} label=\"Searching past runs\" className=\"px-1.5 pt-1.5\" />\n      <Results />\n      <CommandFooter>\n        <span className=\"flex items-center gap-1.5\">\n          <kbd>↑</kbd>\n          <kbd>↓</kbd>\n          Move\n        </span>\n        <span className=\"flex items-center gap-1.5\">\n          <kbd>↵</kbd>\n          Run\n        </span>\n        <span className=\"ml-auto max-sm:hidden\">Results update as you type</span>\n      </CommandFooter>\n    </Command>\n  );\n}\n\n// A search-field look for the trigger, on the Button secondary recipe.\nconst searchButton =\n  \"flex h-9 w-64 items-center gap-2 rounded-lg border border-zinc-950/12 bg-white pr-1.5 pl-3 text-sm text-zinc-500 select-none \" +\n  \"transition-[background-color,border-color] duration-150 ease-out motion-reduce:transition-none \" +\n  \"hover:border-zinc-950/20 hover:bg-zinc-950/[0.03] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500 \" +\n  \"dark:border-white/15 dark:bg-black dark:text-zinc-400 dark:hover:border-white/25 dark:hover:bg-white/[0.06]\";\n\nexport default function CommandExample() {\n  return (\n    <div className=\"grid w-full max-w-xl justify-items-center gap-6\">\n      {/* This docs site already uses Cmd+K for its own search, so the example listens for Cmd+J. */}\n      <CommandDialog\n        shortcut=\"j\"\n        trigger={\n          <CommandDialogTrigger className={searchButton}>\n            <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-4 shrink-0\">\n              <circle cx=\"7.25\" cy=\"7.25\" r=\"4.5\" {...stroke} />\n              <path d=\"m10.75 10.75 2.75 2.75\" {...stroke} />\n            </svg>\n            Search commands\n            <CommandShortcut>{[\"⌘\", \"J\"]}</CommandShortcut>\n          </CommandDialogTrigger>\n        }\n      >\n        <Palette />\n      </CommandDialog>\n\n      <Command items={groups}>\n        <CommandInput />\n        <Results />\n      </Command>\n    </div>\n  );\n}\n"
  }
}
