{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "elastic-tag-input",
  "type": "registry:ui",
  "title": "Elastic Tag Input",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Tokenized multi-tag input with Hooke's Law pill pop-in, FLIP layout reflow, and a two-step Backspace warning wiggle before deletion.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/elastic-tag-input.tsx",
      "content": "\"use client\";\n\nimport React, { useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { Plus, X, Tag } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ElasticTagInputProps {\n  /** Initial array of tag strings. */\n  defaultTags?: string[];\n  /** Maximum number of tags allowed. Default: 8 */\n  maxTags?: number;\n  /** Input placeholder text. Default: \"Add tag & press Enter...\" */\n  placeholder?: string;\n  /** Spring stiffness coefficient for tag pill pop-in and reflow. Default: 380 */\n  stiffness?: number;\n  /** Spring damping coefficient for tag pill pop-in and reflow. Default: 24 */\n  damping?: number;\n  /** Callback fired when tag list changes */\n  onChange?: (tags: string[]) => void;\n  className?: string;\n}\n\nconst DEFAULT_TAGS = [\"framer-motion\", \"spring-physics\", \"shadcn-v2\"];\n\nexport function ElasticTagInput({\n  defaultTags = DEFAULT_TAGS,\n  maxTags = 8,\n  placeholder = \"Add tag & press Enter...\",\n  stiffness = 380,\n  damping = 24,\n  onChange,\n  className,\n}: ElasticTagInputProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const [tags, setTags] = useState<string[]>(defaultTags);\n  const [inputValue, setInputValue] = useState(\"\");\n  const [pendingDeleteLast, setPendingDeleteLast] = useState(false);\n\n  const commitTags = (next: string[]) => {\n    setTags(next);\n    onChange?.(next);\n  };\n\n  const addTag = (raw: string) => {\n    const cleaned = raw.trim().toLowerCase().replace(/\\s+/g, \"-\");\n    if (!cleaned || tags.includes(cleaned) || tags.length >= maxTags) return;\n    commitTags([...tags, cleaned]);\n    setInputValue(\"\");\n    setPendingDeleteLast(false);\n  };\n\n  const removeTag = (target: string) => {\n    commitTags(tags.filter((t) => t !== target));\n    setPendingDeleteLast(false);\n  };\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"Enter\" || e.key === \",\") {\n      e.preventDefault();\n      addTag(inputValue);\n    } else if (e.key === \"Backspace\" && inputValue === \"\" && tags.length > 0) {\n      if (!pendingDeleteLast) {\n        setPendingDeleteLast(true);\n      } else {\n        const last = tags[tags.length - 1];\n        if (last) removeTag(last);\n      }\n    } else {\n      setPendingDeleteLast(false);\n    }\n  };\n\n  return (\n    <div\n      className={cn(\n        \"w-full max-w-md rounded-2xl border border-neutral-200 bg-white p-4 shadow-sm dark:border-[#222222] dark:bg-[#0A0A0A]\",\n        className\n      )}\n    >\n      <div className=\"mb-2.5 flex items-center justify-between text-xs\">\n        <span className=\"inline-flex items-center gap-1.5 font-semibold text-black dark:text-white\">\n          <Tag className=\"h-3.5 w-3.5\" />\n          <span>Registry Keywords</span>\n        </span>\n        <span className=\"font-mono text-[10px] text-neutral-400\">\n          {tags.length}/{maxTags} tags\n        </span>\n      </div>\n\n      <div className=\"flex flex-wrap items-center gap-1.5 rounded-xl border border-neutral-200 bg-neutral-50/70 p-2 focus-within:border-black dark:border-[#262626] dark:bg-[#121212] dark:focus-within:border-white\">\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          {tags.map((tag, idx) => {\n            const isWarned =\n              pendingDeleteLast && idx === tags.length - 1;\n\n            return (\n              <motion.span\n                key={tag}\n                layout\n                initial={\n                  shouldReduceMotion\n                    ? { opacity: 1 }\n                    : { scale: 0.6, opacity: 0 }\n                }\n                animate={{\n                  scale: 1,\n                  opacity: 1,\n                  x:\n                    isWarned && !shouldReduceMotion\n                      ? [0, -4, 4, -3, 3, 0]\n                      : 0,\n                }}\n                exit={\n                  shouldReduceMotion\n                    ? { opacity: 0 }\n                    : { scale: 0.6, opacity: 0 }\n                }\n                transition={{ type: \"spring\", stiffness, damping }}\n                className={cn(\n                  \"inline-flex items-center gap-1 rounded-lg border px-2.5 py-1 font-mono text-xs font-medium transition-colors\",\n                  isWarned\n                    ? \"border-black bg-black text-white dark:border-white dark:bg-white dark:text-black\"\n                    : \"border-neutral-200 bg-white text-black dark:border-[#2A2A2A] dark:bg-[#1B1B1B] dark:text-white\"\n                )}\n              >\n                <span>#{tag}</span>\n                <button\n                  type=\"button\"\n                  aria-label={`Remove tag ${tag}`}\n                  onClick={() => removeTag(tag)}\n                  className=\"rounded p-0.5 opacity-60 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-current\"\n                >\n                  <X className=\"h-3 w-3\" />\n                </button>\n              </motion.span>\n            );\n          })}\n        </AnimatePresence>\n\n        <div className=\"flex min-w-[140px] flex-1 items-center gap-1\">\n          <input\n            type=\"text\"\n            value={inputValue}\n            disabled={tags.length >= maxTags}\n            placeholder={\n              tags.length >= maxTags ? \"Max tags reached\" : placeholder\n            }\n            aria-label=\"Add keyword tag\"\n            onChange={(e) => {\n              setInputValue(e.target.value);\n              setPendingDeleteLast(false);\n            }}\n            onKeyDown={handleKeyDown}\n            className=\"w-full bg-transparent px-1.5 py-1 text-xs text-black placeholder:text-neutral-400 focus:outline-none dark:text-white\"\n          />\n          {inputValue.trim() && (\n            <button\n              type=\"button\"\n              aria-label=\"Add current tag\"\n              onClick={() => addTag(inputValue)}\n              className=\"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-black text-white dark:bg-white dark:text-black\"\n            >\n              <Plus className=\"h-3 w-3\" />\n            </button>\n          )}\n        </div>\n      </div>\n\n      <div className=\"mt-2 text-[10px] text-neutral-400\">\n        Press Enter to add • Press Backspace twice to confirm removal\n      </div>\n    </div>\n  );\n}\n\nexport default ElasticTagInput;\n",
      "type": "registry:ui",
      "target": "components/ui/elastic-tag-input.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"
    }
  ]
}
