{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "select",
  "title": "Select",
  "description": "An accessible, animated custom select with a springy chevron, keyboard navigation, type-ahead, option descriptions, disabled options and a focus ring.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/select/select.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 SelectOption {\n  value: string;\n  label: string;\n  description?: string;\n  disabled?: boolean;\n}\n\nexport interface SelectProps {\n  options?: SelectOption[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  placeholder?: string;\n  label?: string;\n  helperText?: string;\n  theme?: \"dark\" | \"light\";\n  disabled?: boolean;\n  size?: number;\n  radius?: number;\n  width?: number;\n  accentColor?: string;\n  maxMenuHeight?: number;\n  className?: string;\n}\n\nconst DEFAULT_OPTIONS: SelectOption[] = [\n  {\n    value: \"design\",\n    label: \"Design\",\n    description: \"Interfaces, systems and motion\",\n  },\n  {\n    value: \"engineering\",\n    label: \"Engineering\",\n    description: \"Frontend, backend and infra\",\n  },\n  {\n    value: \"product\",\n    label: \"Product\",\n    description: \"Strategy, research and roadmaps\",\n  },\n  {\n    value: \"marketing\",\n    label: \"Marketing\",\n    description: \"Growth, content and brand\",\n  },\n  {\n    value: \"support\",\n    label: \"Support\",\n    description: \"Help center and success\",\n    disabled: true,\n  },\n];\n\nconst PALETTES = {\n  dark: {\n    triggerBg: \"rgba(255,255,255,0.03)\",\n    border: \"rgba(255,255,255,0.12)\",\n    borderHover: \"rgba(255,255,255,0.24)\",\n    text: \"#F5F4F1\",\n    muted: \"rgba(245,244,241,0.5)\",\n    menuBg: \"#0E0E0E\",\n    menuBorder: \"rgba(255,255,255,0.08)\",\n    highlight: \"rgba(255,255,255,0.06)\",\n    shadow: \"0 24px 60px rgba(0,0,0,0.55)\",\n  },\n  light: {\n    triggerBg: \"#FFFFFF\",\n    border: \"rgba(10,10,10,0.14)\",\n    borderHover: \"rgba(10,10,10,0.28)\",\n    text: \"#0A0A0A\",\n    muted: \"rgba(10,10,10,0.5)\",\n    menuBg: \"#FFFFFF\",\n    menuBorder: \"rgba(10,10,10,0.08)\",\n    highlight: \"rgba(10,10,10,0.05)\",\n    shadow: \"0 24px 60px rgba(0,0,0,0.18)\",\n  },\n};\n\nfunction ChevronIcon({ size, color }: { size: number; color: string }) {\n  return (\n    <svg\n      width={size}\n      height={size}\n      viewBox=\"0 0 16 16\"\n      fill=\"none\"\n      aria-hidden=\"true\"\n    >\n      <path\n        d=\"M4 6.2L8 10L12 6.2\"\n        stroke={color}\n        strokeWidth=\"1.6\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nfunction CheckIcon({ size, color }: { size: number; color: string }) {\n  return (\n    <svg\n      width={size}\n      height={size}\n      viewBox=\"0 0 16 16\"\n      fill=\"none\"\n      aria-hidden=\"true\"\n    >\n      <motion.path\n        d=\"M3 8.2L6.4 11.6L13 4.4\"\n        stroke={color}\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        initial={{ pathLength: 0 }}\n        animate={{ pathLength: 1 }}\n        transition={{ duration: 0.25, ease: \"easeOut\" }}\n      />\n    </svg>\n  );\n}\n\nexport function Select({\n  options = DEFAULT_OPTIONS,\n  value,\n  defaultValue,\n  onValueChange,\n  placeholder = \"Select a team\",\n  label,\n  helperText,\n  theme = \"dark\",\n  disabled = false,\n  size = 15,\n  radius = 14,\n  width = 320,\n  accentColor = \"#F2A841\",\n  maxMenuHeight = 320,\n  className,\n}: SelectProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const [internalValue, setInternalValue] = React.useState<string | undefined>(\n    defaultValue,\n  );\n  const [open, setOpen] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const [focusVisible, setFocusVisible] = React.useState(false);\n  const [activeIndex, setActiveIndex] = React.useState(-1);\n  const isControlled = value !== undefined;\n  const current = isControlled ? value : internalValue;\n  const selected = options.find((o) => o.value === current);\n  const listId = `${uid}-list`;\n  const height = Math.round(size * 2.9);\n\n  const enabledIndexes = options\n    .map((o, i) => (o.disabled ? -1 : i))\n    .filter((i) => i >= 0);\n\n  const commit = (opt: SelectOption) => {\n    if (opt.disabled) return;\n    if (!isControlled) setInternalValue(opt.value);\n    onValueChange?.(opt.value);\n    setOpen(false);\n  };\n\n  const openMenu = () => {\n    if (disabled) return;\n    const selectedIndex = options.findIndex((o) => o.value === current);\n    setActiveIndex(\n      selectedIndex >= 0 ? selectedIndex : (enabledIndexes[0] ?? -1),\n    );\n    setOpen(true);\n  };\n\n  const move = (dir: 1 | -1) => {\n    if (enabledIndexes.length === 0) return;\n    const pos = enabledIndexes.indexOf(activeIndex);\n    const nextPos =\n      pos === -1\n        ? dir === 1\n          ? 0\n          : enabledIndexes.length - 1\n        : (pos + dir + enabledIndexes.length) % enabledIndexes.length;\n    setActiveIndex(enabledIndexes[nextPos]);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {\n    if (disabled) return;\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 === \"Home\" && open) {\n      e.preventDefault();\n      setActiveIndex(enabledIndexes[0] ?? -1);\n    } else if (e.key === \"End\" && open) {\n      e.preventDefault();\n      setActiveIndex(enabledIndexes[enabledIndexes.length - 1] ?? -1);\n    } else if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      if (!open) openMenu();\n      else if (activeIndex >= 0) commit(options[activeIndex]);\n    } else if (e.key === \"Escape\" && open) {\n      e.preventDefault();\n      setOpen(false);\n    } else if (e.key === \"Tab\") {\n      setOpen(false);\n    } else if (e.key.length === 1 && /\\S/.test(e.key)) {\n      const start = open ? activeIndex + 1 : 0;\n      const ordered = [...options.slice(start), ...options.slice(0, start)];\n      const hit = ordered.find(\n        (o) =>\n          !o.disabled && o.label.toLowerCase().startsWith(e.key.toLowerCase()),\n      );\n      if (hit) {\n        const idx = options.indexOf(hit);\n        if (open) setActiveIndex(idx);\n        else commit(hit);\n      }\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    };\n    document.addEventListener(\"mousedown\", onDown);\n    return () => document.removeEventListener(\"mousedown\", onDown);\n  }, [open]);\n\n  const borderColor = open ? accentColor : hovered ? p.borderHover : p.border;\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative inline-flex flex-col gap-2\", className)}\n      style={{ width, fontFamily: \"Inter, sans-serif\" }}\n    >\n      {label && (\n        <label\n          id={`${uid}-label`}\n          className=\"font-semibold tracking-[-0.01em]\"\n          style={{ color: p.text, fontSize: size * 0.9 }}\n        >\n          {label}\n        </label>\n      )}\n\n      <div className=\"relative\">\n        <button\n          type=\"button\"\n          role=\"combobox\"\n          aria-haspopup=\"listbox\"\n          aria-expanded={open}\n          aria-controls={listId}\n          aria-labelledby={label ? `${uid}-label` : undefined}\n          aria-activedescendant={\n            open && activeIndex >= 0 ? `${uid}-opt-${activeIndex}` : undefined\n          }\n          disabled={disabled}\n          onClick={() => (open ? setOpen(false) : openMenu())}\n          onKeyDown={onKeyDown}\n          onMouseEnter={() => setHovered(true)}\n          onMouseLeave={() => setHovered(false)}\n          onFocus={(e) =>\n            setFocusVisible(e.currentTarget.matches(\":focus-visible\"))\n          }\n          onBlur={() => setFocusVisible(false)}\n          className=\"flex w-full items-center justify-between gap-3 text-left outline-none\"\n          style={{\n            height,\n            padding: `0 ${size * 0.95}px`,\n            borderRadius: radius,\n            border: `1px solid ${borderColor}`,\n            background: p.triggerBg,\n            color: selected ? p.text : p.muted,\n            fontSize: size,\n            fontWeight: 500,\n            cursor: disabled ? \"default\" : \"pointer\",\n            opacity: disabled ? 0.5 : 1,\n            boxShadow:\n              focusVisible || open\n                ? `0 0 0 3px color-mix(in srgb, ${accentColor} 25%, transparent)`\n                : \"0 0 0 0 transparent\",\n            transition: \"border-color 0.18s ease, box-shadow 0.18s ease\",\n          }}\n        >\n          <span className=\"truncate\">\n            {selected ? selected.label : placeholder}\n          </span>\n          <motion.span\n            className=\"flex shrink-0\"\n            animate={{ rotate: open ? 180 : 0 }}\n            transition={{ type: \"spring\", stiffness: 420, damping: 26 }}\n          >\n            <ChevronIcon\n              size={size * 1.1}\n              color={open ? accentColor : p.muted}\n            />\n          </motion.span>\n        </button>\n\n        <AnimatePresence>\n          {open && (\n            <motion.ul\n              id={listId}\n              role=\"listbox\"\n              aria-labelledby={label ? `${uid}-label` : undefined}\n              className=\"absolute left-0 z-50 m-0 w-full list-none overflow-auto p-1.5\"\n              style={{\n                top: \"calc(100% + 8px)\",\n                maxHeight: maxMenuHeight,\n                borderRadius: radius + 2,\n                border: `1px solid ${p.menuBorder}`,\n                background: p.menuBg,\n                boxShadow: p.shadow,\n                transformOrigin: \"top center\",\n              }}\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              {options.map((opt, i) => {\n                const isSelected = opt.value === current;\n                const isActive = i === activeIndex;\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                    onClick={() => commit(opt)}\n                    className=\"flex items-center justify-between gap-3\"\n                    style={{\n                      padding: `${size * 0.6}px ${size * 0.75}px`,\n                      borderRadius: radius - 4,\n                      background: isActive ? p.highlight : \"transparent\",\n                      opacity: opt.disabled ? 0.4 : 1,\n                      cursor: opt.disabled ? \"default\" : \"pointer\",\n                      transition: \"background 0.12s ease\",\n                    }}\n                  >\n                    <div className=\"flex min-w-0 flex-col gap-0.5\">\n                      <span\n                        className=\"truncate font-medium\"\n                        style={{\n                          color: isSelected ? accentColor : p.text,\n                          fontSize: size,\n                        }}\n                      >\n                        {opt.label}\n                      </span>\n                      {opt.description && (\n                        <span\n                          className=\"truncate\"\n                          style={{ color: p.muted, fontSize: size * 0.8 }}\n                        >\n                          {opt.description}\n                        </span>\n                      )}\n                    </div>\n                    {isSelected && (\n                      <span className=\"flex shrink-0\">\n                        <CheckIcon size={size} color={accentColor} />\n                      </span>\n                    )}\n                  </li>\n                );\n              })}\n            </motion.ul>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {helperText && (\n        <span style={{ color: p.muted, fontSize: size * 0.8, lineHeight: 1.4 }}>\n          {helperText}\n        </span>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}