{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slide-button",
  "title": "Slide Button",
  "description": "Slide to confirm: drag the knob to the end so the action can't happen by accident.",
  "files": [
    {
      "path": "registry/ombak/slide-button/slide-button.tsx",
      "content": "\"use client\";\n\nimport { useRef, useState, type KeyboardEvent, type PointerEvent, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type SlideButtonProps = {\n  /** Text on the track. Default \"Slide to confirm\" */\n  label?: ReactNode;\n  /** Text after confirming. Default \"Confirmed\" */\n  doneLabel?: ReactNode;\n  /** Called when the knob reaches the end. */\n  onConfirm?: () => void;\n  /** How far (0–1) the knob must travel to confirm. Default 0.9 */\n  threshold?: number;\n  /** Milliseconds before resetting after confirming. 0 keeps it done. Default 2000 */\n  resetAfter?: number;\n  className?: string;\n};\n\n/**\n * \"Slide to confirm\": drag the knob to the end of the track to trigger the action, so it can't\n * happen by accident. Keyboard users press Enter or the right arrow on the knob.\n */\nexport function SlideButton({\n  label = \"Slide to confirm\",\n  doneLabel = \"Confirmed\",\n  onConfirm,\n  threshold = 0.9,\n  resetAfter = 2000,\n  className,\n}: SlideButtonProps) {\n  const trackRef = useRef<HTMLDivElement>(null);\n  const knobRef = useRef<HTMLButtonElement>(null);\n  const [x, setX] = useState(0);\n  const [dragging, setDragging] = useState(false);\n  const [done, setDone] = useState(false);\n  const startX = useRef(0);\n\n  const max = () => (trackRef.current && knobRef.current ? trackRef.current.clientWidth - knobRef.current.offsetWidth - 8 : 1);\n\n  const confirm = () => {\n    setX(max());\n    setDone(true);\n    onConfirm?.();\n    if (resetAfter) {\n      window.setTimeout(() => {\n        setDone(false);\n        setX(0);\n      }, resetAfter);\n    }\n  };\n\n  const onDown = (e: PointerEvent<HTMLButtonElement>) => {\n    if (done) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    startX.current = e.clientX - x;\n    setDragging(true);\n  };\n  const onMove = (e: PointerEvent<HTMLButtonElement>) => {\n    if (!dragging) return;\n    setX(Math.max(0, Math.min(max(), e.clientX - startX.current)));\n  };\n  const onUp = () => {\n    if (!dragging) return;\n    setDragging(false);\n    if (x / max() >= threshold) confirm();\n    else setX(0);\n  };\n  const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {\n    if (done) return;\n    if (e.key === \"Enter\" || e.key === \"ArrowRight\" || e.key === \"End\") {\n      e.preventDefault();\n      confirm();\n    }\n  };\n\n  const progress = x / max();\n\n  return (\n    <div\n      ref={trackRef}\n      className={cn(\"relative h-14 w-72 overflow-hidden rounded-full border bg-muted/60 p-1 select-none touch-none\", className)}\n    >\n      {/* fill behind the knob */}\n      <div\n        aria-hidden\n        className=\"absolute inset-y-0 left-0 rounded-full bg-emerald-500/25\"\n        style={{ width: `calc(${x}px + 3.5rem)`, transition: dragging ? \"none\" : \"width 350ms cubic-bezier(.2,.8,.2,1)\" }}\n      />\n      <span\n        className=\"pointer-events-none absolute inset-0 grid place-items-center pl-10 text-sm font-medium text-muted-foreground\"\n        style={{ opacity: done ? 1 : 1 - progress * 1.4 }}\n      >\n        {done ? doneLabel : label}\n      </span>\n      <button\n        ref={knobRef}\n        type=\"button\"\n        aria-label={typeof label === \"string\" ? label : \"Slide to confirm\"}\n        onPointerDown={onDown}\n        onPointerMove={onMove}\n        onPointerUp={onUp}\n        onPointerCancel={onUp}\n        onKeyDown={onKey}\n        className={cn(\n          \"relative z-10 grid size-12 cursor-grab place-items-center rounded-full bg-primary text-primary-foreground shadow-md outline-none focus-visible:ring-4 focus-visible:ring-ring/50 active:cursor-grabbing\",\n          done && \"bg-emerald-500 text-white\",\n        )}\n        style={{ transform: `translateX(${x}px)`, transition: dragging ? \"none\" : \"transform 350ms cubic-bezier(.2,.8,.2,1), background-color 200ms\" }}\n      >\n        {done ? (\n          <svg viewBox=\"0 0 24 24\" className=\"size-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M5 12.5l4.5 4.5L19 7\" /></svg>\n        ) : (\n          <svg viewBox=\"0 0 24 24\" className=\"size-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M5 12h14M13 6l6 6-6 6\" /></svg>\n        )}\n      </button>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "buttons"
  ],
  "type": "registry:component"
}