{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select",
  "title": "Select",
  "description": "Fully custom single or multi select: outline, filled, ghost, underline, pill and neo triggers; icons, avatars, descriptions and groups; search with match highlight, chips, clear, type-ahead and full keyboard; animated menu that flips up when space runs out.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/core/select.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring, ease as easing } from \"@/lib/goodui-motion\"\n\n/*\n * A fully custom select, independent layers: every axis combines with every other.\n *   variant    outline, filled, ghost, underline, pill, neo      tone      accent for focus and selection\n *   size       sm, md, lg                                         shadow    trigger elevation\n *   animation  none, fade-scale, slide, stagger (menu open)\n *   behaviour  single or multiple (chips), searchable, clearable, groups, icons, avatars, descriptions\n * Keyboard: ↑ ↓ Home End, Enter/Space to pick, Esc to close, type to jump, Backspace removes the last chip.\n * The menu lives inside the component (no portal) and flips up when there is no room below.\n * options can be objects, plain strings, or one comma-separated string: \"Haircut, Beard trim\".\n */\n\nexport type SelectVariant = \"outline\" | \"filled\" | \"ghost\" | \"underline\" | \"pill\" | \"neo\"\nexport type SelectTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type SelectSize = \"sm\" | \"md\" | \"lg\"\nexport type SelectShadow = \"none\" | \"sm\" | \"md\" | \"lg\"\nexport type SelectAnimation = \"none\" | \"fade-scale\" | \"slide\" | \"stagger\"\n\nexport type SelectOption = {\n  /** Unique value reported by onValueChange. */\n  value: string\n  /** Text shown in the menu and the trigger; used for search and type-ahead. */\n  label: string\n  /** Muted second line in the menu; also searched. */\n  description?: string\n  icon?: React.ReactNode\n  /** Image URL, or true for colored initials. */\n  avatar?: string | true\n  /** Section heading; options with the same group are shown together. */\n  group?: string\n  disabled?: boolean\n  /** Extra search terms. */\n  keywords?: string[]\n}\n\ntype SelectBase = Omit<React.ComponentProps<\"div\">, \"defaultValue\" | \"onChange\" | \"children\"> & {\n  /** Option objects, plain strings, or one comma-separated string: \"Haircut, Beard trim\". */\n  options?: (SelectOption | string)[] | string\n  /** Trigger text when nothing is selected. */\n  placeholder?: string\n  /** Trigger style: outline (default), filled, ghost, underline, pill or neo. */\n  variant?: SelectVariant\n  /** Accent for focus ring, selected option, checkboxes and chips. */\n  tone?: SelectTone\n  size?: SelectSize\n  /** Trigger shadow. Ignored by neo. */\n  shadow?: SelectShadow\n  /** How the menu opens: fade-scale (default), slide (unrolls), stagger (options one by one) or none. */\n  animation?: SelectAnimation\n  /** Search box at the top of the menu. */\n  searchable?: boolean\n  /** Placeholder and accessible name of the search box. */\n  searchPlaceholder?: string\n  /** × button that resets the value. */\n  clearable?: boolean\n  disabled?: boolean\n  /** Red border and aria-invalid on the trigger. */\n  invalid?: boolean\n  /** Leading icon in the trigger. */\n  icon?: React.ReactNode\n  /** Form field name (renders hidden inputs). */\n  name?: string\n  /** Shown when the search has no matches. */\n  emptyText?: string\n  /** Multiple: chips shown before \"+N\". */\n  maxChips?: number\n  /** Menu open state (controlled). */\n  open?: boolean\n  /** Initial open state when uncontrolled. */\n  defaultOpen?: boolean\n  /** Called when the menu opens or closes. */\n  onOpenChange?: (open: boolean) => void\n  /** Class for the dropdown menu. */\n  menuClassName?: string\n  /** Names the trigger and the listbox. Pass one unless a visible <label htmlFor={id}> points at the select. */\n  \"aria-label\"?: string\n  /** Goes on the combobox trigger, so <label htmlFor> works. */\n  id?: string\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<SelectLabels>\n}\nexport type SelectSingleProps = SelectBase & {\n  /** true picks several values, shown as chips; value then becomes string[]. */\n  multiple?: false\n  /** Selected value (controlled): a string or null, or string[] with multiple. */\n  value?: string | null\n  /** Initial value when uncontrolled (string[] with multiple). */\n  defaultValue?: string | null\n  /** Called with the picked value (null after clearing), or with the full string[] with multiple. */\n  onValueChange?: (value: string | null) => void\n}\nexport type SelectMultipleProps = SelectBase & {\n  multiple: true\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (value: string[]) => void\n}\nexport type SelectProps = SelectSingleProps | SelectMultipleProps\n\nexport type SelectLabels = { clear: string; selectedHint: (selected: string) => string; remove: (label: string) => string }\nconst DEFAULT_LABELS: SelectLabels = {\n  clear: \"Clear selection\",\n  selectedHint: (selected) => `${selected} selected. Backspace removes the last one.`,\n  remove: (label) => `Remove ${label}`,\n}\n\nconst CSS = `\n.pc-select{--pc-c:var(--primary);--pc-fg:var(--primary-foreground)}\n.pc-select[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.pc-select[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.pc-select[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.pc-select[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.pc-select[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .pc-select[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .pc-select[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .pc-select[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.pc-select{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.pc-select[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n.pc-select{--pc-ring:color-mix(in oklab,var(--pc-c) 32%,transparent);--pc-edge:color-mix(in oklab,var(--pc-c) 55%,var(--border))}\n.pc-select{--pc-muted:color-mix(in oklab,var(--muted-foreground) 80%,var(--foreground))}\n\n.pc-select-trigger{position:relative;color:var(--foreground);transition:border-color .15s,background-color .15s,box-shadow .15s,transform .12s}\n.pc-select[data-variant=outline] .pc-select-trigger,.pc-select[data-variant=pill] .pc-select-trigger{background:var(--background);border:1px solid var(--input)}\n.pc-select[data-variant=outline] .pc-select-trigger:hover,.pc-select[data-variant=pill] .pc-select-trigger:hover{border-color:color-mix(in oklab,var(--pc-c) 30%,var(--input))}\n.pc-select[data-variant=filled] .pc-select-trigger{background:var(--muted);border:1px solid transparent}\n.pc-select[data-variant=filled] .pc-select-trigger:hover{background:color-mix(in oklab,var(--foreground) 7%,var(--muted))}\n.pc-select[data-variant=filled][data-open] .pc-select-trigger{background:var(--background)}\n.pc-select[data-variant=ghost] .pc-select-trigger{border:1px solid transparent}\n.pc-select[data-variant=ghost] .pc-select-trigger:hover,.pc-select[data-variant=ghost][data-open] .pc-select-trigger{background:var(--pc-tint)}\n.pc-select[data-variant=underline] .pc-select-trigger{border-radius:0;border-bottom:1.5px solid var(--input);padding-inline:.125rem}\n.pc-select[data-variant=underline] .pc-select-trigger::after{content:\"\";position:absolute;left:0;right:0;bottom:-1.5px;height:2px;background:var(--pc-c);transform:scaleX(0);transition:transform .25s var(--pc-ease-out)}\n.pc-select[data-variant=underline][data-open] .pc-select-trigger::after,.pc-select[data-variant=underline] .pc-select-trigger:focus-within::after{transform:scaleX(1)}\n.pc-select[data-variant=neo] .pc-select-trigger{background:var(--background);border:2px solid var(--foreground);box-shadow:3px 3px 0 var(--foreground)}\n.pc-select[data-variant=neo][data-open] .pc-select-trigger{transform:translate(1px,1px);box-shadow:2px 2px 0 var(--foreground)}\n.pc-select:not([data-variant=underline]):not([data-variant=neo]):not([data-variant=ghost])[data-open] .pc-select-trigger,\n.pc-select:not([data-variant=underline]):not([data-variant=neo]) .pc-select-trigger:has(:focus-visible){border-color:var(--pc-edge);box-shadow:0 0 0 3px var(--pc-ring)}\n.pc-select[data-variant=neo] .pc-select-trigger:has(:focus-visible){outline:2px solid var(--pc-c);outline-offset:3px}\n.pc-select[data-invalid] .pc-select-trigger{border-color:oklch(0.56 0.21 27)}\n.pc-select[data-variant=underline][data-invalid] .pc-select-trigger::after{background:oklch(0.56 0.21 27);transform:scaleX(1)}\n.pc-select[data-shadow=sm] .pc-select-trigger{box-shadow:var(--pc-e1)}\n.pc-select[data-shadow=md] .pc-select-trigger{box-shadow:var(--pc-e2)}\n.pc-select[data-shadow=lg] .pc-select-trigger{box-shadow:var(--pc-e3)}\n.pc-select-chev{transition:transform .2s var(--pc-ease-out);color:var(--pc-muted)}\n.pc-select-muted{color:var(--pc-muted)}\n.pc-select[data-open] .pc-select-chev{transform:rotate(180deg)}\n\n.pc-select-menu{background:var(--popover);color:var(--popover-foreground);border:1px solid transparent;box-shadow:var(--pc-e2)}\n.pc-select[data-variant=neo] .pc-select-menu{border:2px solid var(--foreground);box-shadow:4px 4px 0 var(--foreground)}\n.pc-select-opt{position:relative;z-index:1;color:var(--foreground)}\n/* One highlight glides between options instead of each option lighting up on its own. */\n.pc-select-list{position:relative;isolation:isolate}\n.pc-select-glide{position:absolute;top:0;inset-inline:0;height:var(--pc-gl-h,0);transform:translateY(var(--pc-gl-y,0));opacity:0;z-index:0;pointer-events:none;background:color-mix(in oklab,var(--pc-c) 6%,var(--accent));transition:transform 150ms var(--pc-ease-out),height 150ms var(--pc-ease-out),opacity 100ms ease}\n.pc-select-glide[data-on]{opacity:1}\n.pc-select-opt[data-selected]{color:var(--pc-ink)}\n.pc-select[data-tone=neutral] .pc-select-opt[data-selected],.pc-select[data-tone=primary] .pc-select-opt[data-selected]{color:var(--foreground)}\n.pc-select-opt[aria-disabled=true]{cursor:not-allowed}\n.pc-select-opt[aria-disabled=true]>*{opacity:.45}\n.pc-select-check{color:var(--pc-c)}\n.pc-select-box{border:1.5px solid color-mix(in oklab,var(--foreground) 25%,transparent);transition:background-color .12s,border-color .12s}\n.pc-select-opt[data-selected] .pc-select-box{background:var(--pc-c);border-color:var(--pc-c);color:var(--pc-fg)}\n.pc-select-chip{background:color-mix(in oklab,var(--pc-c) 10%,var(--muted));color:var(--foreground);border:1px solid color-mix(in oklab,var(--pc-c) 16%,transparent)}\n.pc-select[data-variant=neo] .pc-select-chip{border:1.5px solid var(--foreground);background:color-mix(in oklab,var(--pc-c) 18%,var(--background))}\n.pc-select-hl{background:none;color:inherit;font-weight:600;text-decoration:underline;text-decoration-color:color-mix(in oklab,var(--pc-c) 60%,transparent);text-decoration-thickness:2px;text-underline-offset:2px}\n@media (prefers-reduced-motion:reduce){.pc-select-glide,.pc-select-trigger,.pc-select-chev,.pc-select-trigger::after{transition:none!important}}\n`\n\nconst SIZES = {\n  sm: { trigger: \"min-h-8 px-2.5 text-sm gap-1.5\", chip: \"h-5 text-[11px]\", opt: \"px-2 py-1.5 text-sm\", icon: \"[&_svg]:size-3.5\" },\n  md: { trigger: \"min-h-10 px-3 text-sm gap-2\", chip: \"h-6 text-xs\", opt: \"px-2 py-2 text-sm\", icon: \"[&_svg]:size-4\" },\n  lg: { trigger: \"min-h-12 px-4 text-base gap-2.5\", chip: \"h-7 text-sm\", opt: \"px-2.5 py-2.5 text-base\", icon: \"[&_svg]:size-[18px]\" },\n} satisfies Record<SelectSize, Record<string, string>>\nconst RADIUS: Record<SelectVariant, string> = { outline: \"rounded-lg\", filled: \"rounded-lg\", ghost: \"rounded-lg\", underline: \"rounded-none\", pill: \"rounded-full\", neo: \"rounded-md\" }\nconst MENU_RADIUS: Record<SelectVariant, string> = { outline: \"rounded-xl\", filled: \"rounded-xl\", ghost: \"rounded-xl\", underline: \"rounded-lg\", pill: \"rounded-2xl\", neo: \"rounded-md\" }\n\nconst fold = (s: string) => s.normalize(\"NFD\").replace(/[̀-ͯ]/g, \"\").toLowerCase()\n\nfunction normalize(options: SelectBase[\"options\"]): SelectOption[] {\n  if (!options) return []\n  const list = typeof options === \"string\" ? options.split(\",\").map((s) => s.trim()).filter(Boolean) : options\n  return list.map((o) => (typeof o === \"string\" ? { value: o, label: o } : o))\n}\n\nfunction Avatar({ src, label }: { src: string | true; label: string }) {\n  if (src !== true) return <img src={src} alt=\"\" className=\"size-6 shrink-0 rounded-full object-cover\" />\n  const initials = label\n    .split(/\\s+/)\n    .slice(0, 2)\n    .map((w) => w[0])\n    .join(\"\")\n    .toUpperCase()\n  let h = 0\n  for (const ch of label) h = (h * 31 + ch.charCodeAt(0)) % 360\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"grid size-6 shrink-0 place-items-center rounded-full text-[10px] font-semibold text-white\"\n      style={{ background: `oklch(0.5 0.13 ${h})` }}\n    >\n      {initials}\n    </span>\n  )\n}\n\nfunction Highlight({ text, query }: { text: string; query: string }) {\n  if (!query) return <>{text}</>\n  const i = fold(text).indexOf(fold(query))\n  if (i < 0) return <>{text}</>\n  return (\n    <>\n      {text.slice(0, i)}\n      <mark className=\"pc-select-hl\">{text.slice(i, i + query.length)}</mark>\n      {text.slice(i + query.length)}\n    </>\n  )\n}\n\nconst Check = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"M3.5 8.5 6.5 11.5 12.5 4.5\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n)\nconst Cross = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n  </svg>\n)\n\nexport function Select(props: SelectProps) {\n  const {\n    options: rawOptions,\n    placeholder = \"Select…\",\n    variant = \"outline\",\n    tone = \"primary\",\n    size = \"md\",\n    shadow = \"none\",\n    animation = \"fade-scale\",\n    searchable,\n    searchPlaceholder = \"Search…\",\n    clearable,\n    disabled,\n    invalid,\n    icon,\n    name,\n    emptyText = \"No results\",\n    maxChips = 3,\n    open: openProp,\n    defaultOpen = false,\n    onOpenChange,\n    menuClassName,\n    className,\n    multiple,\n    value: valueProp,\n    defaultValue,\n    onValueChange,\n    \"aria-label\": ariaLabel,\n    labels,\n    id: idProp,\n    ...rest\n  } = props\n  const l = useLabels(\"select\", DEFAULT_LABELS, labels)\n  const prefersReduced = useReducedMotion()\n  // Gate reduced motion behind mount so a defaultOpen menu renders the same on server and first client pass.\n  const [mounted, setMounted] = React.useState(false)\n  React.useEffect(() => setMounted(true), [])\n  const reduce = mounted && !!prefersReduced\n  const id = React.useId()\n  const triggerId = idProp ?? id + \"-trigger\"\n  const listId = id + \"-list\"\n  const optId = (i: number) => `${id}-opt-${i}`\n\n  const options = React.useMemo(() => normalize(rawOptions), [rawOptions])\n  const [inner, setInner] = React.useState<string | string[] | null | undefined>(defaultValue)\n  const current = valueProp !== undefined ? valueProp : inner\n  const selected: string[] = Array.isArray(current) ? current : current ? [current] : []\n  const commit = (next: string[]) => {\n    const v = multiple ? next : (next[0] ?? null)\n    if (valueProp === undefined) setInner(v)\n    ;(onValueChange as ((v: string | string[] | null) => void) | undefined)?.(v)\n  }\n\n  const [openInner, setOpenInner] = React.useState(defaultOpen)\n  const open = openProp ?? openInner\n  const setOpen = (o: boolean) => {\n    if (openProp === undefined) setOpenInner(o)\n    onOpenChange?.(o)\n  }\n\n  const [query, setQuery] = React.useState(\"\")\n  const [active, setActive] = React.useState(-1)\n  const [side, setSide] = React.useState<\"bottom\" | \"top\">(\"bottom\")\n  const [rtl, setRtl] = React.useState(false)\n  const root = React.useRef<HTMLDivElement>(null)\n  const trigger = React.useRef<HTMLButtonElement>(null)\n  const menu = React.useRef<HTMLDivElement>(null)\n  const search = React.useRef<HTMLInputElement>(null)\n  const typed = React.useRef({ text: \"\", at: 0 })\n\n  const visible = React.useMemo(() => {\n    const q = fold(query.trim())\n    if (!q) return options\n    return options.filter((o) => fold([o.label, o.description ?? \"\", o.group ?? \"\", ...(o.keywords ?? [])].join(\" \")).includes(q))\n  }, [options, query])\n\n  // Groups keep the order in which they first appear.\n  const groups = React.useMemo(() => {\n    const out: { name?: string; items: { o: SelectOption; i: number }[] }[] = []\n    visible.forEach((o, i) => {\n      const g = out.find((x) => x.name === o.group)\n      if (g) g.items.push({ o, i })\n      else out.push({ name: o.group, items: [{ o, i }] })\n    })\n    return out\n  }, [visible])\n\n  const enabledIdx = (from: number, dir: 1 | -1) => {\n    const n = visible.length\n    for (let k = 1; k <= n; k++) {\n      const i = (((from + dir * k) % n) + n) % n\n      if (!visible[i]!.disabled) return i\n    }\n    return -1\n  }\n\n  const openMenu = () => {\n    if (disabled) return\n    const sel = visible.findIndex((o) => selected.includes(o.value) && !o.disabled)\n    setActive(sel >= 0 ? sel : enabledIdx(-1, 1))\n    setOpen(true)\n  }\n  const closeMenu = (focusTrigger = true) => {\n    setOpen(false)\n    setQuery(\"\")\n    if (focusTrigger) trigger.current?.focus()\n  }\n\n  const pick = (o: SelectOption) => {\n    if (o.disabled) return\n    if (multiple) commit(selected.includes(o.value) ? selected.filter((v) => v !== o.value) : [...selected, o.value])\n    else {\n      commit([o.value])\n      closeMenu()\n    }\n  }\n\n  // Flip up when the menu would overflow the viewport and there is more room above.\n  React.useLayoutEffect(() => {\n    if (!open || !root.current) return\n    const r = root.current.getBoundingClientRect()\n    const h = menu.current?.offsetHeight ?? 280\n    const below = window.innerHeight - r.bottom\n    setSide(below < h + 12 && r.top > below ? \"top\" : \"bottom\")\n    setRtl(getComputedStyle(root.current).direction === \"rtl\")\n  }, [open, visible.length])\n\n  React.useEffect(() => {\n    if (!open) return\n    if (searchable) search.current?.focus()\n    const onDown = (e: PointerEvent) => {\n      if (root.current && !root.current.contains(e.target as Node)) closeMenu(false)\n    }\n    document.addEventListener(\"pointerdown\", onDown)\n    return () => document.removeEventListener(\"pointerdown\", onDown)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [open, searchable])\n\n  React.useEffect(() => {\n    if (!open || active < 0) return\n    menu.current?.querySelector<HTMLElement>(`[id=\"${optId(active)}\"]`)?.scrollIntoView({ block: \"nearest\" })\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [active, open])\n\n  // Keep the active row valid as the search narrows the list.\n  React.useEffect(() => {\n    if (open) setActive(visible[0] ? (visible[0].disabled ? enabledIdx(0, 1) : 0) : -1)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [query])\n\n  const typeAhead = (key: string) => {\n    const now = Date.now()\n    const t = typed.current\n    t.text = now - t.at > 600 ? key : t.text + key\n    t.at = now\n    const q = fold(t.text)\n    const start = t.text.length === 1 ? active + 1 : active\n    for (let k = 0; k < visible.length; k++) {\n      const i = (start + k) % visible.length\n      const o = visible[i]!\n      if (!o.disabled && fold(o.label).startsWith(q)) {\n        if (!open) openMenu()\n        setActive(i)\n        return true\n      }\n    }\n    return false\n  }\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    if (disabled || (e.target as HTMLElement).closest(\"[data-clear],[data-chip-x]\")) return\n    const inSearch = e.target === search.current\n    if (!open) {\n      if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n        e.preventDefault()\n        openMenu()\n      } else if (e.key === \"Backspace\" && multiple && selected.length) {\n        e.preventDefault()\n        commit(selected.slice(0, -1))\n      } else if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {\n        if (searchable) {\n          openMenu()\n          setQuery(e.key)\n          e.preventDefault()\n        } else typeAhead(e.key)\n      }\n      return\n    }\n    switch (e.key) {\n      case \"ArrowDown\":\n        e.preventDefault()\n        setActive((a) => enabledIdx(a, 1))\n        break\n      case \"ArrowUp\":\n        e.preventDefault()\n        setActive((a) => enabledIdx(a < 0 ? 0 : a, -1))\n        break\n      case \"Home\":\n        if (inSearch) break\n        e.preventDefault()\n        setActive(enabledIdx(-1, 1))\n        break\n      case \"End\":\n        if (inSearch) break\n        e.preventDefault()\n        setActive(enabledIdx(visible.length, -1))\n        break\n      case \"Enter\":\n        e.preventDefault()\n        if (visible[active]) pick(visible[active])\n        break\n      case \" \":\n        if (inSearch) break\n        e.preventDefault()\n        if (visible[active]) pick(visible[active])\n        break\n      case \"Escape\":\n        e.preventDefault()\n        e.stopPropagation()\n        closeMenu()\n        break\n      case \"Tab\":\n        closeMenu(false)\n        break\n      default:\n        if (!inSearch && e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) typeAhead(e.key)\n    }\n  }\n\n  const byValue = (v: string) => options.find((o) => o.value === v)\n  const chosen = selected.map(byValue).filter((o): o is SelectOption => !!o)\n  const s = SIZES[size]\n  const pop = side === \"bottom\" ? -1 : 1\n  const t: Transition = reduce || animation === \"none\" ? { duration: 0 } : spring.snap\n  const menuMotion =\n    animation === \"fade-scale\"\n      ? { initial: { opacity: 0, scale: 0.96, y: pop * 4 }, animate: { opacity: 1, scale: 1, y: 0 }, exit: { opacity: 0, scale: 0.97, y: pop * 2 } }\n      : animation === \"slide\"\n        ? { initial: { opacity: 0, y: pop * 10, clipPath: side === \"bottom\" ? \"inset(0 0 100% 0)\" : \"inset(100% 0 0 0)\" }, animate: { opacity: 1, y: 0, clipPath: \"inset(0 0 0% 0)\" }, exit: { opacity: 0, y: pop * 6 } }\n        : animation === \"stagger\"\n          ? { initial: { opacity: 0, y: pop * 4 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0 } }\n          : { initial: { opacity: 1 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n  const reduced = reduce ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } } : menuMotion\n  const exitT: Transition = reduce || animation === \"none\" ? { duration: 0 } : { duration: 0.1, ease: easing.out }\n  // Opened from the keyboard: no entrance at all. Frequent actions stay quiet.\n  const byKey = React.useRef(false)\n  const wasOpen = React.useRef(false)\n  if (open && !wasOpen.current) byKey.current = typeof document !== \"undefined\" && !!document.activeElement?.matches(\":focus-visible\")\n  wasOpen.current = open\n  const menuT: Transition = reduce || animation === \"none\" || byKey.current ? { duration: 0 } : { duration: 0.15, ease: easing.out }\n\n  const glide = React.useRef<HTMLDivElement>(null)\n  React.useLayoutEffect(() => {\n    const g = glide.current\n    if (!g) return\n    const t = active >= 0 ? document.getElementById(optId(active)) : null\n    if (!t) {\n      delete g.dataset.on\n      return\n    }\n    // From hidden it appears in place; only a move between options slides.\n    if (!g.dataset.on) g.style.transition = \"none\"\n    g.style.setProperty(\"--pc-gl-y\", `${t.offsetTop}px`)\n    g.style.setProperty(\"--pc-gl-h\", `${t.offsetHeight}px`)\n    g.dataset.on = \"\"\n    void g.offsetHeight\n    g.style.transition = \"\"\n  })\n\n  const shown = multiple ? chosen.slice(0, maxChips) : []\n  const more = multiple ? chosen.length - shown.length : 0\n\n  const trig = (content: React.ReactNode, extra: string) => (\n    <button\n      ref={trigger}\n      id={triggerId}\n      type=\"button\"\n      role=\"combobox\"\n      aria-haspopup=\"listbox\"\n      aria-expanded={open}\n      aria-controls={open ? listId : undefined}\n      aria-activedescendant={open && !searchable && active >= 0 ? optId(active) : undefined}\n      aria-label={ariaLabel}\n      aria-invalid={invalid || undefined}\n      disabled={disabled}\n      className={cn(\"pc-press pc-press-soft flex min-w-0 flex-1 items-center text-start outline-none\", extra)}\n    >\n      {content}\n    </button>\n  )\n\n  return (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-select\" precedence=\"default\">\n        {CSS}\n      </style>\n      <div\n        {...rest}\n        ref={root}\n        data-slot=\"select\"\n        data-variant={variant}\n        data-tone={tone}\n        data-shadow={variant === \"neo\" ? \"none\" : shadow}\n        data-open={open ? \"\" : undefined}\n        data-invalid={invalid ? \"\" : undefined}\n        className={cn(\"pc-select relative w-72 max-w-full\", disabled && \"pointer-events-none opacity-55\", className)}\n        onBlur={(e) => {\n          rest.onBlur?.(e)\n          if (open && !root.current?.contains(e.relatedTarget as Node | null)) closeMenu(false)\n        }}\n        onKeyDown={(e) => {\n          rest.onKeyDown?.(e)\n          if (!e.defaultPrevented) onKeyDown(e)\n        }}\n      >\n        <div\n          className={cn(\"pc-select-trigger flex w-full cursor-pointer items-center py-1\", s.trigger, s.icon, RADIUS[variant])}\n          onClick={(e) => {\n            if ((e.target as HTMLElement).closest(\"[data-clear],[data-chip-x]\")) return\n            if (open) closeMenu()\n            else {\n              openMenu()\n              trigger.current?.focus()\n            }\n          }}\n        >\n          {icon && <span className=\"pc-select-muted inline-flex shrink-0\">{icon}</span>}\n          {/* Chips sit beside the combobox (not inside it) so their remove buttons are real, tabbable buttons. The\n              combobox keeps the same slot either way, so picking the first value never remounts it (focus stays). */}\n          <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-1\">\n            {multiple && (\n              <AnimatePresence initial={false} mode=\"popLayout\">\n                {shown.map((o) => (\n                  <motion.span\n                    key={o.value}\n                    layout={!reduce && animation !== \"none\"}\n                    initial={reduce || animation === \"none\" ? false : { opacity: 0, scale: 0.8 }}\n                    animate={{ opacity: 1, scale: 1 }}\n                    exit={{ opacity: 0, scale: 0.8 }}\n                    transition={t}\n                    className={cn(\"pc-select-chip inline-flex max-w-full items-center gap-1 rounded-md ps-1.5 pe-0.5 font-medium\", s.chip, variant === \"pill\" && \"rounded-full ps-2\")}\n                  >\n                    {o.avatar ? <span className=\"-ms-0.5 scale-75\">{<Avatar src={o.avatar} label={o.label} />}</span> : null}\n                    <span className=\"truncate\">{o.label}</span>\n                    <button\n                      type=\"button\"\n                      data-chip-x=\"\"\n                      aria-label={l.remove(o.label)}\n                      disabled={disabled}\n                      onClick={() => {\n                        commit(selected.filter((v) => v !== o.value))\n                        trigger.current?.focus()\n                      }}\n                      className=\"pc-press grid size-4 shrink-0 cursor-pointer place-items-center rounded-sm opacity-70 outline-none hover:bg-foreground/10 hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/60\"\n                    >\n                      <Cross className=\"!size-3\" />\n                    </button>\n                  </motion.span>\n                ))}\n              </AnimatePresence>\n            )}\n            {multiple && more > 0 && <span className={cn(\"pc-select-chip inline-flex items-center rounded-md px-1.5 font-medium\", s.chip)}>+{more}</span>}\n            {trig(\n              multiple && chosen.length > 0 ? (\n                <span className=\"sr-only\">{l.selectedHint(chosen.map((o) => o.label).join(\", \"))}</span>\n              ) : chosen[0] && !multiple ? (\n                <span className=\"flex min-w-0 items-center gap-2\">\n                  {chosen[0].avatar ? (\n                    <Avatar src={chosen[0].avatar} label={chosen[0].label} />\n                  ) : chosen[0].icon ? (\n                    <span className=\"pc-select-muted inline-flex shrink-0\">{chosen[0].icon}</span>\n                  ) : null}\n                  <span className=\"truncate\">{chosen[0].label}</span>\n                </span>\n              ) : (\n                <span className=\"pc-select-muted truncate\">{placeholder}</span>\n              ),\n              multiple && chosen.length > 0 ? \"min-w-6 self-stretch\" : \"gap-1\",\n            )}\n          </div>\n          {clearable && chosen.length > 0 && !disabled && (\n            <button\n              type=\"button\"\n              data-clear=\"\"\n              aria-label={l.clear}\n              onClick={() => {\n                commit([])\n                trigger.current?.focus()\n              }}\n              className=\"pc-press pc-select-muted grid size-5 shrink-0 place-items-center rounded-md outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\"\n            >\n              <Cross className=\"!size-3.5\" />\n            </button>\n          )}\n          <svg className=\"pc-select-chev !size-4 shrink-0\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n            <path d=\"m4 6 4 4 4-4\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n        </div>\n\n        {name &&\n          (multiple ? selected.map((v) => <input key={v} type=\"hidden\" name={name} value={v} />) : <input type=\"hidden\" name={name} value={selected[0] ?? \"\"} />)}\n\n        <AnimatePresence>\n          {open && (\n            <motion.div\n              ref={menu}\n              key=\"menu\"\n              {...reduced}\n              transition={menuT}\n              exit={{ ...reduced.exit, transition: exitT }}\n              style={{ transformOrigin: side === \"bottom\" ? \"top center\" : \"bottom center\" }}\n              className={cn(\n                \"pc-select-menu absolute inset-x-0 z-50 min-w-48 overflow-hidden p-1\",\n                side === \"bottom\" ? \"top-full mt-1.5\" : \"bottom-full mb-1.5\",\n                MENU_RADIUS[variant],\n                menuClassName,\n              )}\n            >\n              {searchable && (\n                <div className=\"flex items-center gap-2 border-b px-2 pb-1.5 [&_svg]:size-4\">\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" className=\"pc-select-muted shrink-0\">\n                    <circle cx=\"7\" cy=\"7\" r=\"4.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n                    <path d=\"m10.5 10.5 3 3\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n                  </svg>\n                  <input\n                    ref={search}\n                    value={query}\n                    onChange={(e) => setQuery(e.target.value)}\n                    placeholder={searchPlaceholder}\n                    aria-label={searchPlaceholder}\n                    aria-controls={listId}\n                    aria-activedescendant={active >= 0 ? optId(active) : undefined}\n                    aria-autocomplete=\"list\"\n                    role=\"combobox\"\n                    aria-expanded=\"true\"\n                    className=\"h-8 min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground\"\n                  />\n                </div>\n              )}\n              <div\n                id={listId}\n                role=\"listbox\"\n                aria-multiselectable={multiple || undefined}\n                aria-label={ariaLabel}\n                aria-labelledby={ariaLabel ? undefined : triggerId}\n                className={cn(\"pc-select-list max-h-72 overflow-y-auto overscroll-contain\", searchable && \"pt-1\")}>\n                <div ref={glide} aria-hidden=\"true\" className={cn(\"pc-select-glide rounded-md\", variant === \"pill\" && \"rounded-xl\")} />\n                {visible.length === 0 && <div className=\"px-3 py-6 text-center text-sm text-muted-foreground\">{emptyText}</div>}\n                {groups.map((g, gi) => (\n                  <div key={g.name ?? \"_\" + gi} role=\"group\" aria-label={g.name}>\n                    {g.name && (\n                      <div className={cn(\"pc-select-muted px-2 pt-2 pb-1 text-[11px] font-medium tracking-wide uppercase\", gi > 0 && \"mt-1 border-t pt-2.5\")}>{g.name}</div>\n                    )}\n                    {g.items.map(({ o, i }) => {\n                      const isSel = selected.includes(o.value)\n                      return (\n                        <motion.div\n                          key={o.value}\n                          id={optId(i)}\n                          role=\"option\"\n                          aria-selected={isSel}\n                          aria-disabled={o.disabled || undefined}\n                          data-active={i === active ? \"\" : undefined}\n                          data-selected={isSel ? \"\" : undefined}\n                          initial={animation === \"stagger\" && !reduce ? { opacity: 0, x: rtl ? 6 : -6 } : false}\n                          animate={{ opacity: 1, x: 0 }}\n                          transition={animation === \"stagger\" && !reduce ? { delay: Math.min(i, 10) * 0.028, duration: 0.22, ease: easing.out } : { duration: 0 }}\n                          onPointerMove={() => !o.disabled && active !== i && setActive(i)}\n                          onPointerDown={(e) => e.preventDefault()}\n                          onClick={() => pick(o)}\n                          className={cn(\"pc-select-opt flex cursor-pointer items-center gap-2.5 rounded-md select-none\", s.opt, variant === \"pill\" && \"rounded-xl\")}\n                        >\n                          {multiple && (\n                            <span className=\"pc-select-box grid size-4 shrink-0 place-items-center rounded-[5px]\">{isSel && <Check className=\"size-3\" />}</span>\n                          )}\n                          {o.avatar ? (\n                            <Avatar src={o.avatar} label={o.label} />\n                          ) : o.icon ? (\n                            <span className=\"pc-select-muted inline-flex shrink-0 [&_svg]:size-4\">{o.icon}</span>\n                          ) : null}\n                          <span className=\"flex min-w-0 flex-1 flex-col\">\n                            <span className=\"truncate\">\n                              <Highlight text={o.label} query={query.trim()} />\n                            </span>\n                            {o.description && <span className=\"pc-select-muted truncate text-xs\">{o.description}</span>}\n                          </span>\n                          {!multiple && isSel && <Check className=\"pc-select-check size-4 shrink-0\" />}\n                        </motion.div>\n                      )\n                    })}\n                  </div>\n                ))}\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/select.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}