{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search-bar",
  "title": "Search Bar",
  "description": "An accessible animated search field with a live suggestions menu, keyboard navigation, a clear button, a loading spinner and a Cmd/Ctrl+K shortcut.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/search-bar/search-bar.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 SearchBarProps {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  onSearch?: (value: string) => void;\n  placeholder?: string;\n  suggestions?: string[];\n  maxSuggestions?: number;\n  shortcut?: string;\n  enableShortcut?: boolean;\n  loading?: boolean;\n  disabled?: boolean;\n  theme?: \"dark\" | \"light\";\n  size?: number;\n  radius?: number;\n  width?: number;\n  accentColor?: string;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"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    kbdBg: \"rgba(255,255,255,0.06)\",\n    kbdBorder: \"rgba(255,255,255,0.1)\",\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    bg: \"#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    kbdBg: \"rgba(10,10,10,0.04)\",\n    kbdBorder: \"rgba(10,10,10,0.1)\",\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 SearchIcon({ size, color }: { size: number; color: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n      <circle cx=\"7\" cy=\"7\" r=\"4.6\" stroke={color} strokeWidth=\"1.6\" />\n      <path d=\"M10.6 10.6L13.6 13.6\" stroke={color} strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction Spinner({ size, color }: { size: number; color: string }) {\n  return (\n    <motion.svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" animate={{ rotate: 360 }} transition={{ duration: 0.8, ease: \"linear\", repeat: Infinity }}>\n      <circle cx=\"8\" cy=\"8\" r=\"5.6\" stroke={color} strokeOpacity=\"0.25\" strokeWidth=\"1.6\" />\n      <path d=\"M8 2.4A5.6 5.6 0 0 1 13.6 8\" stroke={color} strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n    </motion.svg>\n  );\n}\n\nfunction highlightMatch(text: string, query: string, color: 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={{ color, fontWeight: 700 }}>{text.slice(i, i + q.length)}</span>\n      {text.slice(i + q.length)}\n    </>\n  );\n}\n\nexport function SearchBar({\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  onSearch,\n  placeholder = \"Search components...\",\n  suggestions = [],\n  maxSuggestions = 6,\n  shortcut = \"⌘K\",\n  enableShortcut = true,\n  loading = false,\n  disabled = false,\n  theme = \"dark\",\n  size = 15,\n  radius = 14,\n  width = 360,\n  accentColor = \"#F2A841\",\n  className,\n}: SearchBarProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [internal, setInternal] = React.useState(defaultValue);\n  const [focused, setFocused] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const [menuOpen, setMenuOpen] = React.useState(false);\n  const [activeIndex, setActiveIndex] = React.useState(-1);\n  const isControlled = value !== undefined;\n  const text = isControlled ? value : internal;\n  const height = Math.round(size * 3);\n  const listId = `${uid}-list`;\n\n  const matches = React.useMemo(() => {\n    const q = text.trim().toLowerCase();\n    const list = q ? suggestions.filter((s) => s.toLowerCase().includes(q) && s.toLowerCase() !== q) : suggestions;\n    return list.slice(0, maxSuggestions);\n  }, [text, suggestions, maxSuggestions]);\n  const showMenu = menuOpen && focused && matches.length > 0;\n\n  const setText = (next: string) => {\n    if (!isControlled) setInternal(next);\n    onValueChange?.(next);\n  };\n\n  const submit = (v: string) => {\n    onSearch?.(v);\n    setMenuOpen(false);\n    setActiveIndex(-1);\n  };\n\n  const pick = (s: string) => {\n    setText(s);\n    submit(s);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      if (matches.length === 0) return;\n      e.preventDefault();\n      setMenuOpen(true);\n      const dir = e.key === \"ArrowDown\" ? 1 : -1;\n      setActiveIndex((i) => (i === -1 ? (dir === 1 ? 0 : matches.length - 1) : (i + dir + matches.length) % matches.length));\n    } else if (e.key === \"Enter\") {\n      if (showMenu && activeIndex >= 0) pick(matches[activeIndex]);\n      else submit(text);\n    } else if (e.key === \"Escape\") {\n      if (showMenu) setMenuOpen(false);\n      else if (text) setText(\"\");\n      else inputRef.current?.blur();\n    }\n  };\n\n  React.useEffect(() => {\n    if (!enableShortcut || disabled) return;\n    const onKey = (e: KeyboardEvent) => {\n      if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"k\") {\n        e.preventDefault();\n        inputRef.current?.focus();\n      }\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [enableShortcut, disabled]);\n\n  React.useEffect(() => {\n    if (!menuOpen) return;\n    const onDown = (e: MouseEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setMenuOpen(false);\n    };\n    document.addEventListener(\"mousedown\", onDown);\n    return () => document.removeEventListener(\"mousedown\", onDown);\n  }, [menuOpen]);\n\n  const borderColor = focused ? accentColor : hovered ? p.borderHover : p.border;\n  const showKbd = shortcut && !focused && !text && !loading;\n\n  return (\n    <div ref={rootRef} className={cn(\"relative inline-block\", className)} style={{ width, fontFamily: \"Inter, sans-serif\" }}>\n      <div\n        onMouseEnter={() => setHovered(true)}\n        onMouseLeave={() => setHovered(false)}\n        onClick={() => inputRef.current?.focus()}\n        className=\"flex items-center\"\n        style={{\n          height,\n          gap: size * 0.7,\n          padding: `0 ${size * 0.85}px`,\n          borderRadius: radius,\n          border: `1px solid ${borderColor}`,\n          background: p.bg,\n          opacity: disabled ? 0.5 : 1,\n          cursor: disabled ? \"default\" : \"text\",\n          boxShadow: focused ? `0 0 0 3px color-mix(in srgb, ${accentColor} 25%, transparent)` : \"0 0 0 0 transparent\",\n          transition: \"border-color 0.18s ease, box-shadow 0.18s ease\",\n        }}\n      >\n        <span className=\"flex shrink-0\" style={{ width: size * 1.15, height: size * 1.15 }}>\n          {loading ? <Spinner size={size * 1.15} color={accentColor} /> : <SearchIcon size={size * 1.15} color={focused ? accentColor : p.muted} />}\n        </span>\n\n        <input\n          ref={inputRef}\n          type=\"text\"\n          role=\"combobox\"\n          aria-expanded={showMenu}\n          aria-controls={listId}\n          aria-autocomplete=\"list\"\n          aria-activedescendant={showMenu && activeIndex >= 0 ? `${uid}-opt-${activeIndex}` : undefined}\n          value={text}\n          disabled={disabled}\n          placeholder={placeholder}\n          onChange={(e) => {\n            setText(e.target.value);\n            setMenuOpen(true);\n            setActiveIndex(-1);\n          }}\n          onFocus={() => {\n            setFocused(true);\n            setMenuOpen(true);\n          }}\n          onBlur={() => setFocused(false)}\n          onKeyDown={onKeyDown}\n          className=\"min-w-0 flex-1 border-none bg-transparent p-0 outline-none placeholder:text-[color:var(--sb-placeholder)]\"\n          style={{ color: p.text, fontSize: size, fontWeight: 500, [\"--sb-placeholder\" as string]: p.muted }}\n        />\n\n        <AnimatePresence initial={false}>\n          {text && !disabled && (\n            <motion.button\n              key=\"clear\"\n              type=\"button\"\n              aria-label=\"Clear search\"\n              onMouseDown={(e) => e.preventDefault()}\n              onClick={() => {\n                setText(\"\");\n                inputRef.current?.focus();\n              }}\n              className=\"flex shrink-0 cursor-pointer items-center justify-center rounded-full border-none p-0\"\n              style={{ width: size * 1.35, height: size * 1.35, background: p.kbdBg, color: p.muted }}\n              initial={{ opacity: 0, scale: 0.6 }}\n              animate={{ opacity: 1, scale: 1 }}\n              exit={{ opacity: 0, scale: 0.6 }}\n              transition={{ duration: 0.14 }}\n              whileTap={{ scale: 0.9 }}\n            >\n              <svg width={size * 0.7} height={size * 0.7} viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                <path d=\"M3 3L9 9M9 3L3 9\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n              </svg>\n            </motion.button>\n          )}\n        </AnimatePresence>\n\n        {showKbd && (\n          <span className=\"shrink-0 rounded-md font-medium\" style={{ padding: `${size * 0.2}px ${size * 0.5}px`, background: p.kbdBg, border: `1px solid ${p.kbdBorder}`, color: p.muted, fontSize: size * 0.8 }}>\n            {shortcut}\n          </span>\n        )}\n      </div>\n\n      <AnimatePresence>\n        {showMenu && (\n          <motion.ul\n            id={listId}\n            role=\"listbox\"\n            className=\"absolute left-0 z-50 m-0 w-full list-none p-1.5\"\n            style={{ top: \"calc(100% + 8px)\", borderRadius: 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            {matches.map((s, i) => (\n              <li\n                key={s}\n                id={`${uid}-opt-${i}`}\n                role=\"option\"\n                aria-selected={i === activeIndex}\n                onMouseEnter={() => setActiveIndex(i)}\n                onMouseDown={(e) => e.preventDefault()}\n                onClick={() => pick(s)}\n                className=\"flex cursor-pointer items-center\"\n                style={{ gap: size * 0.7, padding: `${size * 0.6}px ${size * 0.75}px`, borderRadius: radius - 4, background: i === activeIndex ? p.highlight : \"transparent\", color: p.text, fontSize: size, transition: \"background 0.12s ease\" }}\n              >\n                <SearchIcon size={size * 0.95} color={p.muted} />\n                <span className=\"truncate\">{highlightMatch(s, text, accentColor)}</span>\n              </li>\n            ))}\n          </motion.ul>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}