{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-palette",
  "type": "registry:component",
  "title": "Workspace commands",
  "description": "Help people jump to a project, find a record, or start their next task from the keyboard.",
  "categories": [
    "navigation"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [
    "command"
  ],
  "files": [
    {
      "path": "src/registry/overtrue/command-palette.tsx",
      "type": "registry:component",
      "target": "components/overtrue/command-palette.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\n\"use client\";\n\nimport * as React from \"react\";\nimport {\n  IconArrowDown as ArrowDown,\n  IconArrowUp as ArrowUp,\n  IconCornerDownLeft as CornerDownLeft,\n  IconSearch as Search,\n} from \"@tabler/icons-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  Command,\n  CommandDialog,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  CommandSeparator,\n  CommandShortcut,\n} from \"@/components/ui/command\";\n\nexport interface CommandPaletteItem {\n  id: string;\n  label: string;\n  description?: string;\n  icon?: React.ReactNode;\n  shortcut?: React.ReactNode;\n  keywords?: string[];\n  disabled?: boolean;\n  onSelect?: () => void;\n}\n\nexport interface CommandPaletteGroup {\n  heading?: string;\n  items: CommandPaletteItem[];\n}\n\nexport interface CommandPaletteProps {\n  groups: CommandPaletteGroup[];\n  variant?: \"dialog\" | \"inline\";\n  /** Arrange results as familiar command rows or as an app-launcher grid. */\n  layout?: \"list\" | \"grid\";\n  /** Tighten list rows for dense navigation menus. */\n  density?: \"compact\" | \"default\";\n  size?: \"compact\" | \"default\" | \"wide\";\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  placeholder?: string;\n  emptyLabel?: React.ReactNode;\n  title?: string;\n  description?: string;\n  footer?: React.ReactNode;\n  className?: string;\n  onSelect?: (item: CommandPaletteItem) => void;\n}\n\nconst sizeClasses = {\n  compact: \"sm:max-w-md\",\n  default: \"sm:max-w-xl\",\n  wide: \"sm:max-w-2xl\",\n};\n\n// Shared by the dialog and inline surfaces: a roomy search row and quiet group headings.\nconst surfaceClasses =\n  \"**:data-[slot=command-input-wrapper]:h-12! **:data-[slot=command-input-wrapper]:gap-2.5 **:data-[slot=command-input-wrapper]:border-border/60 **:data-[slot=command-input-wrapper]:px-4 **:data-[slot=command-input]:h-12 **:data-[slot=command-input]:text-sm [&_[cmdk-group-heading]]:px-2.5! [&_[cmdk-group-heading]]:pt-2 [&_[cmdk-group-heading]]:pb-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground\";\n\nconst useIsoLayoutEffect =\n  typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\ninterface HighlightRect {\n  left: number;\n  top: number;\n  width: number;\n  height: number;\n}\n\n/**\n * Follow cmdk's selected item with one shared highlight, so moving through\n * results with the keyboard or pointer glides instead of blinking.\n */\nfunction useSelectionHighlight(\n  marker: React.RefObject<HTMLSpanElement | null>,\n) {\n  const [{ rect, snap }, setState] = React.useState<{\n    rect: HighlightRect | null;\n    snap: boolean;\n  }>({ rect: null, snap: true });\n  // The first placement snaps into place; later moves glide.\n  const [glide, setGlide] = React.useState(false);\n\n  useIsoLayoutEffect(() => {\n    const highlight = marker.current;\n    const root = highlight?.closest(\"[cmdk-root]\");\n    if (!highlight || !root) return;\n    let frame = 0;\n\n    const measure = () => {\n      frame = 0;\n      const item = root.querySelector<HTMLElement>(\n        '[cmdk-item][data-selected=\"true\"]',\n      );\n      const parent = highlight.offsetParent as HTMLElement | null;\n      if (!item || !parent || !item.getClientRects().length) {\n        setState((current) =>\n          current.rect ? { rect: null, snap: true } : current,\n        );\n        return;\n      }\n      let next: HighlightRect;\n      if (item.offsetParent === parent) {\n        next = {\n          left: item.offsetLeft,\n          top: item.offsetTop,\n          width: item.offsetWidth,\n          height: item.offsetHeight,\n        };\n      } else {\n        const box = item.getBoundingClientRect();\n        const origin = parent.getBoundingClientRect();\n        next = {\n          left: box.left - origin.left + parent.scrollLeft,\n          top: box.top - origin.top + parent.scrollTop,\n          width: box.width,\n          height: box.height,\n        };\n      }\n      setState((current) =>\n        current.rect &&\n        current.rect.left === next.left &&\n        current.rect.top === next.top &&\n        current.rect.width === next.width &&\n        current.rect.height === next.height\n          ? current\n          : // Reappearing after an empty search fades in place instead of sliding.\n            { rect: next, snap: !current.rect },\n      );\n    };\n    const schedule = () => {\n      if (!frame) frame = requestAnimationFrame(measure);\n    };\n\n    measure();\n    const mutations = new MutationObserver(schedule);\n    mutations.observe(root, {\n      subtree: true,\n      childList: true,\n      attributes: true,\n      attributeFilter: [\"data-selected\", \"hidden\"],\n    });\n    const resize = new ResizeObserver(schedule);\n    if (highlight.parentElement) resize.observe(highlight.parentElement);\n    const ready = requestAnimationFrame(() => setGlide(true));\n    return () => {\n      mutations.disconnect();\n      resize.disconnect();\n      cancelAnimationFrame(frame);\n      cancelAnimationFrame(ready);\n    };\n  }, [marker]);\n\n  return { rect, glide: glide && !snap, snap };\n}\n\n/** Bind Command/Ctrl+K to a controlled command palette without stealing input shortcuts. */\nfunction useCommandPaletteShortcut(\n  onOpenChange: React.Dispatch<React.SetStateAction<boolean>>,\n  enabled = true,\n) {\n  React.useEffect(() => {\n    if (!enabled) return;\n\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== \"k\")\n        return;\n      const target = event.target;\n      if (\n        target instanceof HTMLInputElement ||\n        target instanceof HTMLTextAreaElement ||\n        target instanceof HTMLSelectElement ||\n        (target instanceof HTMLElement && target.isContentEditable)\n      )\n        return;\n\n      event.preventDefault();\n      onOpenChange((open) => !open);\n    };\n\n    document.addEventListener(\"keydown\", onKeyDown);\n    return () => document.removeEventListener(\"keydown\", onKeyDown);\n  }, [enabled, onOpenChange]);\n}\n\nfunction CommandPaletteHints({ dialog }: { dialog: boolean }) {\n  return (\n    <span\n      data-slot=\"command-palette-hints\"\n      className=\"flex min-w-0 items-center gap-4\"\n    >\n      <span className=\"flex items-center gap-1.5\">\n        <CommandPaletteKbd>\n          <CornerDownLeft />\n        </CommandPaletteKbd>\n        Select\n      </span>\n      <span className=\"flex items-center gap-1.5\">\n        <span className=\"flex gap-0.5\">\n          <CommandPaletteKbd>\n            <ArrowUp />\n          </CommandPaletteKbd>\n          <CommandPaletteKbd>\n            <ArrowDown />\n          </CommandPaletteKbd>\n        </span>\n        Navigate\n      </span>\n      {dialog ? (\n        <span className=\"hidden items-center gap-1.5 sm:flex\">\n          <CommandPaletteKbd>Esc</CommandPaletteKbd>\n          Close\n        </span>\n      ) : null}\n    </span>\n  );\n}\n\nfunction CommandPaletteContent({\n  groups,\n  placeholder,\n  emptyLabel,\n  footer,\n  onSelect,\n  layout,\n  density,\n  variant,\n}: Pick<\n  CommandPaletteProps,\n  | \"groups\"\n  | \"placeholder\"\n  | \"emptyLabel\"\n  | \"footer\"\n  | \"onSelect\"\n  | \"layout\"\n  | \"density\"\n  | \"variant\"\n>) {\n  const marker = React.useRef<HTMLSpanElement>(null);\n  const { rect, glide, snap } = useSelectionHighlight(marker);\n  const grid = layout === \"grid\";\n  const compact = density === \"compact\";\n\n  return (\n    <>\n      <CommandInput placeholder={placeholder} />\n      {variant === \"dialog\" ? (\n        <CommandPaletteKbd\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute top-3.5 right-4\"\n        >\n          Esc\n        </CommandPaletteKbd>\n      ) : null}\n      <CommandList\n        data-highlight={rect ? \"\" : undefined}\n        className=\"group/palette @container/palette relative max-h-[min(420px,60vh)] scroll-py-2 px-1.5 py-1.5 [&>[cmdk-list-sizer]]:relative\"\n      >\n        <span\n          ref={marker}\n          aria-hidden=\"true\"\n          data-slot=\"command-palette-highlight\"\n          className={cn(\n            \"pointer-events-none absolute top-0 left-0\",\n            grid\n              ? \"rounded-xl bg-primary/[0.05] shadow-[0_0_0_2px_color-mix(in_oklab,var(--color-primary)_30%,transparent),0_10px_28px_-14px_color-mix(in_oklab,var(--color-primary)_60%,transparent)] dark:bg-primary/[0.09]\"\n              : \"rounded-lg bg-primary/[0.07] shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--color-primary)_14%,transparent),0_6px_18px_-12px_color-mix(in_oklab,var(--color-primary)_60%,transparent)] dark:bg-primary/[0.13]\",\n            rect ? \"opacity-100\" : \"opacity-0\",\n            glide\n              ? \"transition-[translate,width,height,opacity] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\"\n              : snap &&\n                  \"transition-opacity duration-200 motion-reduce:transition-none\",\n          )}\n          style={\n            rect\n              ? {\n                  width: rect.width,\n                  height: rect.height,\n                  translate: `${rect.left}px ${rect.top}px`,\n                }\n              : undefined\n          }\n        />\n        <CommandEmpty className=\"px-6 py-10 text-center text-sm text-muted-foreground\">\n          <span\n            aria-hidden=\"true\"\n            className=\"mx-auto mb-3 flex size-10 items-center justify-center rounded-xl bg-muted/60 text-muted-foreground ring-1 ring-border/60 ring-inset [&>svg]:size-[18px]!\"\n          >\n            <Search />\n          </span>\n          {emptyLabel}\n        </CommandEmpty>\n        {groups.map((group, groupIndex) => (\n          <React.Fragment key={group.heading ?? groupIndex}>\n            {groupIndex > 0 ? (\n              <CommandSeparator className=\"-mx-1.5 my-1.5 bg-border/60\" />\n            ) : null}\n            <CommandGroup\n              heading={group.heading}\n              className={cn(\n                \"overflow-visible p-0!\",\n                grid &&\n                  \"[&_[cmdk-group-items]]:grid [&_[cmdk-group-items]]:grid-cols-2 [&_[cmdk-group-items]]:gap-2 [&_[cmdk-group-items]]:p-1 @lg/palette:[&_[cmdk-group-items]]:grid-cols-3\",\n              )}\n            >\n              {group.items.map((item) => (\n                <CommandItem\n                  key={item.id}\n                  value={item.id}\n                  keywords={[\n                    item.label,\n                    item.description ?? \"\",\n                    ...(item.keywords ?? []),\n                  ]}\n                  disabled={item.disabled}\n                  onSelect={() => {\n                    item.onSelect?.();\n                    onSelect?.(item);\n                  }}\n                  className={cn(\n                    \"group/item gap-3 rounded-lg px-2.5! text-foreground transition-colors duration-150 motion-reduce:transition-none data-[selected=true]:bg-primary/[0.07] data-[selected=true]:text-foreground group-data-[highlight]/palette:data-[selected=true]:bg-transparent dark:data-[selected=true]:bg-primary/[0.13]\",\n                    compact ? \"py-1.5!\" : \"py-2!\",\n                    grid &&\n                      \"h-auto min-h-28 flex-col items-start justify-between gap-4 rounded-xl border border-border/60 p-3.5! data-[selected=true]:border-primary/30 group-data-[highlight]/palette:data-[selected=true]:border-transparent\",\n                  )}\n                >\n                  {item.icon ? (\n                    <span\n                      data-slot=\"command-palette-icon\"\n                      className={cn(\n                        \"flex shrink-0 items-center justify-center rounded-lg bg-muted/60 text-muted-foreground ring-1 ring-border/60 transition-[color,background-color,box-shadow] duration-150 ring-inset motion-reduce:transition-none [&>svg]:size-4! [&>svg]:text-current!\",\n                        \"group-data-[selected=true]/item:bg-card group-data-[selected=true]/item:text-primary group-data-[selected=true]/item:shadow-[0_1px_2px_rgb(0_0_0/0.06)] group-data-[selected=true]/item:ring-primary/25 dark:group-data-[selected=true]/item:bg-primary/15\",\n                        compact ? \"size-7\" : \"size-8\",\n                        grid && \"size-9 rounded-[10px] [&>svg]:size-[18px]!\",\n                      )}\n                    >\n                      {item.icon}\n                    </span>\n                  ) : null}\n                  <span className={cn(\"min-w-0 flex-1\", grid && \"w-full flex-none\")}>\n                    <span className=\"block truncate text-sm leading-5 font-medium tracking-tight\">\n                      {item.label}\n                    </span>\n                    {item.description ? (\n                      <span className=\"block truncate text-xs leading-4 text-muted-foreground\">\n                        {item.description}\n                      </span>\n                    ) : null}\n                  </span>\n                  {item.shortcut ? (\n                    <CommandShortcut className=\"tracking-normal\">\n                      {item.shortcut}\n                    </CommandShortcut>\n                  ) : !grid ? (\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"ms-auto shrink-0 opacity-0 transition-opacity duration-150 group-data-[selected=true]/item:opacity-100 motion-reduce:transition-none\"\n                    >\n                      <CommandPaletteKbd>\n                        <CornerDownLeft />\n                      </CommandPaletteKbd>\n                    </span>\n                  ) : null}\n                </CommandItem>\n              ))}\n            </CommandGroup>\n          </React.Fragment>\n        ))}\n      </CommandList>\n      {footer !== null ? (\n        <div\n          data-slot=\"command-palette-footer\"\n          className=\"flex min-h-10 items-center justify-between gap-3 border-t border-border/60 bg-muted/30 px-4 py-2 text-xs text-muted-foreground\"\n        >\n          {footer === undefined ? (\n            <CommandPaletteHints dialog={variant === \"dialog\"} />\n          ) : (\n            footer\n          )}\n        </div>\n      ) : null}\n    </>\n  );\n}\n\n/** A data-driven command menu that renders as a modal palette or an embedded search surface. */\nfunction CommandPalette({\n  groups,\n  variant = \"dialog\",\n  layout = \"list\",\n  density = \"default\",\n  size = \"default\",\n  open,\n  onOpenChange,\n  placeholder = \"Type a command or search…\",\n  emptyLabel = \"No commands found.\",\n  title = \"Command palette\",\n  description = \"Search for a command to run.\",\n  footer,\n  className,\n  onSelect,\n}: CommandPaletteProps) {\n  const content = (\n    <CommandPaletteContent\n      groups={groups}\n      placeholder={placeholder}\n      emptyLabel={emptyLabel}\n      footer={footer}\n      onSelect={onSelect}\n      layout={layout}\n      density={density}\n      variant={variant}\n    />\n  );\n\n  if (variant === \"inline\") {\n    return (\n      <Command\n        data-slot=\"command-palette\"\n        data-variant=\"inline\"\n        className={cn(\n          \"relative h-auto rounded-2xl border border-border/70 bg-card text-card-foreground shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.5)]\",\n          surfaceClasses,\n          className,\n        )}\n      >\n        {content}\n      </Command>\n    );\n  }\n\n  return (\n    <CommandDialog\n      open={open}\n      onOpenChange={onOpenChange}\n      title={title}\n      description={description}\n      showCloseButton={false}\n      className={cn(\n        \"gap-0 overflow-hidden rounded-2xl border border-border/70 bg-popover/95 p-0 text-popover-foreground backdrop-blur-xl dark:bg-popover/90 **:data-[slot=command]:bg-transparent\",\n        \"bg-[radial-gradient(90%_55%_at_50%_-10%,color-mix(in_oklab,var(--color-primary)_7%,transparent),transparent_70%)]\",\n        \"shadow-[0_0_0_1px_rgb(0_0_0/0.02),0_24px_64px_-16px_rgb(0_0_0/0.28)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06),0_24px_64px_-16px_rgb(0_0_0/0.7)]\",\n        \"transition-[opacity,scale] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:starting:scale-[0.98] motion-safe:starting:opacity-0 motion-reduce:transition-none\",\n        \"**:data-[slot=command-input]:pe-12\",\n        surfaceClasses,\n        sizeClasses[size],\n        className,\n      )}\n    >\n      {content}\n    </CommandDialog>\n  );\n}\n\nfunction CommandPaletteKbd({\n  className,\n  ...props\n}: React.ComponentProps<\"kbd\">) {\n  return (\n    <kbd\n      data-slot=\"command-palette-kbd\"\n      className={cn(\n        \"inline-flex h-5 min-w-5 items-center justify-center rounded-md border border-border/70 bg-background/80 px-1 font-sans text-[11px] leading-none font-medium text-muted-foreground shadow-[inset_0_-1px_0_var(--color-border)] dark:bg-foreground/[0.06] [&_svg]:size-3!\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nfunction CommandPaletteShortcutKeys({\n  keys,\n  label,\n  className,\n}: {\n  keys: string[];\n  label?: string;\n  className?: string;\n}) {\n  return (\n    <span\n      aria-label={label ?? keys.join(\" then \")}\n      className={cn(\"flex items-center gap-1\", className)}\n    >\n      {keys.map((key) => (\n        <CommandPaletteKbd key={key}>{key}</CommandPaletteKbd>\n      ))}\n    </span>\n  );\n}\n\nexport {\n  CommandPalette,\n  CommandPaletteKbd,\n  CommandPaletteShortcutKeys,\n  useCommandPaletteShortcut,\n};\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/command-palette. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
