{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox",
  "title": "Combobox",
  "description": "A searchable select where you type to filter options, with match highlighting, option descriptions, disabled options, a clear button, an empty state and full keyboard navigation.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/combobox/combobox.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface ComboboxOption {\n  value: string;\n  label: string;\n  description?: string;\n  disabled?: boolean;\n}\n\nexport type ComboboxSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface ComboboxProps {\n  options?: ComboboxOption[];\n  value?: string | null;\n  defaultValue?: string | null;\n  onValueChange?: (value: string | null) => void;\n  placeholder?: string;\n  label?: string;\n  helperText?: string;\n  emptyText?: string;\n  clearable?: boolean;\n  size?: ComboboxSize;\n  theme?: \"dark\" | \"light\";\n  width?: number | string;\n  maxMenuHeight?: number;\n  disabled?: boolean;\n  className?: string;\n}\n\nconst DEFAULT_OPTIONS: ComboboxOption[] = [\n  { value: \"react\", label: \"React\", description: \"A library for building user interfaces\" },\n  { value: \"vue\", label: \"Vue\", description: \"The progressive JavaScript framework\" },\n  { value: \"svelte\", label: \"Svelte\", description: \"Cybernetically enhanced web apps\" },\n  { value: \"solid\", label: \"SolidJS\", description: \"Simple and performant reactivity\" },\n  { value: \"angular\", label: \"Angular\", description: \"Platform for building web apps\" },\n  { value: \"astro\", label: \"Astro\", description: \"Content-driven websites, fast by default\" },\n  { value: \"next\", label: \"Next.js\", description: \"The React framework for production\" },\n  { value: \"remix\", label: \"Remix\", description: \"Full stack web framework\", disabled: true },\n];\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", bg: \"rgba(255,255,255,0.03)\", border: \"rgba(255,255,255,0.12)\", borderHover: \"rgba(255,255,255,0.24)\", focus: \"rgba(245,244,241,0.85)\", menuBg: \"#0E0E0E\", menuBorder: \"rgba(255,255,255,0.08)\", highlight: \"rgba(255,255,255,0.07)\", clearBg: \"rgba(255,255,255,0.08)\", shadow: \"0 24px 60px rgba(0,0,0,0.55)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.16)\", borderHover: \"rgba(10,10,10,0.3)\", focus: \"rgba(10,10,10,0.85)\", menuBg: \"#FFFFFF\", menuBorder: \"rgba(10,10,10,0.12)\", highlight: \"rgba(10,10,10,0.05)\", clearBg: \"rgba(10,10,10,0.06)\", shadow: \"0 20px 50px rgba(0,0,0,0.16)\" },\n};\n\nconst SIZES: Record<ComboboxSize, { font: number; height: number; padX: number; radius: number }> = {\n  sm: { font: 13, height: 36, padX: 12, radius: 11 },\n  md: { font: 14.5, height: 44, padX: 14, radius: 13 },\n  lg: { font: 16, height: 52, padX: 16, radius: 15 },\n};\n\nfunction highlightMatch(text: string, query: string) {\n  const q = query.trim();\n  if (!q) return text;\n  const i = text.toLowerCase().indexOf(q.toLowerCase());\n  if (i < 0) return text;\n  return (\n    <>\n      {text.slice(0, i)}\n      <span style={{ fontWeight: 700, textDecoration: \"underline\", textUnderlineOffset: 3, textDecorationThickness: 1.5 }}>{text.slice(i, i + q.length)}</span>\n      {text.slice(i + q.length)}\n    </>\n  );\n}\n\nexport function Combobox({\n  options = DEFAULT_OPTIONS,\n  value,\n  defaultValue = null,\n  onValueChange,\n  placeholder = \"Select a framework...\",\n  label,\n  helperText,\n  emptyText = \"No results found\",\n  clearable = true,\n  size = \"md\",\n  theme = \"dark\",\n  width = 340,\n  maxMenuHeight = 300,\n  disabled = false,\n  className,\n}: ComboboxProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const listRef = React.useRef<HTMLUListElement>(null);\n  const [internal, setInternal] = React.useState<string | null>(defaultValue);\n  const [query, setQuery] = React.useState<string | null>(null);\n  const [open, setOpen] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const [activeIndex, setActiveIndex] = React.useState(-1);\n  const isControlled = value !== undefined;\n  const current = isControlled ? value : internal;\n  const selected = options.find((o) => o.value === current) ?? null;\n\n  const filtered = React.useMemo(() => {\n    const q = (query ?? \"\").trim().toLowerCase();\n    if (!q) return options;\n    return options.filter((o) => o.label.toLowerCase().includes(q));\n  }, [options, query]);\n\n  const commit = (next: string | null) => {\n    if (!isControlled) setInternal(next);\n    onValueChange?.(next);\n  };\n\n  const close = () => {\n    setOpen(false);\n    setQuery(null);\n    setActiveIndex(-1);\n  };\n\n  const pick = (opt: ComboboxOption) => {\n    if (opt.disabled) return;\n    commit(opt.value);\n    close();\n  };\n\n  const firstEnabled = (list: ComboboxOption[]) => list.findIndex((o) => !o.disabled);\n\n  const openMenu = () => {\n    if (disabled) return;\n    setOpen(true);\n    const idx = filtered.findIndex((o) => o.value === current);\n    setActiveIndex(idx >= 0 ? idx : firstEnabled(filtered));\n  };\n\n  const move = (dir: 1 | -1) => {\n    const enabled = filtered.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0);\n    if (enabled.length === 0) return;\n    const pos = enabled.indexOf(activeIndex);\n    const next = pos === -1 ? (dir === 1 ? 0 : enabled.length - 1) : (pos + dir + enabled.length) % enabled.length;\n    setActiveIndex(enabled[next]);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      if (!open) openMenu();\n      else move(e.key === \"ArrowDown\" ? 1 : -1);\n    } else if (e.key === \"Enter\") {\n      if (open && activeIndex >= 0 && filtered[activeIndex]) {\n        e.preventDefault();\n        pick(filtered[activeIndex]);\n      }\n    } else if (e.key === \"Escape\") {\n      if (open) {\n        e.preventDefault();\n        close();\n      }\n    } else if (e.key === \"Home\" && open) {\n      e.preventDefault();\n      setActiveIndex(firstEnabled(filtered));\n    } else if (e.key === \"End\" && open) {\n      e.preventDefault();\n      const rev = [...filtered].reverse().findIndex((o) => !o.disabled);\n      if (rev >= 0) setActiveIndex(filtered.length - 1 - rev);\n    } else if (e.key === \"Tab\") {\n      close();\n    }\n  };\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onDown = (e: MouseEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) {\n        setOpen(false);\n        setQuery(null);\n        setActiveIndex(-1);\n      }\n    };\n    document.addEventListener(\"mousedown\", onDown);\n    return () => document.removeEventListener(\"mousedown\", onDown);\n  }, [open]);\n\n  React.useEffect(() => {\n    if (!open || activeIndex < 0) return;\n    listRef.current?.children[activeIndex]?.scrollIntoView({ block: \"nearest\" });\n  }, [activeIndex, open]);\n\n  const displayValue = query !== null ? query : (selected?.label ?? \"\");\n  const borderColor = open ? p.focus : hovered ? p.borderHover : p.border;\n  const showClear = clearable && !disabled && (selected !== null || (query ?? \"\") !== \"\");\n\n  return (\n    <div ref={rootRef} className={cn(\"relative inline-flex flex-col gap-2\", className)} style={{ width, maxWidth: \"100%\", fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {label && (\n        <label htmlFor={`${uid}-input`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n          {label}\n        </label>\n      )}\n\n      <div className=\"relative\">\n        <div\n          onMouseEnter={() => setHovered(true)}\n          onMouseLeave={() => setHovered(false)}\n          onClick={() => {\n            inputRef.current?.focus();\n            if (!open) openMenu();\n          }}\n          className=\"flex items-center\"\n          style={{ height: s.height, gap: 8, padding: `0 ${s.padX}px`, borderRadius: s.radius, background: p.bg, border: `1px solid ${borderColor}`, boxShadow: open ? `0 0 0 3px color-mix(in srgb, ${p.focus} 14%, transparent)` : \"0 0 0 0 transparent\", cursor: disabled ? \"default\" : \"text\", transition: \"border-color 0.18s ease, box-shadow 0.18s ease\" }}\n        >\n          <input\n            ref={inputRef}\n            id={`${uid}-input`}\n            type=\"text\"\n            role=\"combobox\"\n            aria-expanded={open}\n            aria-controls={`${uid}-list`}\n            aria-autocomplete=\"list\"\n            aria-activedescendant={open && activeIndex >= 0 ? `${uid}-opt-${activeIndex}` : undefined}\n            autoComplete=\"off\"\n            spellCheck={false}\n            disabled={disabled}\n            value={displayValue}\n            placeholder={placeholder}\n            onChange={(e) => {\n              setQuery(e.target.value);\n              setOpen(true);\n              setActiveIndex(0);\n            }}\n            onFocus={() => !open && openMenu()}\n            onKeyDown={onKeyDown}\n            className=\"min-w-0 flex-1 border-none bg-transparent p-0 outline-none placeholder:text-[color:var(--cb-placeholder)]\"\n            style={{ color: p.text, fontSize: s.font, fontWeight: 500, [\"--cb-placeholder\" as string]: p.muted }}\n          />\n          {showClear && (\n            <button\n              type=\"button\"\n              aria-label=\"Clear selection\"\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={(e) => {\n                e.stopPropagation();\n                commit(null);\n                setQuery(null);\n                inputRef.current?.focus();\n              }}\n              className=\"flex shrink-0 cursor-pointer items-center justify-center rounded-full border-none p-0 outline-none\"\n              style={{ width: 20, height: 20, background: p.clearBg, color: p.muted }}\n            >\n              <svg width=\"9\" height=\"9\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                <path d=\"M3 3L9 9M9 3L3 9\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n              </svg>\n            </button>\n          )}\n          <motion.span aria-hidden=\"true\" className=\"flex shrink-0\" animate={{ rotate: open ? 180 : 0 }} transition={{ type: \"spring\", stiffness: 420, damping: 28 }} style={{ color: open ? p.text : p.muted }}>\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n              <path d=\"M4 6.2L8 10L12 6.2\" />\n            </svg>\n          </motion.span>\n        </div>\n\n        <AnimatePresence>\n          {open && (\n            <motion.ul\n              ref={listRef}\n              id={`${uid}-list`}\n              role=\"listbox\"\n              className=\"absolute left-0 z-50 m-0 w-full list-none overflow-auto p-1.5\"\n              style={{ top: \"calc(100% + 8px)\", maxHeight: maxMenuHeight, borderRadius: s.radius + 2, border: `1px solid ${p.menuBorder}`, background: p.menuBg, boxShadow: p.shadow, transformOrigin: \"top center\" }}\n              initial={{ opacity: 0, y: -6, scale: 0.98 }}\n              animate={{ opacity: 1, y: 0, scale: 1 }}\n              exit={{ opacity: 0, y: -6, scale: 0.98 }}\n              transition={{ duration: 0.16, ease: [0.16, 1, 0.3, 1] }}\n            >\n              {filtered.length === 0 ? (\n                <li role=\"presentation\" className=\"text-center\" style={{ padding: \"18px 12px\", color: p.muted, fontSize: s.font }}>\n                  {emptyText}\n                </li>\n              ) : (\n                filtered.map((opt, i) => {\n                  const isSelected = opt.value === current;\n                  return (\n                    <li\n                      key={opt.value}\n                      id={`${uid}-opt-${i}`}\n                      role=\"option\"\n                      aria-selected={isSelected}\n                      aria-disabled={opt.disabled}\n                      onMouseEnter={() => !opt.disabled && setActiveIndex(i)}\n                      onMouseDown={(e) => e.preventDefault()}\n                      onClick={() => pick(opt)}\n                      className=\"flex items-center justify-between gap-3\"\n                      style={{ padding: `${s.height * 0.2}px ${s.padX - 4}px`, borderRadius: s.radius - 4, background: i === activeIndex ? p.highlight : \"transparent\", opacity: opt.disabled ? 0.4 : 1, cursor: opt.disabled ? \"default\" : \"pointer\", color: p.text, transition: \"background 0.12s ease\" }}\n                    >\n                      <div className=\"flex min-w-0 flex-col\" style={{ gap: 2 }}>\n                        <span className=\"truncate\" style={{ fontSize: s.font, fontWeight: isSelected ? 700 : 500 }}>\n                          {highlightMatch(opt.label, query ?? \"\")}\n                        </span>\n                        {opt.description && (\n                          <span className=\"truncate\" style={{ fontSize: s.font * 0.82, color: p.muted }}>\n                            {opt.description}\n                          </span>\n                        )}\n                      </div>\n                      {isSelected && (\n                        <svg width=\"15\" height=\"15\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"shrink-0\" aria-hidden=\"true\">\n                          <motion.path d=\"M3 8.2L6.4 11.6L13 4.4\" stroke={p.text} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: 0.25, ease: \"easeOut\" }} />\n                        </svg>\n                      )}\n                    </li>\n                  );\n                })\n              )}\n            </motion.ul>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {helperText && <span style={{ color: p.muted, fontSize: s.font - 1.5, lineHeight: 1.4 }}>{helperText}</span>}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}