{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kinetic-swipe-button",
  "type": "registry:ui",
  "title": "Kinetic Swipe Button",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Slide-to-execute actuator switch with a spring-tethered thumb that locks upon crossing the completion threshold or recoils elastically.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/kinetic-swipe-button.tsx",
      "content": "\"use client\";\n\nimport React, { useRef, useState } from \"react\";\nimport {\n  motion,\n  useMotionValue,\n  useSpring,\n  useTransform,\n  useReducedMotion,\n} from \"framer-motion\";\nimport { ArrowRight, Check, RotateCcw } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface KineticSwipeButtonProps {\n  /** Track instruction text before completion. Default: \"Slide to Deploy Production\" */\n  label?: string;\n  /** Text displayed when locked at the right end. Default: \"Deployment Triggered\" */\n  completedLabel?: string;\n  /** Completion threshold ratio (0.5 to 0.95). Default: 0.78 */\n  threshold?: number;\n  /** Spring stiffness coefficient for thumb snap-back. Default: 360 */\n  stiffness?: number;\n  /** Spring damping coefficient for thumb snap-back. Default: 26 */\n  damping?: number;\n  /** Callback fired when swipe crosses completion threshold */\n  onComplete?: () => void;\n  className?: string;\n}\n\nexport function KineticSwipeButton({\n  label = \"Slide to Deploy Production\",\n  completedLabel = \"Deployment Triggered\",\n  threshold = 0.78,\n  stiffness = 360,\n  damping = 26,\n  onComplete,\n  className,\n}: KineticSwipeButtonProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const trackRef = useRef<HTMLDivElement | null>(null);\n  const [isDragging, setIsDragging] = useState(false);\n  const [isCompleted, setIsCompleted] = useState(false);\n  const startXRef = useRef<number>(0);\n\n  const dragX = useMotionValue(0);\n  const springX = useSpring(dragX, { stiffness, damping, mass: 0.4 });\n  const textOpacity = useTransform(springX, [0, 140], [1, 0]);\n\n  const getMaxTravel = () => {\n    const track = trackRef.current;\n    if (!track) return 220;\n    return Math.max(0, track.clientWidth - 52);\n  };\n\n  const handlePointerDown = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (isCompleted) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    setIsDragging(true);\n    startXRef.current = e.clientX - dragX.get();\n  };\n\n  const handlePointerMove = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (!isDragging || isCompleted) return;\n    const maxTravel = getMaxTravel();\n    const nextX = Math.max(0, Math.min(maxTravel, e.clientX - startXRef.current));\n    dragX.set(nextX);\n  };\n\n  const handlePointerUp = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (!isDragging) return;\n    if (e.currentTarget.hasPointerCapture(e.pointerId)) {\n      e.currentTarget.releasePointerCapture(e.pointerId);\n    }\n    setIsDragging(false);\n\n    const maxTravel = getMaxTravel();\n    if (dragX.get() >= maxTravel * threshold) {\n      dragX.set(maxTravel);\n      setIsCompleted(true);\n      onComplete?.();\n    } else {\n      dragX.set(0);\n    }\n  };\n\n  const resetSwipe = () => {\n    setIsCompleted(false);\n    dragX.set(0);\n  };\n\n  return (\n    <div\n      ref={trackRef}\n      className={cn(\n        \"relative flex h-14 w-full max-w-xs select-none items-center overflow-hidden rounded-2xl border border-neutral-200 bg-neutral-100 p-1.5 dark:border-[#222222] dark:bg-[#0D0D0D]\",\n        className\n      )}\n    >\n      {/* Center Track Label */}\n      {!isCompleted ? (\n        <motion.span\n          style={{ opacity: shouldReduceMotion ? 1 : textOpacity }}\n          className=\"pointer-events-none mx-auto pl-8 text-xs font-semibold tracking-tight text-neutral-500 dark:text-neutral-400\"\n        >\n          {label}\n        </motion.span>\n      ) : (\n        <button\n          type=\"button\"\n          onClick={resetSwipe}\n          className=\"mx-auto inline-flex items-center gap-1.5 text-xs font-semibold text-black dark:text-white\"\n        >\n          <Check className=\"h-4 w-4\" />\n          <span>{completedLabel}</span>\n          <RotateCcw className=\"ml-1 h-3 w-3 text-neutral-400\" />\n        </button>\n      )}\n\n      {/* Draggable Magnetic Actuator Thumb */}\n      {!isCompleted && (\n        <motion.button\n          type=\"button\"\n          aria-label={label}\n          onPointerDown={handlePointerDown}\n          onPointerMove={handlePointerMove}\n          onPointerUp={handlePointerUp}\n          onPointerCancel={handlePointerUp}\n          onKeyDown={(e) => {\n            if (e.key === \"Enter\" || e.key === \" \") {\n              e.preventDefault();\n              dragX.set(getMaxTravel());\n              setIsCompleted(true);\n              onComplete?.();\n            }\n          }}\n          style={{ x: shouldReduceMotion ? 0 : springX }}\n          className=\"absolute left-1.5 flex h-11 w-11 cursor-grab touch-none items-center justify-center rounded-xl bg-black text-white shadow-sm active:cursor-grabbing focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:bg-white dark:text-black dark:focus-visible:ring-white\"\n        >\n          <ArrowRight className=\"h-4 w-4\" />\n        </motion.button>\n      )}\n    </div>\n  );\n}\n\nexport default KineticSwipeButton;\n",
      "type": "registry:ui",
      "target": "components/ui/kinetic-swipe-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"
    }
  ]
}
