{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "morphing-action-button",
  "type": "registry:ui",
  "title": "Morphing Action Button",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Multi-phase stateful pill button that morphs its bounding width across Idle, Compiling, and Published states using spring layout projection.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/morphing-action-button.tsx",
      "content": "\"use client\";\n\nimport React, { useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport { ArrowRight, Check, Loader2, AlertTriangle } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ActionPhase = \"idle\" | \"loading\" | \"success\" | \"error\";\n\nexport interface MorphingActionButtonProps {\n  /** Label shown in resting idle phase. Default: \"Publish Registry\" */\n  idleLabel?: string;\n  /** Label shown during async loading phase. Default: \"Compiling...\" */\n  loadingLabel?: string;\n  /** Label shown upon completion. Default: \"Published v2.4\" */\n  successLabel?: string;\n  /** Simulate an error state on every second click for demo purposes. Default: false */\n  simulateError?: boolean;\n  /** Hooke's Law spring stiffness coefficient for pill width morphing. Default: 380 */\n  stiffness?: number;\n  /** Spring damping coefficient for pill width morphing. Default: 26 */\n  damping?: number;\n  className?: string;\n}\n\nexport function MorphingActionButton({\n  idleLabel = \"Publish Registry\",\n  loadingLabel = \"Compiling...\",\n  successLabel = \"Published v2.4\",\n  simulateError = false,\n  stiffness = 380,\n  damping = 26,\n  className,\n}: MorphingActionButtonProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const [phase, setPhase] = useState<ActionPhase>(\"idle\");\n  const [runCount, setRunCount] = useState(0);\n\n  const handleTrigger = () => {\n    if (phase === \"loading\") return;\n    if (phase !== \"idle\") {\n      setPhase(\"idle\");\n      return;\n    }\n\n    setPhase(\"loading\");\n    const nextRun = runCount + 1;\n    setRunCount(nextRun);\n\n    setTimeout(() => {\n      if (simulateError && nextRun % 2 === 0) {\n        setPhase(\"error\");\n      } else {\n        setPhase(\"success\");\n      }\n      setTimeout(() => {\n        setPhase(\"idle\");\n      }, 1800);\n    }, 950);\n  };\n\n  return (\n    <motion.button\n      layout\n      type=\"button\"\n      aria-live=\"polite\"\n      onClick={handleTrigger}\n      animate={\n        phase === \"error\" && !shouldReduceMotion\n          ? { x: [0, -7, 7, -4, 4, 0] }\n          : { x: 0 }\n      }\n      transition={\n        shouldReduceMotion\n          ? { duration: 0.01 }\n          : { type: \"spring\", stiffness, damping }\n      }\n      className={cn(\n        \"relative inline-flex h-12 items-center justify-center overflow-hidden rounded-full border px-6 text-xs font-semibold shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black focus-visible:ring-offset-2 dark:focus-visible:ring-white\",\n        phase === \"idle\" &&\n          \"border-black bg-black text-white hover:opacity-90 dark:border-white dark:bg-white dark:text-black\",\n        phase === \"loading\" &&\n          \"border-neutral-300 bg-neutral-100 text-neutral-700 dark:border-[#262626] dark:bg-[#141414] dark:text-neutral-300\",\n        phase === \"success\" &&\n          \"border-black bg-white text-black dark:border-white dark:bg-[#0D0D0D] dark:text-white\",\n        phase === \"error\" &&\n          \"border-neutral-800 bg-neutral-900 text-white dark:border-neutral-300 dark:bg-neutral-200 dark:text-black\",\n        className\n      )}\n    >\n      <AnimatePresence mode=\"popLayout\" initial={false}>\n        {phase === \"idle\" && (\n          <motion.span\n            key=\"idle\"\n            initial={{ opacity: 0, y: 10 }}\n            animate={{ opacity: 1, y: 0 }}\n            exit={{ opacity: 0, y: -10 }}\n            transition={{ duration: 0.15 }}\n            className=\"inline-flex items-center gap-2 whitespace-nowrap\"\n          >\n            <span>{idleLabel}</span>\n            <ArrowRight className=\"h-3.5 w-3.5\" />\n          </motion.span>\n        )}\n\n        {phase === \"loading\" && (\n          <motion.span\n            key=\"loading\"\n            initial={{ opacity: 0, y: 10 }}\n            animate={{ opacity: 1, y: 0 }}\n            exit={{ opacity: 0, y: -10 }}\n            transition={{ duration: 0.15 }}\n            className=\"inline-flex items-center gap-2 whitespace-nowrap\"\n          >\n            <Loader2 className=\"h-3.5 w-3.5 animate-spin\" />\n            <span>{loadingLabel}</span>\n          </motion.span>\n        )}\n\n        {phase === \"success\" && (\n          <motion.span\n            key=\"success\"\n            initial={{ opacity: 0, scale: 0.85 }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0, scale: 0.85 }}\n            transition={{ type: \"spring\", stiffness: 420, damping: 22 }}\n            className=\"inline-flex items-center gap-2 whitespace-nowrap\"\n          >\n            <Check className=\"h-4 w-4\" />\n            <span>{successLabel}</span>\n          </motion.span>\n        )}\n\n        {phase === \"error\" && (\n          <motion.span\n            key=\"error\"\n            initial={{ opacity: 0, scale: 0.85 }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0, scale: 0.85 }}\n            transition={{ duration: 0.15 }}\n            className=\"inline-flex items-center gap-2 whitespace-nowrap\"\n          >\n            <AlertTriangle className=\"h-3.5 w-3.5\" />\n            <span>Build Failed • Retry</span>\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </motion.button>\n  );\n}\n\nexport default MorphingActionButton;\n",
      "type": "registry:ui",
      "target": "components/ui/morphing-action-button.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"
    }
  ]
}
