{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox",
  "title": "Combobox",
  "description": "A select with a search box, for long lists of options.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/command",
    "@corsair-ui/popover"
  ],
  "files": [
    {
      "path": "registry/default/ui/combobox.tsx",
      "content": "\"use client\";\n\nimport { CheckIcon, ChevronDownIcon } from \"lucide-react\";\nimport { useId, useState, type ComponentProps, type ReactNode } from \"react\";\n\nimport { cn } from \"@/registry/default/lib/utils\";\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n} from \"@/registry/default/ui/command\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"@/registry/default/ui/popover\";\n\ninterface ComboboxOption {\n  value: string;\n  label: string;\n  /** Extra words the search matches, e.g. an abbreviation or another spelling. */\n  keywords?: string[];\n  disabled?: boolean;\n}\n\ninterface ComboboxProps extends Omit<\n  ComponentProps<\"button\">,\n  \"value\" | \"defaultValue\" | \"onChange\" | \"children\"\n> {\n  options: ComboboxOption[];\n  value?: string | null;\n  defaultValue?: string | null;\n  onValueChange?: (value: string | null) => void;\n  placeholder?: ReactNode;\n  searchPlaceholder?: string;\n  /** Shown when the search matches no option. */\n  emptyMessage?: ReactNode;\n  /** Submits the value in a native form. */\n  name?: string;\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  contentClassName?: string;\n}\n\n/**\n * A select with a search box, for lists long enough that scrolling gets in\n * the way. Options are data (`options`), so it can be fed from an API.\n */\nfunction Combobox(props: ComboboxProps) {\n  const {\n    options,\n    value,\n    defaultValue,\n    onValueChange,\n    placeholder = \"Select an option\",\n    searchPlaceholder = \"Search…\",\n    emptyMessage = \"No results.\",\n    name,\n    open,\n    onOpenChange,\n    contentClassName,\n    className,\n    disabled,\n    ...buttonProps\n  } = props;\n  const controlled = \"value\" in props;\n  const listId = useId();\n  const [internalValue, setInternalValue] = useState(defaultValue ?? null);\n  const [internalOpen, setInternalOpen] = useState(false);\n  const current = controlled ? (value ?? null) : internalValue;\n  const isOpen = open ?? internalOpen;\n  const selected = options.find((option) => option.value === current);\n\n  const setOpen = (next: boolean) => {\n    if (open === undefined) setInternalOpen(next);\n    onOpenChange?.(next);\n  };\n  const select = (next: string) => {\n    if (!controlled) setInternalValue(next);\n    onValueChange?.(next);\n    setOpen(false);\n  };\n\n  return (\n    <Popover open={isOpen} onOpenChange={setOpen}>\n      <PopoverTrigger asChild>\n        {/* Points at the listbox rather than the popover, like a native combobox would. */}\n        <button\n          type=\"button\"\n          role=\"combobox\"\n          aria-expanded={isOpen}\n          aria-controls={listId}\n          data-slot=\"combobox-trigger\"\n          data-empty={!selected || undefined}\n          disabled={disabled}\n          className={cn(\n            \"border-input bg-field flex h-9 w-full cursor-pointer items-center justify-between gap-2 rounded-md border px-3 py-2 text-sm whitespace-nowrap sm:w-[16rem]\",\n            \"transition-[color,border-color,box-shadow] outline-none motion-reduce:transition-none\",\n            \"data-[empty=true]:text-muted-foreground\",\n            \"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n            \"aria-[invalid=true]:border-destructive aria-[invalid=true]:ring-destructive/20\",\n            \"disabled:cursor-not-allowed disabled:opacity-50\",\n            \"[&[data-state=open]>[data-slot=combobox-icon]]:rotate-180\",\n            className\n          )}\n          {...buttonProps}\n        >\n          <span className=\"truncate\">{selected ? selected.label : placeholder}</span>\n          <ChevronDownIcon\n            aria-hidden=\"true\"\n            data-slot=\"combobox-icon\"\n            className=\"text-muted-foreground size-4 shrink-0 opacity-50 transition-transform duration-200 motion-reduce:transition-none\"\n          />\n        </button>\n      </PopoverTrigger>\n      <PopoverContent\n        align=\"start\"\n        className={cn(\"w-[var(--radix-popover-trigger-width)] min-w-[12rem] p-0\", contentClassName)}\n      >\n        <Command>\n          <CommandInput placeholder={searchPlaceholder} />\n          <CommandList id={listId}>\n            <CommandEmpty>{emptyMessage}</CommandEmpty>\n            <CommandGroup>\n              {options.map((option) => (\n                <CommandItem\n                  key={option.value}\n                  value={option.value}\n                  keywords={[option.label, ...(option.keywords ?? [])]}\n                  disabled={option.disabled}\n                  onSelect={() => select(option.value)}\n                >\n                  <span className=\"truncate\">{option.label}</span>\n                  <CheckIcon\n                    aria-hidden=\"true\"\n                    className={cn(\n                      \"ml-auto\",\n                      option.value === current ? \"opacity-100\" : \"opacity-0\"\n                    )}\n                  />\n                </CommandItem>\n              ))}\n            </CommandGroup>\n          </CommandList>\n        </Command>\n      </PopoverContent>\n      {name ? <input type=\"hidden\" name={name} value={current ?? \"\"} /> : null}\n    </Popover>\n  );\n}\n\nexport { Combobox, type ComboboxOption, type ComboboxProps };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}