{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox-motion",
  "title": "Motion combobox",
  "description": "Styled combobox: the Motion set. 5 decorative combobox variations (SlideCombobox, PopCombobox, FadeCombobox, SpringCombobox, MorphCombobox) 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-motion.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Check, ChevronsUpDown, Search } from \"lucide-react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Motion combobox family: 5 decorative SELF-CONTAINED searchable selects. NO\n   radix, NO portal, NO cmdk. The body stays the same in every variant; the whole\n   difference is in the PANEL's open / close motion. Each export is a complete\n   combobox: a real <input> carrying role=\"combobox\" filters, the arrow keys move\n   the highlight, Enter selects, Escape closes. Controlled (value/onValueChange) +\n   uncontrolled (defaultValue). Color comes ONLY from tokens, via alpha color-mix.\n   The motion is disabled through useReducedMotion. */\n\nexport type StyledSize = \"sm\" | \"md\" | \"lg\" | \"xl\"\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\n/* Varsayilan 6 secenek: prop'suz render eder. */\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\n/* The label can be a ReactNode; flatten it to plain text for filtering. */\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 border border-field-border bg-transparent pl-9 pr-9 text-sm text-foreground shadow-xs outline-none transition-colors placeholder:text-muted-foreground focus-visible:border-ring 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\n/* The panel carries a min-w so it does not get squeezed in a narrow container. */\nconst panelBase =\n  \"absolute left-0 right-0 top-full z-50 mt-2 min-w-56 overflow-hidden rounded-xl border border-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\n/* Ortak durum: input trigger + filtre + vurgu + klavye + disari tiklama. */\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  /* Filter while typing; show the full list only on focus. */\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    close,\n    onInputKeyDown,\n    wrapperRef,\n    inputValue,\n    listId,\n    optionId,\n  }\n}\n\ninterface PanelMotion {\n  initial: Record<string, number>\n  animate: Record<string, number>\n  exit: Record<string, number>\n  transition: Record<string, unknown>\n  className?: string\n}\n\n/* Shared shell: input plus an AnimatePresence panel. panelMotion carries each variant's opening flavour; a plain fade under reduced motion. */\nfunction MotionCombobox({\n  props,\n  panelMotion,\n}: {\n  props: ComboboxProps\n  panelMotion: PanelMotion\n}) {\n  const { className, size = \"md\", placeholder = \"Search framework...\" } = props\n  const state = useCombobox(props)\n  const reduce = useReducedMotion() ?? false\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      className={cn(rootBase, panelWidth[size], className)}\n    >\n      <div className=\"relative\">\n        <Search className=\"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground\" />\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])}\n        />\n        <ChevronsUpDown className=\"pointer-events-none absolute right-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground opacity-70\" />\n      </div>\n\n      <AnimatePresence>\n        {open ? (\n          <motion.div\n            id={listId}\n            role=\"listbox\"\n            className={cn(panelBase, panelMotion.className)}\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 } : panelMotion.transition}\n          >\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(\n                        optionBase,\n                        (isActive || isSelected) && \"bg-accent text-accent-foreground\"\n                      )}\n                    >\n                      <span className=\"flex-1 truncate\">{option.label}</span>\n                      {isSelected ? <Check className=\"text-foreground\" /> : null}\n                    </div>\n                  )\n                })\n              )}\n            </div>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  )\n}\n\n/* SlideCombobox: panel yukaridan asagi kayarak girer. */\nexport function SlideCombobox(props: ComboboxProps) {\n  return (\n    <MotionCombobox\n      props={props}\n      panelMotion={{\n        initial: { opacity: 0, y: -10 },\n        animate: { opacity: 1, y: 0 },\n        exit: { opacity: 0, y: -10 },\n        transition: { duration: 0.18, ease: \"easeOut\" },\n      }}\n    />\n  )\n}\n\n/* PopCombobox: it \"pops\" by growing from small and leans over the trigger. */\nexport function PopCombobox(props: ComboboxProps) {\n  return (\n    <MotionCombobox\n      props={props}\n      panelMotion={{\n        className: \"origin-top\",\n        initial: { opacity: 0, scale: 0.9 },\n        animate: { opacity: 1, scale: 1 },\n        exit: { opacity: 0, scale: 0.9 },\n        transition: { duration: 0.16, ease: \"easeOut\" },\n      }}\n    />\n  )\n}\n\n/* FadeCombobox: opacity only; no movement, a calm transition. */\nexport function FadeCombobox(props: ComboboxProps) {\n  return (\n    <MotionCombobox\n      props={props}\n      panelMotion={{\n        initial: { opacity: 0 },\n        animate: { opacity: 1 },\n        exit: { opacity: 0 },\n        transition: { duration: 0.22, ease: \"easeInOut\" },\n      }}\n    />\n  )\n}\n\n/* SpringCombobox: yayli, hafif zipli giris. */\nexport function SpringCombobox(props: ComboboxProps) {\n  return (\n    <MotionCombobox\n      props={props}\n      panelMotion={{\n        className: \"origin-top\",\n        initial: { opacity: 0, y: -14, scale: 0.96 },\n        animate: { opacity: 1, y: 0, scale: 1 },\n        exit: { opacity: 0, y: -8, scale: 0.98 },\n        transition: { type: \"spring\" as const, stiffness: 420, damping: 26, mass: 0.7 },\n      }}\n    />\n  )\n}\n\n/* MorphCombobox: it grows with scaleY like a curtain opening vertically. */\nexport function MorphCombobox(props: ComboboxProps) {\n  return (\n    <MotionCombobox\n      props={props}\n      panelMotion={{\n        className: \"origin-top\",\n        initial: { opacity: 0, scaleY: 0.6, scaleX: 0.98 },\n        animate: { opacity: 1, scaleY: 1, scaleX: 1 },\n        exit: { opacity: 0, scaleY: 0.6, scaleX: 0.98 },\n        transition: { duration: 0.2, ease: \"easeOut\" },\n      }}\n    />\n  )\n}\n",
      "type": "registry:component",
      "target": "components/ui/combobox-motion.tsx"
    }
  ],
  "categories": [
    "styled",
    "combobox"
  ],
  "type": "registry:component"
}