{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-box",
  "title": "Command Box",
  "author": "jyotirmoydas <jyotirmoydas12345@gmail.com>",
  "description": "A customizable command palette/search box with keyboard shortcuts and footer logo customization.",
  "dependencies": ["cn", "cmdk", "lucide-react", "react-hotkeys-hook"],
  "registryDependencies": ["button", "command", "kbd", "separator"],
  "files": [
    {
      "path": "src/registry/command-box/command-box.tsx",
      "content": "\"use client\";\n\nimport { useCommandState } from \"cmdk\";\nimport { cn } from \"cn\";\nimport type { LucideProps } from \"lucide-react\";\nimport { CornerDownLeftIcon, SearchIcon } from \"lucide-react\";\nimport Image from \"next/image\";\nimport * as React from \"react\";\nimport { useCallback, useState } from \"react\";\nimport { useHotkeys } from \"react-hotkeys-hook\";\n\nimport {\n  CommandDialog,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n} from \"@/components/ui/command\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport { Separator } from \"@/components/ui/separator\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type CommandLinkItem = {\n  title: string;\n  href: string;\n  icon?: React.ComponentType<LucideProps>;\n  iconImage?: string;\n  keywords?: string[];\n  openInNewTab?: boolean;\n};\n\nexport type CommandActionItem = {\n  title: string;\n  icon?: React.ComponentType<LucideProps>;\n  keywords?: string[];\n  onSelect: () => void;\n};\n\nexport type CommandKind = \"command\" | \"page\" | \"link\";\n\nexport interface CommandBoxProps {\n  /** Whether the command box dialog is open */\n  open: boolean;\n  /** Callback when the open state changes */\n  onOpenChange: (open: boolean) => void;\n  /** Enable backdrop blur effect for focused view */\n  backdropBlur?: boolean;\n  /** Blur intensity (in pixels, default: 8) */\n  blurIntensity?: number;\n  /** Placeholder text for the search input */\n  placeholder?: string;\n  /** Text shown when no results are found */\n  emptyText?: string;\n  /** Custom logo component for the footer (bottom-left) */\n  footerLogo?: React.ReactNode;\n  /** Image URL for the footer logo (alternative to footerLogo component) */\n  footerLogoSrc?: string;\n  /** Alt text for footer logo image */\n  footerLogoAlt?: string;\n  /** Size of the footer logo in pixels */\n  footerLogoSize?: number;\n  /** Additional class name for the dialog */\n  className?: string;\n  /** Children components (CommandBoxGroup, CommandBoxItem, etc.) */\n  children: React.ReactNode;\n}\n\nexport interface CommandBoxTriggerProps {\n  /** Callback when the trigger is clicked */\n  onClick?: () => void;\n  /** Additional class name */\n  className?: string;\n}\n\nexport interface CommandBoxGroupProps {\n  /** Group heading text */\n  heading: string;\n  /** Children items */\n  children: React.ReactNode;\n}\n\nexport interface CommandBoxItemProps {\n  /** Keywords for search filtering */\n  keywords?: string[];\n  /** Callback when item is selected */\n  onSelect?: () => void;\n  /** Render as child element (for links) */\n  asChild?: boolean;\n  /** Children content */\n  children: React.ReactNode;\n}\n\nexport interface CommandBoxLinkGroupProps {\n  /** Group heading text */\n  heading: string;\n  /** Link items to display */\n  links: CommandLinkItem[];\n  /** Fallback icon if link has no icon */\n  fallbackIcon?: React.ComponentType<LucideProps>;\n  /** Callback when a link is selected */\n  onLinkSelect: (href: string, openInNewTab?: boolean) => void;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Command Box Trigger Button\n// ─────────────────────────────────────────────────────────────────────────────\n\nimport { Button } from \"@/components/ui/button\";\nimport { Kbd as KbdComponent, KbdGroup } from \"@/components/ui/kbd\";\n\n/**\n * A search/command trigger button matching the site header style.\n * Shows ⌘K on macOS and Ctrl K on other platforms.\n */\nexport function CommandBoxTrigger({\n  onClick,\n  className,\n}: CommandBoxTriggerProps) {\n  return (\n    <Button\n      variant=\"secondary\"\n      className={cn(\n        \"h-8 gap-1.5 rounded-full border border-input bg-white px-2.5 text-muted-foreground shadow-xs select-none hover:bg-white dark:bg-input/30 dark:hover:bg-input/30\",\n        className\n      )}\n      onClick={onClick}\n    >\n      <SearchIcon aria-hidden />\n\n      <span className=\"font-sans text-sm/4 font-medium sm:hidden\">Search</span>\n\n      <KbdGroup className=\"hidden sm:in-[.os-macos_&]:flex\">\n        <KbdComponent className=\"w-5 min-w-5\">⌘</KbdComponent>\n        <KbdComponent className=\"w-5 min-w-5\">K</KbdComponent>\n      </KbdGroup>\n\n      <KbdGroup className=\"hidden sm:not-[.os-macos_&]:flex\">\n        <KbdComponent>Ctrl</KbdComponent>\n        <KbdComponent className=\"w-5 min-w-5\">K</KbdComponent>\n      </KbdGroup>\n    </Button>\n  );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Command Box Dialog\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * A command box dialog with customizable footer logo.\n * Exact replica of the site header command menu.\n *\n * @example\n * ```tsx\n * <CommandBox\n *   open={open}\n *   onOpenChange={setOpen}\n *   footerLogoSrc=\"/my-logo.svg\"\n *   footerLogoAlt=\"My App\"\n * >\n *   <CommandBoxInput />\n *   <CommandBoxList>\n *     <CommandBoxGroup heading=\"Menu\">\n *       <CommandBoxItem>Home</CommandBoxItem>\n *     </CommandBoxGroup>\n *   </CommandBoxList>\n * </CommandBox>\n * ```\n */\nexport function CommandBox({\n  open,\n  onOpenChange,\n  backdropBlur = false,\n  blurIntensity = 8,\n  children,\n}: CommandBoxProps) {\n  return (\n    <>\n      {/* Backdrop blur overlay */}\n      {backdropBlur && open && (\n        <div\n          className=\"fixed inset-0 z-50 bg-black/20 transition-opacity duration-200\"\n          style={{ backdropFilter: `blur(${blurIntensity}px)` }}\n          onClick={() => onOpenChange(false)}\n          aria-hidden\n        />\n      )}\n      <CommandDialog open={open} onOpenChange={onOpenChange}>\n        {children}\n      </CommandDialog>\n    </>\n  );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Command Box Sub-components\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport function CommandBoxInput({\n  placeholder = \"Type a command or search...\",\n  value,\n  onValueChange,\n  ...props\n}: React.ComponentProps<typeof CommandInput>) {\n  return (\n    <CommandInput\n      placeholder={placeholder}\n      value={value}\n      onValueChange={onValueChange}\n      {...props}\n    />\n  );\n}\n\nexport function CommandBoxList({\n  className,\n  children,\n  ...props\n}: React.ComponentProps<typeof CommandList>) {\n  return (\n    <CommandList\n      className={cn(\n        \"min-h-80 supports-timeline-scroll:scroll-fade-effect-y\",\n        className\n      )}\n      {...props}\n    >\n      {children}\n    </CommandList>\n  );\n}\n\nexport function CommandBoxEmpty({\n  children = \"No results found.\",\n  ...props\n}: React.ComponentProps<typeof CommandEmpty>) {\n  return <CommandEmpty {...props}>{children}</CommandEmpty>;\n}\n\nexport function CommandBoxGroup({\n  heading,\n  children,\n  ...props\n}: CommandBoxGroupProps &\n  Omit<React.ComponentProps<typeof CommandGroup>, \"heading\">) {\n  return (\n    <CommandGroup heading={heading} {...props}>\n      {children}\n    </CommandGroup>\n  );\n}\n\nexport function CommandBoxItem({\n  keywords,\n  onSelect,\n  asChild,\n  children,\n  ...props\n}: CommandBoxItemProps &\n  Omit<React.ComponentProps<typeof CommandItem>, \"onSelect\">) {\n  return (\n    <CommandItem\n      keywords={keywords}\n      onSelect={onSelect}\n      asChild={asChild}\n      {...props}\n    >\n      {children}\n    </CommandItem>\n  );\n}\n\nexport function CommandBoxSeparator({\n  className,\n  ...props\n}: React.ComponentProps<typeof Separator>) {\n  return <Separator className={className} {...props} />;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Command Box Link Group (convenience component)\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport function CommandBoxLinkGroup({\n  heading,\n  links,\n  fallbackIcon,\n  onLinkSelect,\n}: CommandBoxLinkGroupProps) {\n  return (\n    <CommandGroup heading={heading}>\n      {links.map((link) => {\n        const Icon = link?.icon ?? fallbackIcon ?? React.Fragment;\n        return (\n          <CommandItem\n            key={link.href}\n            keywords={link.keywords}\n            onSelect={() => onLinkSelect(link.href, link.openInNewTab)}\n          >\n            {link?.iconImage ? (\n              <Image\n                className=\"rounded-sm corner-squircle supports-corner-shape:rounded-[50%]\"\n                src={link.iconImage}\n                alt={link.title}\n                width={16}\n                height={16}\n                unoptimized\n              />\n            ) : (\n              <Icon />\n            )}\n            {link.title}\n          </CommandItem>\n        );\n      })}\n    </CommandGroup>\n  );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Command Box Footer\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface CommandBoxFooterProps {\n  /** Custom logo component (bottom-left) */\n  logo?: React.ReactNode;\n  /** Image URL for the logo (alternative to logo component) */\n  logoSrc?: string;\n  /** Alt text for logo image */\n  logoAlt?: string;\n  /** Size of the logo in pixels (for image) */\n  logoSize?: number;\n  /** Map of command titles to their kind (for dynamic action labels) */\n  commandMetaMap?: Map<string, { commandKind: CommandKind }>;\n  /** Custom action labels */\n  actionLabels?: Record<CommandKind, string>;\n}\n\nconst DEFAULT_ACTION_LABELS: Record<CommandKind, string> = {\n  command: \"Run Command\",\n  page: \"Go to Page\",\n  link: \"Open Link\",\n};\n\nexport function CommandBoxFooter({\n  logo,\n  logoSrc,\n  logoAlt = \"Logo\",\n  logoSize = 24,\n  commandMetaMap = new Map(),\n  actionLabels = DEFAULT_ACTION_LABELS,\n}: CommandBoxFooterProps) {\n  const selectedCommandKind = useCommandState(\n    (state) => commandMetaMap.get(state.value)?.commandKind ?? \"page\"\n  );\n\n  const renderLogo = () => {\n    if (logo) return logo;\n    if (logoSrc) {\n      return (\n        <Image\n          src={logoSrc}\n          alt={logoAlt}\n          width={logoSize}\n          height={logoSize}\n          className=\"text-muted-foreground\"\n          unoptimized\n        />\n      );\n    }\n    return null;\n  };\n\n  return (\n    <>\n      <div className=\"flex h-10\" />\n      <div className=\"absolute inset-x-0 bottom-0 flex h-10 items-center justify-between gap-2 border-t bg-zinc-100/30 px-4 text-xs font-medium dark:bg-zinc-800/30\">\n        <div className=\"size-6\">{renderLogo()}</div>\n        <div className=\"flex shrink-0 items-center gap-2\">\n          <span>{actionLabels[selectedCommandKind]}</span>\n          <Kbd>\n            <CornerDownLeftIcon />\n          </Kbd>\n          <Separator\n            orientation=\"vertical\"\n            className=\"data-[orientation=vertical]:h-4\"\n          />\n          <span className=\"text-muted-foreground\">Exit</span>\n          <Kbd>Esc</Kbd>\n        </div>\n      </div>\n    </>\n  );\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Hook: useCommandBox\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface UseCommandBoxOptions {\n  /** Initial open state */\n  defaultOpen?: boolean;\n  /** Keyboard shortcut keys (default: \"mod+k, slash\") */\n  hotkeys?: string;\n  /** Callback when opened via keyboard */\n  onKeyboardOpen?: (key: string) => void;\n}\n\n/**\n * Hook to manage command box state with keyboard shortcuts.\n *\n * @example\n * ```tsx\n * const { open, setOpen, toggle } = useCommandBox();\n * ```\n */\nexport function useCommandBox({\n  defaultOpen = false,\n  hotkeys = \"mod+k, slash\",\n  onKeyboardOpen,\n}: UseCommandBoxOptions = {}) {\n  const [open, setOpen] = useState(defaultOpen);\n\n  useHotkeys(hotkeys, (e: KeyboardEvent) => {\n    e.preventDefault();\n    setOpen((prev) => {\n      if (!prev && onKeyboardOpen) {\n        const key = e.key === \"/\" ? \"/\" : e.metaKey ? \"cmd+k\" : \"ctrl+k\";\n        onKeyboardOpen(key);\n      }\n      return !prev;\n    });\n  });\n\n  const toggle = useCallback(() => setOpen((prev) => !prev), []);\n\n  return { open, setOpen, toggle };\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "https://jyotimoydas.in/components/command-box",
  "type": "registry:component"
}
