{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "multi-select",
  "title": "Multi-select",
  "description": "A field for several values from a searchable list, shown as chips you can remove, built on the shadcn Combobox so its list follows your style and font.",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "button",
    "combobox"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/multi-select.tsx",
      "content": "'use client'\n\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { Combobox as ComboboxPrimitive } from '@base-ui/react/combobox'\nimport { type ReactNode, useState } from 'react'\n\nimport { buttonVariants } from '@/components/ui/button'\nimport {\n  Combobox,\n  ComboboxChip,\n  ComboboxChips,\n  ComboboxChipsInput,\n  ComboboxContent,\n  ComboboxEmpty,\n  ComboboxItem,\n  ComboboxList,\n  ComboboxValue,\n  useComboboxAnchor,\n} from '@/components/ui/combobox'\n\ninterface MultiSelectOption<V extends string = string> {\n  disabled?: boolean\n  /** Drawn before the label, in the list and on its chip, such as a flag or an avatar. */\n  icon?: ReactNode\n  label: string\n  value: V\n}\n\ninterface MultiSelectProps<V extends string = string> {\n  'aria-describedby'?: string\n  'aria-invalid'?: boolean\n  'aria-label'?: string\n  /**\n   * Name the field with this rather than a `<label htmlFor>` alone: while the list is open,\n   * Base UI hides the rest of the page from screen readers, the label included.\n   */\n  'aria-labelledby'?: string\n  className?: string\n  disabled?: boolean\n  id?: string\n  /** Submits each picked value under this name, as a native multiple select does. */\n  name?: string\n  onValueChange?: (value: V[]) => void\n  options: readonly MultiSelectOption<V>[]\n  /** Shown while nothing is picked. */\n  placeholder?: string\n  /** The values picked, in the order they were picked. */\n  value: readonly V[]\n}\n\nfunction MultiSelect<V extends string>({\n  className,\n  disabled,\n  name,\n  onValueChange,\n  options,\n  placeholder,\n  value,\n  ...props\n}: MultiSelectProps<V>) {\n  const anchor = useComboboxAnchor()\n  const [query, setQuery] = useState('')\n  const picked = value\n    .map((item) => options.find((option) => option.value === item))\n    .filter((option) => option !== undefined)\n\n  return (\n    <Combobox\n      autoHighlight\n      disabled={disabled}\n      inputValue={query}\n      isItemEqualToValue={(item, current) => item.value === current.value}\n      itemToStringLabel={(item) => item.label}\n      itemToStringValue={(item) => item.value}\n      items={options}\n      multiple\n      name={name}\n      value={picked}\n      onInputValueChange={setQuery}\n      onValueChange={(next, details) => {\n        // Base UI clears every pick on Escape; let Escape close what's around the field instead.\n        if (details.reason === 'escape-key') {\n          details.allowPropagation()\n          return\n        }\n        onValueChange?.(next.map((option) => option.value))\n      }}\n    >\n      <ComboboxChips ref={anchor} className={className}>\n        <ComboboxValue>\n          {(items: MultiSelectOption<V>[]) =>\n            items.map((item) => (\n              <ComboboxChip\n                key={item.value}\n                className='[&_svg]:size-3.5'\n                showRemove={false}\n              >\n                {item.icon}\n                {item.label}\n                <ComboboxPrimitive.ChipRemove\n                  aria-label={`Remove ${item.label}`}\n                  className={buttonVariants({\n                    className: '-ml-1 opacity-50 hover:opacity-100',\n                    size: 'icon-xs',\n                    variant: 'ghost',\n                  })}\n                  data-slot='combobox-chip-remove'\n                >\n                  <IconPlaceholder\n                    lucide='XIcon'\n                    tabler='IconX'\n                    hugeicons='Cancel01Icon'\n                    phosphor='XIcon'\n                    remixicon='RiCloseLine'\n                    className='pointer-events-none'\n                  />\n                </ComboboxPrimitive.ChipRemove>\n              </ComboboxChip>\n            ))\n          }\n        </ComboboxValue>\n        <ComboboxChipsInput\n          {...props}\n          placeholder={picked.length === 0 ? placeholder : undefined}\n        />\n      </ComboboxChips>\n      <ComboboxContent anchor={anchor}>\n        <ComboboxEmpty>Nothing matches “{query.trim()}”.</ComboboxEmpty>\n        <ComboboxList>\n          {(item: MultiSelectOption<V>) => (\n            <ComboboxItem key={item.value} disabled={item.disabled} value={item}>\n              {item.icon}\n              {item.label}\n            </ComboboxItem>\n          )}\n        </ComboboxList>\n      </ComboboxContent>\n    </Combobox>\n  )\n}\n\nexport { MultiSelect }\nexport type { MultiSelectOption, MultiSelectProps }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/multi-select.tsx"
    }
  ],
  "type": "registry:component"
}
