{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select-search",
  "title": "Select Search",
  "description": "Searchable single-select combobox built on Popover and Command.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "command",
    "popover"
  ],
  "files": [
    {
      "path": "components/dentil/select-search/select-search.tsx",
      "content": "'use client';\n\nimport { CheckIcon, ChevronDownIcon } from 'lucide-react';\nimport * as React from 'react';\n\nimport { Button } from '@/components/ui/button';\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  CommandSeparator,\n} from '@/components/ui/command';\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';\nimport { cn } from '@/lib/utils';\n\n/** A Lucide-style icon component, or any node such as a flag or a currency symbol. */\nexport type SelectSearchIcon = React.ReactNode | React.ComponentType<{ className?: string }>;\n\nexport interface SelectSearchOption {\n  label: string;\n  value: string;\n  /** Extra terms the search matches, on top of the label and value. */\n  keywords?: string[];\n  /** Shown before the label, in the list and on the trigger. */\n  icon?: SelectSearchIcon;\n  /** Muted text after the label, in the list only. Search matches it. */\n  description?: string;\n  /** Classes for the label. With a description, the label stays a fixed column. */\n  labelClassName?: string;\n}\n\nexport type SelectSearchFilter = (value: string, search: string, keywords?: string[]) => number;\n\nexport interface SelectSearchProps extends Omit<\n  React.ComponentProps<'button'>,\n  'value' | 'onChange' | 'children' | 'type'\n> {\n  options: SelectSearchOption[];\n  value: string | null | undefined;\n  /** Called with the selected value, or `''` when the selected option is picked again. */\n  onChange: (value: string) => void;\n  placeholder?: string;\n  searchPlaceholder?: string;\n  emptyText?: React.ReactNode;\n  filter?: SelectSearchFilter;\n  /**\n   * Render `options` in these groups, with a separator between them.\n   * The separator hides while searching, and a group hides when none of its options match.\n   * `options` is still used for the selected label.\n   */\n  groups?: SelectSearchOption[][];\n  /** Trigger content in place of the selected option's icon and label. */\n  renderValue?: (selected: SelectSearchOption | undefined) => React.ReactNode;\n  /** Popover alignment against the trigger. */\n  align?: 'start' | 'center' | 'end';\n  contentClassName?: string;\n}\n\nfunction isIconComponent(icon: SelectSearchIcon): icon is React.ComponentType<{ className?: string }> {\n  if (typeof icon === 'function') return true;\n  return typeof icon === 'object' && icon !== null && !React.isValidElement(icon) && '$$typeof' in icon;\n}\n\nfunction OptionIcon({ icon }: { icon: SelectSearchIcon }) {\n  if (icon == null || typeof icon === 'boolean') return null;\n  if (isIconComponent(icon)) {\n    const Icon = icon;\n    return (\n      <span aria-hidden=\"true\" className=\"text-muted-foreground flex shrink-0 items-center\">\n        <Icon className=\"size-4\" />\n      </span>\n    );\n  }\n  const text = typeof icon === 'string' || typeof icon === 'number';\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={cn(\n        \"text-muted-foreground flex shrink-0 items-center [&_svg:not([class*='size-'])]:size-4\",\n        text && 'min-w-6 justify-center'\n      )}>\n      {icon}\n    </span>\n  );\n}\n\nconst defaultFilter: SelectSearchFilter = (value, search, keywords) => {\n  const query = search.toLowerCase();\n  if (value.toLowerCase().includes(query)) return 1;\n  if (keywords?.some((keyword) => keyword.toLowerCase().includes(query))) return 1;\n  return 0;\n};\n\nexport function SelectSearch({\n  options,\n  value,\n  onChange,\n  placeholder = 'Select...',\n  searchPlaceholder = 'Search...',\n  emptyText = 'No results.',\n  filter = defaultFilter,\n  groups,\n  renderValue,\n  align = 'start',\n  contentClassName,\n  disabled = false,\n  className,\n  ...props\n}: SelectSearchProps) {\n  const [open, setOpen] = React.useState(false);\n  const [width, setWidth] = React.useState<number>();\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n\n  const selected = value ? options.find((option) => option.value === value) : undefined;\n  const lists = groups?.filter((group) => group.length > 0);\n  const rendered = lists && lists.length > 0 ? lists : [options];\n\n  const renderOption = (option: SelectSearchOption) => (\n    <CommandItem\n      key={option.value}\n      value={option.value}\n      keywords={[option.label, ...(option.description ? [option.description] : []), ...(option.keywords ?? [])]}\n      onSelect={(current) => {\n        onChange(current === value ? '' : current);\n        setOpen(false);\n      }}>\n      {option.icon != null && <OptionIcon icon={option.icon} />}\n      {option.description ? (\n        <>\n          <span className={cn('shrink-0', option.labelClassName)}>{option.label}</span>\n          <span className=\"text-muted-foreground min-w-0 truncate\">{option.description}</span>\n        </>\n      ) : (\n        <span className={cn('min-w-0 truncate', option.labelClassName)}>{option.label}</span>\n      )}\n      <CheckIcon\n        className={cn('ml-auto size-4', option.value === value ? 'opacity-100' : 'opacity-0')}\n        aria-hidden=\"true\"\n      />\n    </CommandItem>\n  );\n\n  const handleOpenChange = (next: boolean) => {\n    if (next) setWidth(triggerRef.current?.offsetWidth);\n    setOpen(next);\n  };\n\n  return (\n    <Popover open={open} onOpenChange={handleOpenChange}>\n      <PopoverTrigger asChild>\n        <Button\n          ref={triggerRef}\n          type=\"button\"\n          variant=\"outline\"\n          role=\"combobox\"\n          aria-expanded={open}\n          disabled={disabled}\n          data-slot=\"select-search\"\n          className={cn('w-full justify-between px-3 font-normal', className)}\n          {...props}>\n          {renderValue ? (\n            renderValue(selected)\n          ) : (\n            <span className={cn('flex min-w-0 items-center gap-2', !selected && 'text-muted-foreground')}>\n              {selected?.icon != null && <OptionIcon icon={selected.icon} />}\n              <span className=\"min-w-0 truncate\">{selected ? selected.label : placeholder}</span>\n            </span>\n          )}\n          <ChevronDownIcon className=\"text-muted-foreground size-4 shrink-0\" aria-hidden=\"true\" />\n        </Button>\n      </PopoverTrigger>\n      <PopoverContent className={cn('min-w-48 p-0', contentClassName)} style={{ width }} align={align}>\n        <Command filter={filter}>\n          <CommandInput placeholder={searchPlaceholder} />\n          <CommandList>\n            <CommandEmpty>{emptyText}</CommandEmpty>\n            {rendered.map((list, index) => (\n              <React.Fragment key={index}>\n                {index > 0 && <CommandSeparator />}\n                <CommandGroup>{list.map(renderOption)}</CommandGroup>\n              </React.Fragment>\n            ))}\n          </CommandList>\n        </Command>\n      </PopoverContent>\n    </Popover>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/dentil/select-search/select-search.tsx"
    }
  ],
  "type": "registry:component"
}
