{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "listbox",
  "title": "Listbox",
  "description": "An always-open list for picking one or several options: a search box that filters as you type, sticky group headings, avatars and descriptions, a highlight that follows the pointer or keyboard, checks that draw in, and type-ahead to jump by name.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/listbox/listbox.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } 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 ListboxOption {\n  value: string;\n  label: string;\n  description?: string;\n  group?: string;\n  /** Initials or a short tag shown in a round avatar. */\n  avatar?: string;\n  disabled?: boolean;\n}\n\nexport interface ListboxProps {\n  options?: ListboxOption[];\n  multiple?: boolean;\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n  filter?: boolean;\n  filterPlaceholder?: string;\n  label?: string;\n  /** Height of the scrolling list. */\n  height?: number;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.3)\", panel: \"#0E0E0E\", border: \"rgba(255,255,255,0.1)\", line: \"rgba(255,255,255,0.06)\", active: \"rgba(255,255,255,0.06)\", sel: \"rgba(255,255,255,0.1)\", box: \"rgba(255,255,255,0.24)\", fill: \"#F5F4F1\", onFill: \"#0A0A0A\", avatar: \"rgba(255,255,255,0.1)\", input: \"rgba(255,255,255,0.04)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.3)\", panel: \"#FFFFFF\", border: \"rgba(10,10,10,0.12)\", line: \"rgba(10,10,10,0.06)\", active: \"rgba(10,10,10,0.04)\", sel: \"rgba(10,10,10,0.07)\", box: \"rgba(10,10,10,0.25)\", fill: \"#0A0A0A\", onFill: \"#FFFFFF\", avatar: \"rgba(10,10,10,0.07)\", input: \"rgba(10,10,10,0.03)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst DEFAULT_OPTIONS: ListboxOption[] = [\n  { value: \"maya\", label: \"Maya Chen\", description: \"Head of Design\", group: \"Design\", avatar: \"MC\" },\n  { value: \"tom\", label: \"Tom Silva\", description: \"Product designer\", group: \"Design\", avatar: \"TS\" },\n  { value: \"lena\", label: \"Lena Moreau\", description: \"Brand designer\", group: \"Design\", avatar: \"LM\" },\n  { value: \"leo\", label: \"Leo Fischer\", description: \"VP Engineering\", group: \"Engineering\", avatar: \"LF\" },\n  { value: \"amara\", label: \"Amara Okafor\", description: \"Platform lead\", group: \"Engineering\", avatar: \"AO\" },\n  { value: \"jun\", label: \"Jun Park\", description: \"Engineer · on leave\", group: \"Engineering\", avatar: \"JP\", disabled: true },\n  { value: \"sofia\", label: \"Sofia Rossi\", description: \"Engineer\", group: \"Engineering\", avatar: \"SR\" },\n  { value: \"omar\", label: \"Omar Haddad\", description: \"VP Sales\", group: \"Sales\", avatar: \"OH\" },\n];\n\nexport function Listbox({ options = DEFAULT_OPTIONS, multiple = true, value, defaultValue = [\"maya\", \"leo\"], onValueChange, filter = true, filterPlaceholder = \"Search people\", label = \"Assign to\", height = 300, theme = \"dark\", className }: ListboxProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState<string[]>(defaultValue);\n  const sel = value ?? internal;\n  const [query, setQuery] = React.useState(\"\");\n  const [active, setActive] = React.useState<string | null>(null);\n  const listRef = React.useRef<HTMLDivElement>(null);\n  const typed = React.useRef({ text: \"\", at: 0 });\n\n  const q = query.trim().toLowerCase();\n  const shown = options.filter((o) => !q || o.label.toLowerCase().includes(q) || (o.description ?? \"\").toLowerCase().includes(q));\n  const enabled = shown.filter((o) => !o.disabled);\n  const groups = Array.from(new Set(shown.map((o) => o.group ?? \"\")));\n\n  const commit = (next: string[]) => {\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n  const toggle = (o: ListboxOption) => {\n    if (o.disabled) return;\n    setActive(o.value);\n    if (multiple) commit(sel.includes(o.value) ? sel.filter((v) => v !== o.value) : [...sel, o.value]);\n    else commit([o.value]);\n  };\n\n  // Keep the active option in view.\n  React.useEffect(() => {\n    if (!active) return;\n    listRef.current?.querySelector(`[data-value=\"${active}\"]`)?.scrollIntoView({ block: \"nearest\" });\n  }, [active]);\n\n  const onKey = (e: React.KeyboardEvent) => {\n    const i = enabled.findIndex((o) => o.value === active);\n    const go = (n: number) => {\n      e.preventDefault();\n      const o = enabled[Math.max(0, Math.min(enabled.length - 1, n))];\n      if (o) setActive(o.value);\n    };\n    if (e.key === \"ArrowDown\") go(i + 1);\n    else if (e.key === \"ArrowUp\") go(i < 0 ? enabled.length - 1 : i - 1);\n    else if (e.key === \"Home\") go(0);\n    else if (e.key === \"End\") go(enabled.length - 1);\n    else if ((e.key === \" \" || e.key === \"Enter\") && active) {\n      e.preventDefault();\n      const o = enabled.find((x) => x.value === active);\n      if (o) toggle(o);\n    } else if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && e.currentTarget === listRef.current) {\n      // Type-ahead: jump to the next option starting with what's been typed.\n      const now = e.timeStamp;\n      typed.current = { text: (now - typed.current.at < 600 ? typed.current.text : \"\") + e.key.toLowerCase(), at: now };\n      const hit = enabled.find((o) => o.label.toLowerCase().startsWith(typed.current.text));\n      if (hit) setActive(hit.value);\n    }\n  };\n\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 500, damping: 36 };\n\n  return (\n    <div className={cn(\"flex w-full flex-col overflow-hidden\", className)} style={{ borderRadius: 16, background: p.panel, border: `1px solid ${p.border}`, fontFamily: \"Inter, sans-serif\", color: p.text }}>\n      <div className=\"flex items-center justify-between\" style={{ padding: \"12px 14px 8px\" }}>\n        <span id={`${uid}-label`} className=\"text-[13.5px] font-semibold\">\n          {label}\n        </span>\n        <span className=\"text-[12px] tabular-nums\" style={{ color: p.muted }} aria-live=\"polite\">\n          {multiple ? `${sel.length} selected` : \"\"}\n        </span>\n      </div>\n      {filter && (\n        <div style={{ padding: \"0 10px 8px\" }}>\n          <label className=\"relative flex items-center\">\n            <svg className=\"pointer-events-none absolute left-2.5\" width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.muted} strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <circle cx=\"11\" cy=\"11\" r=\"7\" />\n              <path d=\"m20 20-3.5-3.5\" />\n            </svg>\n            <input\n              type=\"search\"\n              value={query}\n              onChange={(e) => setQuery(e.target.value)}\n              onKeyDown={onKey}\n              placeholder={filterPlaceholder}\n              aria-label={filterPlaceholder}\n              aria-controls={`${uid}-list`}\n              aria-activedescendant={active ? `${uid}-${active}` : undefined}\n              className=\"h-9 w-full rounded-lg text-[13px] outline-none\"\n              style={{ padding: \"0 10px 0 30px\", background: p.input, border: `1px solid ${p.line}`, color: p.text }}\n            />\n          </label>\n        </div>\n      )}\n      <div\n        ref={listRef}\n        id={`${uid}-list`}\n        role=\"listbox\"\n        tabIndex={0}\n        aria-labelledby={`${uid}-label`}\n        aria-multiselectable={multiple || undefined}\n        aria-activedescendant={active ? `${uid}-${active}` : undefined}\n        onKeyDown={onKey}\n        onFocus={() => !active && enabled[0] && setActive(enabled[0].value)}\n        onMouseLeave={(e) => document.activeElement !== e.currentTarget && setActive(null)}\n        className=\"overflow-y-auto outline-none focus-visible:ring-2 focus-visible:ring-inset\"\n        style={{ height, padding: \"2px 6px 8px\", scrollbarWidth: \"thin\", [\"--tw-ring-color\" as string]: p.focus }}\n      >\n        {groups.map((g) => (\n          <div key={g || \"all\"} role=\"group\" aria-label={g || undefined}>\n            {g && (\n              <div className=\"sticky top-0 z-10 text-[11px] font-semibold tracking-wider uppercase\" style={{ padding: \"10px 10px 6px\", color: p.faint, background: p.panel }}>\n                {g}\n              </div>\n            )}\n            <AnimatePresence initial={false}>\n              {shown\n                .filter((o) => (o.group ?? \"\") === g)\n                .map((o) => {\n                  const on = sel.includes(o.value);\n                  const isActive = active === o.value;\n                  return (\n                    <motion.div\n                      key={o.value}\n                      id={`${uid}-${o.value}`}\n                      data-value={o.value}\n                      role=\"option\"\n                      aria-selected={on}\n                      aria-disabled={o.disabled || undefined}\n                      onClick={() => toggle(o)}\n                      onMouseMove={() => !o.disabled && setActive(o.value)}\n                      className=\"relative flex cursor-pointer items-center rounded-xl\"\n                      style={{ gap: 11, padding: \"8px 10px\", opacity: o.disabled ? 0.4 : 1, cursor: o.disabled ? \"not-allowed\" : \"pointer\" }}\n                      initial={{ opacity: 0, height: 0 }}\n                      animate={{ opacity: o.disabled ? 0.4 : 1, height: \"auto\" }}\n                      exit={{ opacity: 0, height: 0 }}\n                      transition={{ duration: reduce ? 0 : 0.18 }}\n                    >\n                      {isActive && <motion.span layoutId={`${uid}-active`} className=\"absolute inset-0 rounded-xl\" style={{ background: p.active }} transition={spring} />}\n                      {on && !multiple && <motion.span layoutId={`${uid}-sel`} className=\"absolute inset-0 rounded-xl\" style={{ background: p.sel }} transition={spring} />}\n                      {o.avatar && (\n                        <span className=\"relative flex shrink-0 items-center justify-center rounded-full text-[11px] font-semibold\" style={{ width: 30, height: 30, background: on ? p.fill : p.avatar, color: on ? p.onFill : p.text, transition: \"background 0.2s ease, color 0.2s ease\" }}>\n                          {o.avatar}\n                        </span>\n                      )}\n                      <span className=\"relative flex min-w-0 flex-1 flex-col\">\n                        <span className=\"truncate text-[13.5px] font-medium\">{o.label}</span>\n                        {o.description && (\n                          <span className=\"truncate text-[12px]\" style={{ color: p.muted }}>\n                            {o.description}\n                          </span>\n                        )}\n                      </span>\n                      <span aria-hidden=\"true\" className=\"relative flex shrink-0 items-center justify-center\" style={{ width: 18, height: 18, borderRadius: multiple ? 5 : 999, border: `1.5px solid ${on ? p.fill : multiple ? p.box : \"transparent\"}`, background: on ? p.fill : \"transparent\", transition: \"background 0.15s ease, border-color 0.15s ease\" }}>\n                        <svg width=\"10\" height=\"10\" viewBox=\"0 0 12 12\" fill=\"none\">\n                          <motion.path d=\"M2.4 6.3 4.9 8.7 9.6 3.4\" stroke={p.onFill} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={false} animate={{ pathLength: on ? 1 : 0, opacity: on ? 1 : 0 }} transition={{ duration: reduce ? 0 : 0.2 }} />\n                        </svg>\n                      </span>\n                    </motion.div>\n                  );\n                })}\n            </AnimatePresence>\n          </div>\n        ))}\n        {shown.length === 0 && (\n          <div className=\"flex h-full items-center justify-center text-[13px]\" style={{ color: p.faint }}>\n            No one matches “{query}”\n          </div>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default Listbox;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}