{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox-tone",
  "title": "Tone combobox",
  "description": "Styled combobox: the Tone set. 5 decorative combobox variations (InfoCombobox, SuccessCombobox, WarningCombobox, DangerCombobox, MutedCombobox) on the ai2 token system, powered by framer-motion, reduced-motion aware and sized sm to xl. Part of the free styled layer.",
  "dependencies": [
    "motion@^12.42.2",
    "lucide-react@^1.23.0"
  ],
  "registryDependencies": [
    "@ai2/tokens"
  ],
  "files": [
    {
      "path": "registry/ai2/styled/combobox-tone.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  AlertTriangle,\n  Check,\n  ChevronsUpDown,\n  CircleAlert,\n  CircleCheck,\n  Info,\n  Minus,\n  Search,\n} from \"lucide-react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Tone combobox family: 5 decorative SELF-CONTAINED searchable selects. NO radix,\n   NO portal, NO cmdk. The body is the same in every variant; the whole difference\n   is the SEMANTIC TONE: info, success, warning, danger and muted. The tone drives\n   the border, the focus ring, the leading icon, the panel header and the\n   highlight of the selected row. ai2 uses `danger`, NOT `destructive`. Each export\n   is a complete combobox: a real <input> carrying role=\"combobox\" filters, the\n   arrow keys move the highlight, Enter selects, Escape closes. Color comes ONLY\n   from tokens, via alpha color-mix. Every root carries `data-tone`. */\n\nexport type StyledSize = \"sm\" | \"md\" | \"lg\" | \"xl\"\n\ntype Tone = \"info\" | \"success\" | \"warning\" | \"danger\" | \"muted\"\n\nconst triggerHeight: Record<StyledSize, string> = {\n  sm: \"h-8\",\n  md: \"h-9\",\n  lg: \"h-10\",\n  xl: \"h-12\",\n}\n\nconst panelWidth: Record<StyledSize, string> = {\n  sm: \"w-56\",\n  md: \"w-64\",\n  lg: \"w-72\",\n  xl: \"w-80\",\n}\n\nexport interface ComboboxOption {\n  value: string\n  label: React.ReactNode\n}\n\ninterface ComboboxProps {\n  className?: string\n  size?: StyledSize\n  placeholder?: string\n  options?: ComboboxOption[]\n  value?: string\n  defaultValue?: string\n  onValueChange?: (v: string) => void\n}\n\nconst defaultOptions: ComboboxOption[] = [\n  { value: \"next\", label: \"Next.js\" },\n  { value: \"react\", label: \"React\" },\n  { value: \"vue\", label: \"Vue\" },\n  { value: \"svelte\", label: \"Svelte\" },\n  { value: \"solid\", label: \"Solid\" },\n  { value: \"astro\", label: \"Astro\" },\n]\n\nfunction nodeText(node: React.ReactNode): string {\n  if (node === null || node === undefined || typeof node === \"boolean\") return \"\"\n  if (typeof node === \"string\" || typeof node === \"number\") return String(node)\n  if (Array.isArray(node)) return node.map(nodeText).join(\"\")\n  if (React.isValidElement(node)) {\n    return nodeText((node.props as { children?: React.ReactNode }).children)\n  }\n  return \"\"\n}\n\nfunction filterOptions(options: ComboboxOption[], query: string): ComboboxOption[] {\n  const q = query.trim().toLowerCase()\n  if (q.length === 0) return options\n  return options.filter((o) => nodeText(o.label).toLowerCase().includes(q))\n}\n\nconst rootBase = \"relative\"\n\nconst inputBase =\n  \"w-full rounded-lg bg-transparent pl-9 pr-9 text-sm text-foreground shadow-xs outline-none transition-colors placeholder:text-muted-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-danger aria-invalid:ring-danger/20 dark:aria-invalid:ring-danger/40\"\n\nconst panelBase =\n  \"absolute left-0 right-0 top-full z-50 mt-2 min-w-56 origin-top overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-lg outline-none\"\n\nconst listBase = \"max-h-60 overflow-y-auto p-1.5\"\n\nconst optionBase =\n  \"flex cursor-pointer select-none items-center gap-2 rounded-lg px-2.5 py-2 text-sm outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none\"\n\nconst emptyBase = \"py-6 text-center text-sm text-muted-foreground\"\n\nconst noteBase =\n  \"flex items-center gap-2 border-b px-3 py-2 text-xs [&_svg]:size-3.5 [&_svg]:shrink-0 [&_i]:text-sm [&_i]:leading-none\"\n\nconst panelMotion = {\n  initial: { opacity: 0, scale: 0.98, y: -6 },\n  animate: { opacity: 1, scale: 1, y: 0 },\n  exit: { opacity: 0, scale: 0.98, y: -6 },\n}\n\ninterface ToneStyle {\n  border: string\n  ring: string\n  icon: string\n  panelBorder: string\n  note: string\n  noteText: string\n  active: string\n  note_label: string\n}\n\n/* Tone map: every tone carries its own border, ring, icon and note colour. */\nconst toneStyles: Record<Tone, ToneStyle> = {\n  info: {\n    border: \"border border-[color-mix(in_oklab,var(--color-info)_55%,transparent)]\",\n    ring: \"focus-visible:border-info\",\n    icon: \"text-info\",\n    panelBorder: \"border-[color-mix(in_oklab,var(--color-info)_40%,transparent)]\",\n    note: \"border-[color-mix(in_oklab,var(--color-info)_30%,transparent)] bg-[color-mix(in_oklab,var(--color-info)_10%,transparent)]\",\n    noteText: \"text-info\",\n    active: \"bg-[color-mix(in_oklab,var(--color-info)_14%,transparent)] text-foreground\",\n    note_label: \"Pick the framework you want docs for.\",\n  },\n  success: {\n    border: \"border border-[color-mix(in_oklab,var(--color-success)_55%,transparent)]\",\n    ring: \"focus-visible:border-success\",\n    icon: \"text-success\",\n    panelBorder: \"border-[color-mix(in_oklab,var(--color-success)_40%,transparent)]\",\n    note: \"border-[color-mix(in_oklab,var(--color-success)_30%,transparent)] bg-[color-mix(in_oklab,var(--color-success)_10%,transparent)]\",\n    noteText: \"text-success\",\n    active: \"bg-[color-mix(in_oklab,var(--color-success)_14%,transparent)] text-foreground\",\n    note_label: \"Every option here is verified and ready.\",\n  },\n  warning: {\n    border: \"border border-[color-mix(in_oklab,var(--color-warning)_55%,transparent)]\",\n    ring: \"focus-visible:border-warning\",\n    icon: \"text-warning\",\n    panelBorder: \"border-[color-mix(in_oklab,var(--color-warning)_40%,transparent)]\",\n    note: \"border-[color-mix(in_oklab,var(--color-warning)_30%,transparent)] bg-[color-mix(in_oklab,var(--color-warning)_10%,transparent)]\",\n    noteText: \"text-warning\",\n    active: \"bg-[color-mix(in_oklab,var(--color-warning)_16%,transparent)] text-foreground\",\n    note_label: \"Some options may change on the next release.\",\n  },\n  danger: {\n    border: \"border border-[color-mix(in_oklab,var(--color-danger)_55%,transparent)]\",\n    ring: \"focus-visible:border-danger\",\n    icon: \"text-danger\",\n    panelBorder: \"border-[color-mix(in_oklab,var(--color-danger)_40%,transparent)]\",\n    note: \"border-[color-mix(in_oklab,var(--color-danger)_30%,transparent)] bg-[color-mix(in_oklab,var(--color-danger)_10%,transparent)]\",\n    noteText: \"text-danger\",\n    active: \"bg-[color-mix(in_oklab,var(--color-danger)_14%,transparent)] text-foreground\",\n    note_label: \"This choice cannot be undone later.\",\n  },\n  muted: {\n    border: \"border border-border\",\n    ring: \"focus-visible:border-ring\",\n    icon: \"text-muted-foreground\",\n    panelBorder: \"border-border\",\n    note: \"border-border bg-[color-mix(in_oklab,var(--color-foreground)_5%,transparent)]\",\n    noteText: \"text-muted-foreground\",\n    active: \"bg-accent text-accent-foreground\",\n    note_label: \"A quiet, low-emphasis picker.\",\n  },\n}\n\nfunction useCombobox(props: ComboboxProps) {\n  const { options = defaultOptions, value, defaultValue, onValueChange } = props\n  const isControlled = value !== undefined\n  const [internal, setInternal] = React.useState<string | undefined>(defaultValue)\n  const current = isControlled ? value : internal\n\n  const [open, setOpen] = React.useState(false)\n  const [editing, setEditing] = React.useState(false)\n  const [query, setQuery] = React.useState(\"\")\n  const [active, setActive] = React.useState(0)\n\n  const wrapperRef = React.useRef<HTMLDivElement>(null)\n  const uid = React.useId()\n  const listId = `${uid}-list`\n  const optionId = React.useCallback((i: number) => `${uid}-option-${i}`, [uid])\n\n  const selected = React.useMemo(\n    () => (current === undefined ? undefined : options.find((o) => o.value === current)),\n    [options, current]\n  )\n\n  const filtered = React.useMemo(\n    () => (editing ? filterOptions(options, query) : options),\n    [editing, options, query]\n  )\n\n  React.useEffect(() => {\n    setActive((prev) => (prev >= filtered.length ? 0 : prev))\n  }, [filtered.length])\n\n  const close = React.useCallback(() => {\n    setOpen(false)\n    setEditing(false)\n    setQuery(\"\")\n    setActive(0)\n  }, [])\n\n  React.useEffect(() => {\n    if (!open) return\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") close()\n    }\n    const onPointer = (e: PointerEvent) => {\n      const node = wrapperRef.current\n      if (node && e.target instanceof Node && !node.contains(e.target)) close()\n    }\n    window.addEventListener(\"keydown\", onKey)\n    window.addEventListener(\"pointerdown\", onPointer)\n    return () => {\n      window.removeEventListener(\"keydown\", onKey)\n      window.removeEventListener(\"pointerdown\", onPointer)\n    }\n  }, [open, close])\n\n  const commit = React.useCallback(\n    (next: string) => {\n      if (!isControlled) setInternal(next)\n      onValueChange?.(next)\n      close()\n    },\n    [isControlled, onValueChange, close]\n  )\n\n  const onInputKeyDown = React.useCallback(\n    (e: React.KeyboardEvent<HTMLInputElement>) => {\n      if (e.key === \"ArrowDown\") {\n        e.preventDefault()\n        setOpen(true)\n        setActive((prev) => (filtered.length === 0 ? 0 : (prev + 1) % filtered.length))\n      } else if (e.key === \"ArrowUp\") {\n        e.preventDefault()\n        setOpen(true)\n        setActive((prev) =>\n          filtered.length === 0 ? 0 : (prev - 1 + filtered.length) % filtered.length\n        )\n      } else if (e.key === \"Enter\") {\n        e.preventDefault()\n        const item = filtered[active]\n        if (item) commit(item.value)\n      } else if (e.key === \"Escape\") {\n        e.preventDefault()\n        close()\n      }\n    },\n    [filtered, active, commit, close]\n  )\n\n  const inputValue = editing ? query : selected ? nodeText(selected.label) : \"\"\n\n  return {\n    open,\n    setOpen,\n    setEditing,\n    setQuery,\n    active,\n    setActive,\n    filtered,\n    current,\n    commit,\n    onInputKeyDown,\n    wrapperRef,\n    inputValue,\n    listId,\n    optionId,\n  }\n}\n\n/* Shared shell: toned input plus toned panel plus a toned note row. */\nfunction ToneCombobox({\n  props,\n  tone,\n  toneIcon,\n}: {\n  props: ComboboxProps\n  tone: Tone\n  toneIcon: React.ReactNode\n}) {\n  const { className, size = \"md\", placeholder = \"Search framework...\" } = props\n  const state = useCombobox(props)\n  const reduce = useReducedMotion() ?? false\n  const t = toneStyles[tone]\n  const {\n    open,\n    setOpen,\n    setEditing,\n    setQuery,\n    active,\n    setActive,\n    filtered,\n    current,\n    commit,\n    onInputKeyDown,\n    wrapperRef,\n    inputValue,\n    listId,\n    optionId,\n  } = state\n\n  const activeId = open && filtered[active] ? optionId(active) : undefined\n\n  return (\n    <div\n      ref={wrapperRef}\n      data-slot=\"styled-combobox\"\n      data-tone={tone}\n      className={cn(rootBase, panelWidth[size], className)}\n    >\n      <div className=\"relative\">\n        <span\n          className={cn(\n            \"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 [&_svg]:size-4 [&_i]:text-base [&_i]:leading-none\",\n            t.icon\n          )}\n        >\n          {toneIcon}\n        </span>\n        <input\n          role=\"combobox\"\n          aria-expanded={open}\n          aria-controls={listId}\n          aria-autocomplete=\"list\"\n          aria-activedescendant={activeId}\n          value={inputValue}\n          placeholder={placeholder}\n          onFocus={() => {\n            setOpen(true)\n            setEditing(false)\n          }}\n          onChange={(e) => {\n            setOpen(true)\n            setEditing(true)\n            setQuery(e.target.value)\n          }}\n          onKeyDown={onInputKeyDown}\n          className={cn(inputBase, triggerHeight[size], t.border, t.ring)}\n        />\n        <ChevronsUpDown\n          className={cn(\n            \"pointer-events-none absolute right-3 top-1/2 size-4 -translate-y-1/2 opacity-70\",\n            t.icon\n          )}\n        />\n      </div>\n\n      <AnimatePresence>\n        {open ? (\n          <motion.div\n            id={listId}\n            role=\"listbox\"\n            className={cn(panelBase, t.panelBorder)}\n            initial={reduce ? { opacity: 0 } : panelMotion.initial}\n            animate={reduce ? { opacity: 1 } : panelMotion.animate}\n            exit={reduce ? { opacity: 0 } : panelMotion.exit}\n            transition={reduce ? { duration: 0 } : { duration: 0.16, ease: \"easeOut\" }}\n          >\n            <div className={cn(noteBase, t.note, t.noteText)}>\n              <Search className=\"shrink-0\" />\n              <span className=\"truncate\">{t.note_label}</span>\n            </div>\n            <div className={listBase}>\n              {filtered.length === 0 ? (\n                <p className={emptyBase}>No results found.</p>\n              ) : (\n                filtered.map((option, i) => {\n                  const isActive = i === active\n                  const isSelected = option.value === current\n                  return (\n                    <div\n                      key={option.value}\n                      id={optionId(i)}\n                      role=\"option\"\n                      tabIndex={-1}\n                      aria-selected={isSelected}\n                      onMouseEnter={() => setActive(i)}\n                      onClick={() => commit(option.value)}\n                      className={cn(optionBase, (isActive || isSelected) && t.active)}\n                    >\n                      <span className=\"flex-1 truncate\">{option.label}</span>\n                      {isSelected ? <Check className={t.icon} /> : null}\n                    </div>\n                  )\n                })\n              )}\n            </div>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  )\n}\n\n/* InfoCombobox: info tonu; notlu, bilgilendirici bir secici. */\nexport function InfoCombobox(props: ComboboxProps) {\n  return <ToneCombobox props={props} tone=\"info\" toneIcon={<Info />} />\n}\n\n/* SuccessCombobox: a success tone; it reads like a validated field. */\nexport function SuccessCombobox(props: ComboboxProps) {\n  return <ToneCombobox props={props} tone=\"success\" toneIcon={<CircleCheck />} />\n}\n\n/* WarningCombobox: warning tonu; dikkat isteyen secim. */\nexport function WarningCombobox(props: ComboboxProps) {\n  return <ToneCombobox props={props} tone=\"warning\" toneIcon={<AlertTriangle />} />\n}\n\n/* DangerCombobox: the danger tone (NOT destructive); an irreversible choice. */\nexport function DangerCombobox(props: ComboboxProps) {\n  return <ToneCombobox props={props} tone=\"danger\" toneIcon={<CircleAlert />} />\n}\n\n/* MutedCombobox: notr, dusuk vurgulu ton. */\nexport function MutedCombobox(props: ComboboxProps) {\n  return <ToneCombobox props={props} tone=\"muted\" toneIcon={<Minus />} />\n}\n",
      "type": "registry:component",
      "target": "components/ui/combobox-tone.tsx"
    }
  ],
  "categories": [
    "styled",
    "combobox"
  ],
  "type": "registry:component"
}