{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "multi-select",
  "type": "registry:ui",
  "title": "Multi select",
  "description": "A field for picking several values from a searchable list: the picks show as removable chips, with groups, disabled options, a limit, an empty state and new values created on the spot. Full keyboard support, controlled or uncontrolled.",
  "author": "DressCode UI <https://dresscodeui.com>",
  "dependencies": [
    "@base-ui/react@^1.9.0",
    "lucide-react@^1.73.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/dresscode/components/multi-select/ui/multi-select.tsx",
      "type": "registry:ui",
      "content": "\"use client\"\n\n// Multi select: pick several values from a searchable list. The picks sit in the field as removable\n// chips (folded into \"+N more\" while the field is idle, if you set maxChips), the list opens below\n// with a check box per option, and it can hold groups, disabled options, a most-picks limit, an empty\n// or loading state and a \"Create “…”\" row for values that are not in the list yet.\n//\n// Built on Base UI's Combobox in multiple mode, the primitive behind shadcn/ui's combobox, so the\n// keyboard works as people expect: type to filter, ArrowUp/ArrowDown to move, Enter to toggle,\n// Backspace in the empty input removes the last chip, ArrowLeft walks the chips (Backspace or Delete\n// removes the focused one), Escape closes the list. Unlike the primitive, Escape never wipes the picks.\n// Built for shadcn/ui; reads only the theme's variables.\n//\n//   <MultiSelect options={...} value={...} onValueChange={...} />   the ready field, for most cases\n//   <MultiSelectRoot> with MultiSelectField, MultiSelectValue, MultiSelectChip, MultiSelectInput,\n//   MultiSelectContent, MultiSelectList, MultiSelectItem, ...          the parts, to compose your own\nimport * as React from \"react\"\nimport { Combobox as ComboboxPrimitive } from \"@base-ui/react/combobox\"\nimport { CheckIcon, ChevronDownIcon, LoaderCircleIcon, PlusIcon, XIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype MultiSelectContextValue = {\n  anchorRef: React.RefObject<HTMLDivElement | null>\n  open: boolean\n  /** Focus is in the field or the list is open: every chip shows, none fold into \"+N more\". */\n  expanded: boolean\n  setFocused: (focused: boolean) => void\n  disabled: boolean\n}\n\nconst MultiSelectContext = React.createContext<MultiSelectContextValue | null>(null)\n\nfunction useMultiSelect() {\n  const context = React.useContext(MultiSelectContext)\n  if (!context) throw new Error(\"MultiSelect parts must be inside <MultiSelectRoot>.\")\n  return context\n}\n\n// ---------------------------------------------------------------------------------------------\n// The parts\n\ntype MultiSelectRootProps<Value> = Omit<ComboboxPrimitive.Root.Props<Value, true>, \"multiple\">\n\n/** Holds the picked values (value/defaultValue/onValueChange) and the list's open state. */\nfunction MultiSelectRoot<Value>({ open: openProp, defaultOpen = false, onOpenChange, disabled = false, ...props }: MultiSelectRootProps<Value>) {\n  const anchorRef = React.useRef<HTMLDivElement | null>(null)\n  const [openState, setOpenState] = React.useState(defaultOpen)\n  const [focused, setFocused] = React.useState(false)\n  const open = openProp ?? openState\n  const context = React.useMemo(\n    () => ({ anchorRef, open, expanded: open || focused, setFocused, disabled }),\n    [open, focused, disabled],\n  )\n  return (\n    <MultiSelectContext.Provider value={context}>\n      <ComboboxPrimitive.Root<Value, true>\n        multiple\n        open={open}\n        onOpenChange={(next, details) => {\n          onOpenChange?.(next, details)\n          if (!details.isCanceled) setOpenState(next)\n        }}\n        disabled={disabled}\n        {...props}\n      />\n    </MultiSelectContext.Provider>\n  )\n}\n\ntype MultiSelectFieldProps = Omit<ComboboxPrimitive.Chips.Props, \"className\" | \"ref\"> & { className?: string }\n\n/** The box that looks like an input: chips and the search input on the left, clear and the chevron on the right. */\nfunction MultiSelectField({ className, onFocus, onBlur, ...props }: MultiSelectFieldProps) {\n  const { anchorRef, setFocused, disabled } = useMultiSelect()\n  return (\n    <ComboboxPrimitive.Chips\n      ref={anchorRef}\n      data-slot=\"multi-select-field\"\n      data-disabled={disabled || undefined}\n      onFocus={(event) => {\n        onFocus?.(event)\n        setFocused(true)\n      }}\n      onBlur={(event) => {\n        onBlur?.(event)\n        if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setFocused(false)\n      }}\n      className={cn(\n        \"group/multi-select relative flex min-h-8 w-full min-w-0 cursor-text items-center gap-1 rounded-lg border border-input bg-transparent py-0.5 pr-1 pl-1 text-sm transition-[color,box-shadow,border-color] outline-none\",\n        \"focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50\",\n        \"has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20\",\n        \"data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** The wrapping row of chips and the input, inside MultiSelectField. */\nfunction MultiSelectChips({ className, ...props }: React.ComponentProps<\"div\">) {\n  return <div data-slot=\"multi-select-chips\" className={cn(\"flex min-w-0 flex-1 flex-wrap items-center gap-1\", className)} {...props} />\n}\n\ntype MultiSelectValueProps<Value> = {\n  /** Renders one chip; give it a key. */\n  children: (value: Value, index: number) => React.ReactNode\n  /** Chips to show while the field is idle. The rest fold into \"+N more\" until the field has focus. */\n  max?: number\n  /** Replaces the default \"+N more\" chip; gets the values that are folded away. */\n  overflow?: (hidden: Value[]) => React.ReactNode\n}\n\n/** The picked values as chips, in the order they were picked. */\nfunction MultiSelectValue<Value>({ children, max, overflow }: MultiSelectValueProps<Value>) {\n  const { expanded } = useMultiSelect()\n  return (\n    <ComboboxPrimitive.Value>\n      {(values: Value[]) => {\n        const fold = max !== undefined && !expanded && values.length > max\n        const shown = fold ? values.slice(0, max) : values\n        const hidden = fold ? values.slice(max) : []\n        return (\n          <>\n            {shown.map((value, index) => children(value, index))}\n            {hidden.length ? (overflow ? overflow(hidden) : <MultiSelectOverflow>+{hidden.length} more</MultiSelectOverflow>) : null}\n          </>\n        )\n      }}\n    </ComboboxPrimitive.Value>\n  )\n}\n\ntype MultiSelectChipProps = Omit<ComboboxPrimitive.Chip.Props, \"className\"> & {\n  className?: string\n  /** The remove button's accessible name, e.g. \"Remove Design\". */\n  removeLabel?: string\n  removable?: boolean\n}\n\nfunction MultiSelectChip({ className, children, removeLabel = \"Remove\", removable = true, ...props }: MultiSelectChipProps) {\n  return (\n    <ComboboxPrimitive.Chip\n      data-slot=\"multi-select-chip\"\n      className={cn(\n        \"flex h-6 max-w-full min-w-0 items-center gap-1 rounded-md bg-foreground/10 pl-2 text-xs font-medium text-foreground outline-none focus:ring-2 focus:ring-ring\",\n        removable ? \"pr-0.5\" : \"pr-2\",\n        className,\n      )}\n      {...props}\n    >\n      {typeof children === \"string\" ? <span className=\"truncate\">{children}</span> : children}\n      {removable ? (\n        <ComboboxPrimitive.ChipRemove\n          aria-label={removeLabel}\n          data-slot=\"multi-select-chip-remove\"\n          className=\"flex size-5 shrink-0 cursor-default items-center justify-center rounded-sm opacity-60 transition-opacity hover:bg-foreground/10 hover:opacity-100 disabled:pointer-events-none\"\n        >\n          <XIcon aria-hidden=\"true\" className=\"size-3\" />\n        </ComboboxPrimitive.ChipRemove>\n      ) : null}\n    </ComboboxPrimitive.Chip>\n  )\n}\n\n/** The \"+N more\" chip MultiSelectValue shows when it folds chips away. */\nfunction MultiSelectOverflow({ className, ...props }: React.ComponentProps<\"span\">) {\n  return (\n    <span\n      data-slot=\"multi-select-overflow\"\n      className={cn(\"flex h-6 shrink-0 items-center rounded-md border border-dashed border-border px-1.5 text-xs font-medium text-muted-foreground tabular-nums\", className)}\n      {...props}\n    />\n  )\n}\n\ntype MultiSelectInputProps = Omit<ComboboxPrimitive.Input.Props, \"className\"> & { className?: string }\n\nfunction MultiSelectInput({ className, onKeyDown, ...props }: MultiSelectInputProps) {\n  const { open, expanded } = useMultiSelect()\n  return (\n    <ComboboxPrimitive.Input\n      data-slot=\"multi-select-input\"\n      onKeyDown={(event) => {\n        onKeyDown?.(event)\n        // The primitive clears every pick on Escape while the list is closed; here Escape only closes it.\n        if (event.key === \"Escape\" && !open) event.preventBaseUIHandler()\n      }}\n      className={cn(\n        \"h-6 flex-1 bg-transparent px-1.5 text-base outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed md:text-sm\",\n        // Room to type while editing; while idle it squeezes in after the chips instead of taking a row.\n        expanded ? \"min-w-20\" : \"min-w-0 not-placeholder-shown:px-0\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\ntype MultiSelectButtonProps = Omit<ComboboxPrimitive.Clear.Props, \"className\"> & { className?: string }\n\nconst iconButton =\n  \"flex size-6 shrink-0 cursor-default items-center justify-center rounded-md text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none [&_svg]:size-4\"\n\n/** Removes every pick. Shows only while something is picked; reachable with Tab. */\nfunction MultiSelectClear({ className, children, ...props }: MultiSelectButtonProps) {\n  return (\n    <ComboboxPrimitive.Clear data-slot=\"multi-select-clear\" aria-label=\"Clear all\" tabIndex={0} className={cn(iconButton, className)} {...props}>\n      {children ?? <XIcon aria-hidden=\"true\" />}\n    </ComboboxPrimitive.Clear>\n  )\n}\n\ntype MultiSelectTriggerProps = Omit<ComboboxPrimitive.Trigger.Props, \"className\"> & { className?: string }\n\n/** The chevron that opens and closes the list. */\nfunction MultiSelectTrigger({ className, children, ...props }: MultiSelectTriggerProps) {\n  return (\n    <ComboboxPrimitive.Trigger\n      data-slot=\"multi-select-trigger\"\n      aria-label=\"Show options\"\n      className={cn(iconButton, \"[&_svg]:transition-transform data-popup-open:[&_svg]:rotate-180\", className)}\n      {...props}\n    >\n      {children ?? <ChevronDownIcon aria-hidden=\"true\" />}\n    </ComboboxPrimitive.Trigger>\n  )\n}\n\ntype MultiSelectContentProps = Omit<ComboboxPrimitive.Popup.Props, \"className\"> & { className?: string } & Pick<\n    ComboboxPrimitive.Positioner.Props,\n    \"side\" | \"align\" | \"sideOffset\" | \"alignOffset\"\n  >\n\n/** The list's popup, as wide as the field and anchored below it. */\nfunction MultiSelectContent({ className, side = \"bottom\", sideOffset = 6, align = \"start\", alignOffset = 0, ...props }: MultiSelectContentProps) {\n  const { anchorRef } = useMultiSelect()\n  return (\n    <ComboboxPrimitive.Portal>\n      <ComboboxPrimitive.Positioner anchor={anchorRef} side={side} sideOffset={sideOffset} align={align} alignOffset={alignOffset} className=\"isolate z-50\">\n        <ComboboxPrimitive.Popup\n          data-slot=\"multi-select-content\"\n          className={cn(\n            \"group/multi-select-content flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) origin-(--transform-origin) flex-col overflow-hidden rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100\",\n            \"data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2\",\n            className,\n          )}\n          {...props}\n        />\n      </ComboboxPrimitive.Positioner>\n    </ComboboxPrimitive.Portal>\n  )\n}\n\ntype MultiSelectListProps = Omit<ComboboxPrimitive.List.Props, \"className\"> & { className?: string }\n\nfunction MultiSelectList({ className, ...props }: MultiSelectListProps) {\n  return (\n    <ComboboxPrimitive.List\n      data-slot=\"multi-select-list\"\n      className={cn(\"max-h-72 min-h-0 flex-1 scroll-py-1 overflow-y-auto overscroll-contain p-1 data-empty:p-0\", className)}\n      {...props}\n    />\n  )\n}\n\nconst itemClass =\n  \"group/multi-select-item relative flex w-full cursor-default items-center gap-2.5 rounded-md px-2 py-1.5 text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0\"\n\ntype MultiSelectItemProps = Omit<ComboboxPrimitive.Item.Props, \"className\"> & { className?: string }\n\n/** An option with a check box that fills when it is picked. */\nfunction MultiSelectItem({ className, children, ...props }: MultiSelectItemProps) {\n  return (\n    <ComboboxPrimitive.Item data-slot=\"multi-select-item\" className={cn(itemClass, className)} {...props}>\n      <span\n        aria-hidden=\"true\"\n        data-slot=\"multi-select-check\"\n        className=\"flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input text-transparent transition-colors group-data-[selected]/multi-select-item:border-primary group-data-[selected]/multi-select-item:bg-primary group-data-[selected]/multi-select-item:text-primary-foreground\"\n      >\n        <CheckIcon className=\"size-3\" strokeWidth={3} />\n      </span>\n      {children}\n    </ComboboxPrimitive.Item>\n  )\n}\n\n/** The \"Create “…”\" row: an option without a check box, for a value that is not in the list yet. */\nfunction MultiSelectCreate({ className, children, ...props }: MultiSelectItemProps) {\n  return (\n    <ComboboxPrimitive.Item data-slot=\"multi-select-create\" className={cn(itemClass, className)} {...props}>\n      <span aria-hidden=\"true\" className=\"flex size-4 shrink-0 items-center justify-center text-muted-foreground group-data-highlighted/multi-select-item:text-accent-foreground\">\n        <PlusIcon className=\"size-4\" />\n      </span>\n      <span className=\"min-w-0 truncate\">{children}</span>\n    </ComboboxPrimitive.Item>\n  )\n}\n\ntype MultiSelectGroupProps = Omit<ComboboxPrimitive.Group.Props, \"className\"> & { className?: string }\n\nfunction MultiSelectGroup({ className, ...props }: MultiSelectGroupProps) {\n  return <ComboboxPrimitive.Group data-slot=\"multi-select-group\" className={cn(\"not-first:mt-1\", className)} {...props} />\n}\n\ntype MultiSelectGroupLabelProps = Omit<ComboboxPrimitive.GroupLabel.Props, \"className\"> & { className?: string }\n\nfunction MultiSelectGroupLabel({ className, ...props }: MultiSelectGroupLabelProps) {\n  return (\n    <ComboboxPrimitive.GroupLabel\n      data-slot=\"multi-select-group-label\"\n      className={cn(\"sticky top-0 z-10 -mx-1 bg-popover px-3 pt-2 pb-1 text-xs font-medium text-muted-foreground\", className)}\n      {...props}\n    />\n  )\n}\n\n/** Renders a group's items; use inside MultiSelectGroup with a function child. */\nconst MultiSelectCollection = ComboboxPrimitive.Collection\n\ntype MultiSelectEmptyProps = Omit<ComboboxPrimitive.Empty.Props, \"className\"> & { className?: string }\n\n/** Shows its children only when nothing matches (it stays mounted as a live region). */\nfunction MultiSelectEmpty({ className, ...props }: MultiSelectEmptyProps) {\n  return (\n    <ComboboxPrimitive.Empty\n      data-slot=\"multi-select-empty\"\n      className={cn(\"flex flex-col items-center justify-center gap-1 px-4 py-6 text-center text-sm text-muted-foreground empty:p-0\", className)}\n      {...props}\n    />\n  )\n}\n\nfunction MultiSelectSeparator({ className, ...props }: Omit<ComboboxPrimitive.Separator.Props, \"className\"> & { className?: string }) {\n  return <ComboboxPrimitive.Separator data-slot=\"multi-select-separator\" className={cn(\"-mx-1 my-1 h-px bg-border\", className)} {...props} />\n}\n\n/** A polite live region, e.g. \"4 results\", for screen readers. Usually with className=\"sr-only\". */\nfunction MultiSelectStatus({ className, ...props }: Omit<ComboboxPrimitive.Status.Props, \"className\"> & { className?: string }) {\n  return <ComboboxPrimitive.Status data-slot=\"multi-select-status\" className={className} {...props} />\n}\n\n/** A strip under the list for a hint such as \"2 of 3 picked\". */\nfunction MultiSelectFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"multi-select-footer\"\n      className={cn(\"flex items-center gap-2 border-t border-border px-3 py-2 text-xs text-muted-foreground\", className)}\n      {...props}\n    />\n  )\n}\n\n// ---------------------------------------------------------------------------------------------\n// The ready field\n\ntype MultiSelectOption = {\n  value: string\n  label: string\n  /** A second line under the label, such as a role or an email. Search matches it too. */\n  description?: string\n  /** More words search should match, such as a country code. */\n  keywords?: string[]\n  disabled?: boolean\n}\n\ntype MultiSelectOptionGroup<T extends MultiSelectOption = MultiSelectOption> = { label: string; options: readonly T[] }\n\nconst CREATE = Symbol(\"multi-select-create\")\ntype CreateEntry = MultiSelectOption & { [CREATE]: true }\ntype Entry<T> = T | CreateEntry\ntype EntryGroup<T> = { label: string | null; items: Entry<T>[] }\n\nconst isCreate = (entry: MultiSelectOption): entry is CreateEntry => CREATE in entry\nconst isGroup = <T extends MultiSelectOption>(entry: T | MultiSelectOptionGroup<T>): entry is MultiSelectOptionGroup<T> => \"options\" in entry\nconst normalize = (text: string) =>\n  text\n    .normalize(\"NFD\")\n    .replace(/[\\u0300-\\u036f]/g, \"\")\n    .toLowerCase()\nconst matches = (option: MultiSelectOption, query: string) =>\n  !query || [option.label, option.description ?? \"\", ...(option.keywords ?? [])].some((text) => normalize(text).includes(query))\n\ntype InputAriaProps = Pick<React.ComponentProps<\"input\">, \"aria-label\" | \"aria-labelledby\" | \"aria-describedby\" | \"aria-invalid\">\n\ntype MultiSelectProps<T extends MultiSelectOption> = InputAriaProps & {\n  /** A flat list, or groups of { label, options }. Options outside a group list first. */\n  options: readonly (T | MultiSelectOptionGroup<T>)[]\n  /** The picked option values, when controlled. */\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (value: string[]) => void\n  /** Shown while nothing is picked. */\n  placeholder?: string\n  /** Most picks allowed. Once full, the options not picked are disabled and the list says so. */\n  max?: number\n  /** Chips to show while the field is idle; the rest fold into \"+N more\" until it has focus. */\n  maxChips?: number\n  /** Offer \"Create “…”\" when the typed text matches no option's label. */\n  creatable?: boolean\n  /** Called with the typed text when someone creates a value. Return the new option, or nothing to use the text as value and label. */\n  onCreate?: (label: string) => T | void\n  /** What the list says when nothing matches. A function gets the typed text. */\n  emptyMessage?: React.ReactNode | ((query: string) => React.ReactNode)\n  /** Show a spinner row instead of the options, e.g. while they load from your API. */\n  loading?: boolean\n  loadingMessage?: React.ReactNode\n  /** An option's content after its check box. Defaults to the label with the description under it. */\n  renderOption?: (option: T) => React.ReactNode\n  /** A chip's content. Defaults to the label. */\n  renderChip?: (option: T) => React.ReactNode\n  chipClassName?: string\n  /** A strip under the list. With max set it defaults to \"N of max picked\"; pass null to hide it. */\n  footer?: React.ReactNode\n  /** Show the clear-all button while something is picked. */\n  clearable?: boolean\n  open?: boolean\n  onOpenChange?: (open: boolean) => void\n  disabled?: boolean\n  required?: boolean\n  /** Submits each picked value under this name with the form. */\n  name?: string\n  /** Goes on the input, for <Label htmlFor>. */\n  id?: string\n  className?: string\n}\n\nfunction MultiSelect<T extends MultiSelectOption = MultiSelectOption>({\n  options,\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  placeholder = \"Select…\",\n  max,\n  maxChips,\n  creatable = false,\n  onCreate,\n  emptyMessage = \"No matches.\",\n  loading = false,\n  loadingMessage = \"Loading…\",\n  renderOption,\n  renderChip,\n  chipClassName,\n  footer,\n  clearable = true,\n  open,\n  onOpenChange,\n  disabled,\n  required,\n  name,\n  id,\n  className,\n  ...aria\n}: MultiSelectProps<T>) {\n  const [valueState, setValueState] = React.useState<string[]>(defaultValue ?? [])\n  const value = valueProp ?? valueState\n  const [query, setQuery] = React.useState(\"\")\n  const [created, setCreated] = React.useState<T[]>([])\n\n  const grouped = options.some(isGroup)\n  const groups = React.useMemo(() => {\n    const loose = options.filter((o): o is T => !isGroup(o))\n    const list: { label: string | null; options: readonly T[] }[] = [\n      ...(loose.length || !options.some(isGroup) ? [{ label: null, options: loose }] : []),\n      ...options.filter(isGroup).map((g) => ({ label: g.label, options: g.options })),\n    ]\n    const known = new Set(list.flatMap((g) => g.options.map((o) => o.value)))\n    const extra = created.filter((o) => !known.has(o.value))\n    if (extra.length) {\n      if (list.length === 1 && list[0].label === null) list[0] = { label: null, options: [...list[0].options, ...extra] }\n      else list.push({ label: \"Added by you\", options: extra })\n    }\n    return list\n  }, [options, created])\n  const byValue = React.useMemo(() => new Map(groups.flatMap((g) => g.options.map((o) => [o.value, o] as const))), [groups])\n  const selected = React.useMemo(() => value.map((v) => byValue.get(v) ?? ({ value: v, label: v } as T)), [value, byValue])\n  const full = max !== undefined && value.length >= max\n\n  const trimmed = query.trim().replace(/\\s+/g, \" \")\n  const q = normalize(trimmed)\n  const createEntry: CreateEntry | null =\n    creatable && trimmed && ![...byValue.values()].some((o) => normalize(o.label) === q) ? { value: `\\u0000create:${trimmed}`, label: trimmed, [CREATE]: true } : null\n\n  const allGroups: EntryGroup<T>[] = groups.map((g) => ({ label: g.label, items: [...g.options] }))\n  const shownGroups: EntryGroup<T>[] = loading\n    ? []\n    : groups.map((g) => ({ label: g.label, items: g.options.filter((o) => matches(o, q)) as Entry<T>[] })).filter((g) => g.items.length)\n  if (createEntry && !loading) {\n    if (grouped) shownGroups.push({ label: null, items: [createEntry] })\n    else if (shownGroups.length) shownGroups[0].items.push(createEntry)\n    else shownGroups.push({ label: null, items: [createEntry] })\n  }\n  const shownCount = shownGroups.reduce((n, g) => n + g.items.filter((e) => !isCreate(e)).length, 0)\n\n  const setValue = (next: string[]) => {\n    if (valueProp === undefined) setValueState(next)\n    onValueChange?.(next)\n  }\n  const handleChange = (next: Entry<T>[]) => {\n    const kept = next.filter((e) => !isCreate(e)).map((e) => e.value)\n    const create = next.find(isCreate)\n    if (!create) return setValue(kept)\n    const made = onCreate?.(create.label) ?? ({ value: create.label, label: create.label } as T)\n    if (!byValue.has(made.value)) setCreated((list) => [...list, made])\n    setValue([...kept.filter((v) => v !== made.value), made.value])\n  }\n\n  const renderEntry = (entry: Entry<T>) =>\n    isCreate(entry) ? (\n      <MultiSelectCreate key={entry.value} value={entry} disabled={full}>\n        Create “{entry.label}”\n      </MultiSelectCreate>\n    ) : (\n      <MultiSelectItem key={entry.value} value={entry} disabled={entry.disabled || (full && !value.includes(entry.value))}>\n        {renderOption ? (\n          renderOption(entry)\n        ) : (\n          <span className=\"flex min-w-0 flex-1 flex-col\">\n            <span className=\"truncate\">{entry.label}</span>\n            {entry.description ? <span className=\"truncate text-xs text-muted-foreground\">{entry.description}</span> : null}\n          </span>\n        )}\n      </MultiSelectItem>\n    )\n\n  const footerContent =\n    footer !== undefined ? footer : max !== undefined ? (full ? `${max} of ${max} picked. Remove one to pick another.` : `${value.length} of ${max} picked`) : null\n\n  return (\n    <MultiSelectRoot<Entry<T>>\n      items={grouped ? allGroups : allGroups[0].items}\n      filteredItems={grouped ? shownGroups : (shownGroups[0]?.items ?? [])}\n      value={selected}\n      onValueChange={handleChange}\n      inputValue={query}\n      onInputValueChange={setQuery}\n      isItemEqualToValue={(a, b) => a.value === b.value}\n      itemToStringLabel={(entry) => entry.label}\n      itemToStringValue={(entry) => entry.value}\n      autoHighlight\n      open={open}\n      onOpenChange={onOpenChange ? (next) => onOpenChange(next) : undefined}\n      disabled={disabled}\n      required={required}\n      name={name}\n      id={id}\n    >\n      <MultiSelectField className={className}>\n        <MultiSelectChips>\n          <MultiSelectValue<Entry<T>>\n            max={maxChips}\n            overflow={(hidden) => (\n              <MultiSelectOverflow title={hidden.map((h) => h.label).join(\", \")}>\n                +{hidden.length} more\n              </MultiSelectOverflow>\n            )}\n          >\n            {(entry) => (\n              <MultiSelectChip key={entry.value} removeLabel={`Remove ${entry.label}`} className={chipClassName}>\n                {renderChip && !isCreate(entry) ? renderChip(entry) : entry.label}\n              </MultiSelectChip>\n            )}\n          </MultiSelectValue>\n          <MultiSelectInput placeholder={value.length ? undefined : placeholder} {...aria} />\n        </MultiSelectChips>\n        {clearable ? <MultiSelectClear /> : null}\n        <MultiSelectTrigger />\n      </MultiSelectField>\n      <MultiSelectContent>\n        <MultiSelectStatus className=\"sr-only\">{trimmed && !loading ? `${shownCount} ${shownCount === 1 ? \"result\" : \"results\"}` : \"\"}</MultiSelectStatus>\n        <MultiSelectEmpty>\n          {loading ? (\n            <span className=\"flex items-center gap-2\">\n              <LoaderCircleIcon aria-hidden=\"true\" className=\"size-4 animate-spin\" />\n              {loadingMessage}\n            </span>\n          ) : typeof emptyMessage === \"function\" ? (\n            emptyMessage(trimmed)\n          ) : (\n            emptyMessage\n          )}\n        </MultiSelectEmpty>\n        <MultiSelectList>\n          {grouped\n            ? (group: EntryGroup<T>, index: number) => (\n                <MultiSelectGroup key={group.label ?? `group-${index}`} items={group.items}>\n                  {group.label ? <MultiSelectGroupLabel>{group.label}</MultiSelectGroupLabel> : null}\n                  <MultiSelectCollection>{(entry: Entry<T>) => renderEntry(entry)}</MultiSelectCollection>\n                </MultiSelectGroup>\n              )\n            : (entry: Entry<T>) => renderEntry(entry)}\n        </MultiSelectList>\n        {footerContent ? <MultiSelectFooter aria-live=\"polite\">{footerContent}</MultiSelectFooter> : null}\n      </MultiSelectContent>\n    </MultiSelectRoot>\n  )\n}\n\nexport {\n  MultiSelect,\n  MultiSelectChip,\n  MultiSelectChips,\n  MultiSelectClear,\n  MultiSelectCollection,\n  MultiSelectContent,\n  MultiSelectCreate,\n  MultiSelectEmpty,\n  MultiSelectField,\n  MultiSelectFooter,\n  MultiSelectGroup,\n  MultiSelectGroupLabel,\n  MultiSelectInput,\n  MultiSelectItem,\n  MultiSelectList,\n  MultiSelectOverflow,\n  MultiSelectRoot,\n  MultiSelectSeparator,\n  MultiSelectStatus,\n  MultiSelectTrigger,\n  MultiSelectValue,\n  type MultiSelectOption,\n  type MultiSelectOptionGroup,\n  type MultiSelectProps,\n}\n"
    }
  ],
  "docs": "Multi select is in components/ui. Examples: https://dresscodeui.com/components/multi-select"
}
