{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "apple-search-field",
  "type": "registry:ui",
  "title": "Search Field",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Rounded iOS-inspired search bar with a magnifier icon, inline clear badge, quick suggestion pills, and a 'Cancel' button that slides in smoothly on focus.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/apple-search-field.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useRef } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { Search, X, ArrowUpRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface AppleSearchFieldProps {\n  /** Placeholder text inside the search field */\n  placeholder?: string;\n  /** Controlled search query */\n  value?: string;\n  /** Initial query for uncontrolled mode */\n  defaultValue?: string;\n  /** Callback fired when query changes */\n  onChange?: (query: string) => void;\n  /** Callback fired when Cancel is clicked */\n  onCancel?: () => void;\n  /** Quick suggestion pills shown when focused */\n  suggestions?: string[];\n  className?: string;\n}\n\nconst DEFAULT_SUGGESTIONS = [\n  \"Drawer Overlay\",\n  \"Picker Wheel\",\n  \"Sticky Sub-Nav\",\n  \"Command Menu\",\n];\n\nexport function AppleSearchField({\n  placeholder = \"Search components, tokens, or docs...\",\n  value: controlledValue,\n  defaultValue = \"\",\n  onChange,\n  onCancel,\n  suggestions = DEFAULT_SUGGESTIONS,\n  className,\n}: AppleSearchFieldProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const inputRef = useRef<HTMLInputElement>(null);\n  const isControlled = controlledValue !== undefined;\n\n  const [internalQuery, setInternalQuery] = useState(defaultValue);\n  const [isActive, setIsActive] = useState(false);\n\n  const query = isControlled ? controlledValue : internalQuery;\n  const showCancel = isActive || query.length > 0;\n\n  const setQuery = (next: string) => {\n    if (!isControlled) {\n      setInternalQuery(next);\n    }\n    onChange?.(next);\n  };\n\n  const handleCancel = () => {\n    setQuery(\"\");\n    setIsActive(false);\n    inputRef.current?.blur();\n    onCancel?.();\n  };\n\n  const filteredSuggestions = suggestions.filter((s) =>\n    s.toLowerCase().includes(query.trim().toLowerCase())\n  );\n\n  return (\n    <div className={cn(\"w-full max-w-md\", className)}>\n      <div className=\"flex items-center gap-2.5\">\n        {/* Expanding / Contracting Rounded Search Field */}\n        <motion.div\n          layout={!shouldReduceMotion}\n          transition={{ type: \"spring\", stiffness: 420, damping: 32 }}\n          className={cn(\n            \"relative flex h-11 flex-1 items-center rounded-2xl border bg-neutral-100/80 px-3.5 transition-colors dark:bg-[#121212]\",\n            isActive\n              ? \"border-neutral-900 bg-white ring-3 ring-neutral-900/10 dark:border-white dark:bg-[#0A0A0A] dark:ring-white/15\"\n              : \"border-neutral-200/80 hover:border-neutral-300 dark:border-neutral-800\"\n          )}\n        >\n          <Search\n            className={cn(\n              \"mr-2.5 h-4 w-4 shrink-0 transition-colors\",\n              isActive\n                ? \"text-neutral-900 dark:text-white\"\n                : \"text-neutral-400 dark:text-neutral-500\"\n            )}\n          />\n\n          <input\n            ref={inputRef}\n            type=\"search\"\n            value={query}\n            onFocus={() => setIsActive(true)}\n            onChange={(e) => setQuery(e.target.value)}\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\") {\n                handleCancel();\n              }\n            }}\n            placeholder={placeholder}\n            className=\"w-full bg-transparent text-xs font-medium text-neutral-950 placeholder:text-neutral-400 focus:outline-none dark:text-white dark:placeholder:text-neutral-500 sm:text-sm [&::-webkit-search-cancel-button]:hidden\"\n          />\n\n          {/* Clear Circle Button */}\n          <AnimatePresence>\n            {query.length > 0 && (\n              <motion.button\n                type=\"button\"\n                aria-label=\"Clear search query\"\n                initial={{ opacity: 0, scale: 0.7 }}\n                animate={{ opacity: 1, scale: 1 }}\n                exit={{ opacity: 0, scale: 0.7 }}\n                transition={{ duration: 0.12 }}\n                onMouseDown={(e) => e.preventDefault()}\n                onClick={() => setQuery(\"\")}\n                className=\"ml-1.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-neutral-300/80 text-neutral-700 transition-colors hover:bg-neutral-400/80 dark:bg-neutral-800 dark:text-neutral-300 dark:hover:bg-neutral-700\"\n              >\n                <X className=\"h-3 w-3\" />\n              </motion.button>\n            )}\n          </AnimatePresence>\n        </motion.div>\n\n        {/* Sliding Cancel Button */}\n        <AnimatePresence initial={false}>\n          {showCancel && (\n            <motion.button\n              type=\"button\"\n              initial={\n                shouldReduceMotion\n                  ? { opacity: 0 }\n                  : { opacity: 0, x: 16, width: 0 }\n              }\n              animate={{ opacity: 1, x: 0, width: \"auto\" }}\n              exit={\n                shouldReduceMotion\n                  ? { opacity: 0 }\n                  : { opacity: 0, x: 16, width: 0 }\n              }\n              transition={{ type: \"spring\", stiffness: 420, damping: 32 }}\n              onClick={handleCancel}\n              className=\"shrink-0 overflow-hidden whitespace-nowrap text-xs font-semibold text-neutral-900 hover:underline dark:text-white sm:text-sm\"\n            >\n              Cancel\n            </motion.button>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {/* Quick Suggestions Shelf when active */}\n      <AnimatePresence>\n        {showCancel && filteredSuggestions.length > 0 && (\n          <motion.div\n            initial={\n              shouldReduceMotion ? { opacity: 0 } : { opacity: 0, y: -6 }\n            }\n            animate={{ opacity: 1, y: 0 }}\n            exit={shouldReduceMotion ? { opacity: 0 } : { opacity: 0, y: -6 }}\n            transition={{ type: \"spring\", stiffness: 400, damping: 30 }}\n            className=\"mt-2.5 flex flex-wrap items-center gap-1.5\"\n          >\n            {filteredSuggestions.map((item) => (\n              <button\n                key={item}\n                type=\"button\"\n                onMouseDown={(e) => e.preventDefault()}\n                onClick={() => setQuery(item)}\n                className=\"inline-flex items-center gap-1 rounded-full border border-neutral-200 bg-white px-2.5 py-1 text-[11px] font-medium text-neutral-600 transition-colors hover:border-neutral-900 hover:text-neutral-950 dark:border-neutral-800 dark:bg-[#0A0A0A] dark:text-neutral-400 dark:hover:border-white dark:hover:text-white\"\n              >\n                <span>{item}</span>\n                <ArrowUpRight className=\"h-3 w-3 opacity-60\" />\n              </button>\n            ))}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default AppleSearchField;\n",
      "type": "registry:ui",
      "target": "components/ui/apple-search-field.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
