{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-swipe-confirm",
  "type": "registry:component",
  "title": "Button Swipe Confirm",
  "description": "A slide-to-pay track: drag the knob with rubber-band resistance at both ends, and past the threshold it locks, spins and draws a check. Short drags spring back with an overshoot.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "swipe",
    "slide to confirm",
    "payment",
    "drag",
    "stateful"
  ],
  "docs": "https://hyperblur.dev/effects/button-swipe-confirm",
  "files": [
    {
      "path": "registry/hyperblur/button-swipe-confirm.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-swipe-confirm.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ButtonSwipeConfirmStatus = \"idle\" | \"pending\" | \"done\";\n\nexport interface ButtonSwipeConfirmProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  label?: string;\n  pendingLabel?: string;\n  doneLabel?: string;\n  onConfirm?: () => unknown;\n  threshold?: number;\n  pendingDuration?: number;\n  resetAfter?: number;\n  accent?: string;\n  disabled?: boolean;\n}\n\nconst css = `\n.hb-xb1 {\n  --hb-xb1-c: #2f7bff;\n  --hb-xb1-h: 56px;\n  --hb-xb1-k: 46px;\n  --hb-xb1-p: 0;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  max-width: 340px;\n  height: var(--hb-xb1-h);\n  padding: 5px;\n  border-radius: 999px;\n  font-family: inherit;\n  color: #ededed;\n  background: linear-gradient(180deg, #121212 0%, #181818 100%);\n  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6), inset 0 0 0 1px #262626, 0 1px 0 rgba(255, 255, 255, 0.04);\n  user-select: none;\n  -webkit-user-select: none;\n  touch-action: pan-y;\n  overflow: hidden;\n  isolation: isolate;\n}\n.hb-xb1 *, .hb-xb1 *::before, .hb-xb1 *::after { box-sizing: border-box; }\n.hb-xb1-fill {\n  position: absolute;\n  top: 5px;\n  bottom: 5px;\n  left: 5px;\n  width: calc(var(--hb-xb1-k) + var(--hb-xb1-x, 0px));\n  border-radius: 999px;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-xb1-c) 10%, transparent), color-mix(in srgb, var(--hb-xb1-c) 42%, transparent));\n  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-xb1-c) 35%, transparent);\n  z-index: 0;\n}\n.hb-xb1[data-drag=\"false\"] .hb-xb1-fill { transition: width 0.55s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.4s ease; }\n.hb-xb1[data-status=\"done\"] .hb-xb1-fill {\n  width: calc(100% - 10px);\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-xb1-c) 70%, #000), var(--hb-xb1-c));\n  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1), background 0.4s ease;\n}\n.hb-xb1-label {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 10px;\n  padding-left: calc(var(--hb-xb1-k) + 14px);\n  padding-right: 18px;\n  font-size: 14px;\n  font-weight: 560;\n  letter-spacing: -0.005em;\n  white-space: nowrap;\n  opacity: calc(1 - var(--hb-xb1-p) * 1.6);\n  transform: translateX(calc(var(--hb-xb1-p) * 18px));\n  z-index: 1;\n  pointer-events: none;\n}\n.hb-xb1-text {\n  background: linear-gradient(100deg, #6f6f6f 0%, #6f6f6f 38%, #f5f5f5 50%, #6f6f6f 62%, #6f6f6f 100%);\n  background-size: 260% 100%;\n  -webkit-background-clip: text;\n  background-clip: text;\n  color: transparent;\n  animation: hb-xb1-shine 2.6s cubic-bezier(0.45, 0, 0.55, 1) infinite;\n}\n.hb-xb1-chev { display: inline-flex; gap: 1px; }\n.hb-xb1-chev svg { width: 9px; height: 12px; fill: none; stroke: #8f8f8f; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; animation: hb-xb1-chev 1.6s ease-in-out infinite; }\n.hb-xb1-chev svg:nth-child(2) { animation-delay: 0.14s; }\n.hb-xb1-chev svg:nth-child(3) { animation-delay: 0.28s; }\n.hb-xb1-state {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  font-size: 14px;\n  font-weight: 600;\n  color: #fff;\n  opacity: 0;\n  transform: translateY(6px);\n  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);\n  z-index: 1;\n  pointer-events: none;\n  white-space: nowrap;\n}\n.hb-xb1[data-status=\"pending\"] .hb-xb1-state[data-for=\"pending\"],\n.hb-xb1[data-status=\"done\"] .hb-xb1-state[data-for=\"done\"] { opacity: 1; transform: none; }\n.hb-xb1[data-status=\"pending\"] .hb-xb1-state[data-for=\"pending\"] { color: #d4d4d4; padding-right: calc(var(--hb-xb1-k) + 8px); }\n.hb-xb1-knob {\n  position: absolute;\n  top: 5px;\n  left: 5px;\n  width: var(--hb-xb1-k);\n  height: var(--hb-xb1-k);\n  display: grid;\n  place-items: center;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 999px;\n  color: #0a0a0a;\n  background: radial-gradient(120% 120% at 30% 20%, #ffffff 0%, #e9e9e9 55%, #cfcfcf 100%);\n  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 6px 14px -4px rgba(0, 0, 0, 0.7), 0 2px 4px rgba(0, 0, 0, 0.5);\n  transform: translateX(var(--hb-xb1-x, 0px));\n  cursor: grab;\n  z-index: 2;\n  font: inherit;\n  touch-action: none;\n}\n.hb-xb1[data-drag=\"true\"] .hb-xb1-knob { cursor: grabbing; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 10px 22px -6px rgba(0, 0, 0, 0.8), 0 0 0 6px color-mix(in srgb, var(--hb-xb1-c) 18%, transparent); }\n.hb-xb1[data-drag=\"false\"] .hb-xb1-knob { transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease, background 0.3s ease, color 0.3s ease; }\n.hb-xb1[data-status=\"done\"] .hb-xb1-knob { color: var(--hb-xb1-c); cursor: default; }\n.hb-xb1-knob:focus-visible { outline: 2px solid var(--hb-xb1-c); outline-offset: 3px; }\n.hb-xb1-ico { position: absolute; display: grid; place-items: center; transition: opacity 0.25s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xb1-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-xb1-ico[data-i=\"spin\"], .hb-xb1-ico[data-i=\"check\"] { opacity: 0; transform: scale(0.4); }\n.hb-xb1[data-status=\"pending\"] .hb-xb1-ico[data-i=\"arrow\"], .hb-xb1[data-status=\"done\"] .hb-xb1-ico[data-i=\"arrow\"] { opacity: 0; transform: scale(0.4) rotate(-40deg); }\n.hb-xb1[data-status=\"pending\"] .hb-xb1-ico[data-i=\"spin\"] { opacity: 1; transform: none; }\n.hb-xb1[data-status=\"done\"] .hb-xb1-ico[data-i=\"check\"] { opacity: 1; transform: none; }\n.hb-xb1-ico[data-i=\"spin\"] svg { animation: hb-xb1-spin 0.8s linear infinite; stroke-width: 2.4; }\n.hb-xb1-ico[data-i=\"check\"] path { stroke-dasharray: 22; stroke-dashoffset: 22; }\n.hb-xb1[data-status=\"done\"] .hb-xb1-ico[data-i=\"check\"] path { animation: hb-xb1-draw 0.42s cubic-bezier(0.65, 0, 0.35, 1) 0.1s forwards; }\n.hb-xb1[data-disabled=\"true\"] { opacity: 0.45; }\n.hb-xb1[data-disabled=\"true\"] .hb-xb1-knob { cursor: not-allowed; }\n@keyframes hb-xb1-shine { 0% { background-position: 100% 0; } 100% { background-position: 0% 0; } }\n@keyframes hb-xb1-chev { 0%, 100% { opacity: 0.25; transform: translateX(0); } 50% { opacity: 1; transform: translateX(2px); } }\n@keyframes hb-xb1-spin { to { transform: rotate(360deg); } }\n@keyframes hb-xb1-draw { to { stroke-dashoffset: 0; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xb1-text, .hb-xb1-chev svg { animation: none; }\n  .hb-xb1-text { color: #a1a1a1; background: none; }\n  .hb-xb1 *, .hb-xb1-fill { transition-duration: 0.01s !important; }\n  .hb-xb1-ico[data-i=\"spin\"] svg { animation-duration: 1.6s; }\n  .hb-xb1[data-status=\"done\"] .hb-xb1-ico[data-i=\"check\"] path { animation: none; stroke-dashoffset: 0; }\n}\n`;\n\nconst chevron = (\n  <svg viewBox=\"0 0 9 12\" aria-hidden=\"true\">\n    <path d=\"M2 2l4 4-4 4\" />\n  </svg>\n);\n\nexport function ButtonSwipeConfirm({\n  label = \"Slide to pay $48.00\",\n  pendingLabel = \"Processing\",\n  doneLabel = \"Payment sent\",\n  onConfirm,\n  threshold = 0.88,\n  pendingDuration = 1100,\n  resetAfter = 0,\n  accent = \"#2f7bff\",\n  disabled = false,\n  className = \"\",\n  style,\n  ...rest\n}: ButtonSwipeConfirmProps) {\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const start = React.useRef<{ x: number; base: number; max: number } | null>(null);\n  const timers = React.useRef<number[]>([]);\n  const [x, setX] = React.useState(0);\n  const [max, setMax] = React.useState(1);\n  const [dragging, setDragging] = React.useState(false);\n  const [status, setStatus] = React.useState<ButtonSwipeConfirmStatus>(\"idle\");\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => list.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  const measure = () => {\n    const el = trackRef.current;\n    if (!el) return 1;\n    const m = Math.max(1, el.clientWidth - 10 - 46);\n    setMax(m);\n    return m;\n  };\n\n  const commit = (m: number) => {\n    setX(m);\n    setStatus(\"pending\");\n    timers.current.push(\n      window.setTimeout(() => {\n        setStatus(\"done\");\n        onConfirm?.();\n        if (resetAfter > 0) {\n          timers.current.push(\n            window.setTimeout(() => {\n              setStatus(\"idle\");\n              setX(0);\n            }, resetAfter),\n          );\n        }\n      }, pendingDuration),\n    );\n  };\n\n  const locked = disabled || status !== \"idle\";\n\n  const onPointerDown = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (locked) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    start.current = { x: e.clientX, base: x, max: measure() };\n    setDragging(true);\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLButtonElement>) => {\n    const s = start.current;\n    if (!s) return;\n    let next = s.base + e.clientX - s.x;\n    if (next < 0) next = next * 0.18;\n    if (next > s.max) next = s.max + (next - s.max) * 0.18;\n    setX(next);\n  };\n\n  const onPointerUp = () => {\n    const s = start.current;\n    if (!s) return;\n    start.current = null;\n    setDragging(false);\n    if (x / s.max >= threshold) commit(s.max);\n    else setX(0);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {\n    if (locked) return;\n    const m = measure();\n    if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      commit(m);\n    } else if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      const next = Math.min(m, x + m * 0.2);\n      if (next / m >= threshold) commit(m);\n      else setX(next);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"Home\") {\n      e.preventDefault();\n      setX(e.key === \"Home\" ? 0 : Math.max(0, x - m * 0.2));\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      commit(m);\n    }\n  };\n\n  const p = Math.max(0, Math.min(1, x / max));\n  const vars = {\n    \"--hb-xb1-c\": accent,\n    \"--hb-xb1-x\": `${x.toFixed(1)}px`,\n    \"--hb-xb1-p\": p.toFixed(3),\n  } as React.CSSProperties;\n\n  return (\n    <div\n      ref={trackRef}\n      className={`hb-xb1 ${className}`.trim()}\n      data-drag={dragging ? \"true\" : \"false\"}\n      data-status={status}\n      data-disabled={disabled ? \"true\" : \"false\"}\n      style={{ ...vars, ...style }}\n      {...rest}\n    >\n      <style href=\"hb-button-swipe-confirm\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xb1-fill\" aria-hidden=\"true\" />\n      <div className=\"hb-xb1-label\" aria-hidden=\"true\">\n        <span className=\"hb-xb1-text\">{label}</span>\n        <span className=\"hb-xb1-chev\">\n          {chevron}\n          {chevron}\n          {chevron}\n        </span>\n      </div>\n      <div className=\"hb-xb1-state\" data-for=\"pending\" aria-hidden=\"true\">{pendingLabel}</div>\n      <div className=\"hb-xb1-state\" data-for=\"done\" aria-hidden=\"true\">{doneLabel}</div>\n      <button\n        type=\"button\"\n        role=\"slider\"\n        className=\"hb-xb1-knob\"\n        aria-label={label}\n        aria-valuemin={0}\n        aria-valuemax={100}\n        aria-valuenow={Math.round(p * 100)}\n        aria-valuetext={status === \"done\" ? doneLabel : status === \"pending\" ? pendingLabel : `${Math.round(p * 100)}%`}\n        aria-disabled={locked || undefined}\n        disabled={disabled}\n        onPointerDown={onPointerDown}\n        onPointerMove={onPointerMove}\n        onPointerUp={onPointerUp}\n        onPointerCancel={onPointerUp}\n        onKeyDown={onKeyDown}\n      >\n        <span className=\"hb-xb1-ico\" data-i=\"arrow\">\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M5 12h13M13 6l6 6-6 6\" />\n          </svg>\n        </span>\n        <span className=\"hb-xb1-ico\" data-i=\"spin\">\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M12 3a9 9 0 1 0 9 9\" />\n          </svg>\n        </span>\n        <span className=\"hb-xb1-ico\" data-i=\"check\">\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n          </svg>\n        </span>\n      </button>\n      <span role=\"status\" aria-live=\"polite\" style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clip: \"rect(0 0 0 0)\" }}>\n        {status === \"done\" ? doneLabel : status === \"pending\" ? pendingLabel : \"\"}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}