{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hold-button",
  "type": "registry:component",
  "title": "Hold Button",
  "description": "Press and hold to confirm. A fill sweeps across while held, letting go early snaps it back.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "button",
    "hold",
    "confirm",
    "press",
    "destructive"
  ],
  "docs": "https://hyperblur.dev/effects/hold-button",
  "files": [
    {
      "path": "registry/hyperblur/hold-button.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hold-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoldButtonProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"color\"> {\n  children: React.ReactNode;\n  onConfirm: () => void;\n  duration?: number;\n  color?: string;\n  confirmedLabel?: string;\n  disabled?: boolean;\n}\n\nconst css = `\n.hb-hold {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  overflow: hidden;\n  isolation: isolate;\n  margin: 0;\n  padding: 0.75em 1.6em;\n  font: inherit;\n  font-weight: 600;\n  line-height: 1.2;\n  color: #fff;\n  background: rgba(255, 255, 255, 0.06);\n  border: 1px solid rgba(255, 255, 255, 0.16);\n  border-radius: 999px;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-touch-callout: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: none;\n  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.2s ease;\n}\n.hb-hold:focus-visible { outline: 2px solid var(--hb-c); outline-offset: 3px; }\n.hb-hold:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-hold:not(:disabled):active { transform: scale(0.97); }\n.hb-hold-f {\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  background: color-mix(in srgb, var(--hb-c) 78%, transparent);\n  transform: scaleX(var(--hb-p, 0));\n  transform-origin: left center;\n  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-hold[data-holding=\"true\"] .hb-hold-f { transition: none; }\n.hb-hold-l { display: grid; place-items: center; }\n.hb-hold-a, .hb-hold-b { grid-area: 1 / 1; white-space: nowrap; }\n.hb-hold-b { visibility: hidden; }\n.hb-hold[data-done=\"true\"] { border-color: var(--hb-c); animation: hb-hold-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-hold[data-done=\"true\"] .hb-hold-a { visibility: hidden; }\n.hb-hold[data-done=\"true\"] .hb-hold-b { visibility: visible; }\n.hb-hold-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n@keyframes hb-hold-pop {\n  0% { transform: scale(1); }\n  40% { transform: scale(1.06); }\n  100% { transform: scale(1); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-hold, .hb-hold-f { transition: none; }\n  .hb-hold[data-done=\"true\"] { animation: none; }\n  .hb-hold:not(:disabled):active { transform: none; }\n}\n`;\n\nexport function HoldButton({\n  children,\n  onConfirm,\n  duration = 1200,\n  color = \"#2f7bff\",\n  confirmedLabel = \"Done\",\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  onPointerDown,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  onKeyDown,\n  onKeyUp,\n  onBlur,\n  onContextMenu,\n  \"aria-describedby\": describedBy,\n  ...rest\n}: HoldButtonProps) {\n  const ref = React.useRef<HTMLButtonElement>(null);\n  const raf = React.useRef(0);\n  const timer = React.useRef(0);\n  const holding = React.useRef(false);\n  const latest = React.useRef(onConfirm);\n  const hintId = React.useId();\n  const [done, setDone] = React.useState(false);\n\n  React.useEffect(() => {\n    latest.current = onConfirm;\n  }, [onConfirm]);\n\n  React.useEffect(() => {\n    return () => {\n      cancelAnimationFrame(raf.current);\n      window.clearTimeout(timer.current);\n    };\n  }, []);\n\n  React.useEffect(() => {\n    if (!disabled) return;\n    holding.current = false;\n    cancelAnimationFrame(raf.current);\n    const el = ref.current;\n    if (!el) return;\n    el.dataset.holding = \"false\";\n    el.style.setProperty(\"--hb-p\", \"0\");\n  }, [disabled]);\n\n  function finish() {\n    holding.current = false;\n    const el = ref.current;\n    if (el) {\n      el.dataset.holding = \"false\";\n      el.style.setProperty(\"--hb-p\", \"1\");\n    }\n    setDone(true);\n    latest.current();\n    timer.current = window.setTimeout(() => {\n      setDone(false);\n      ref.current?.style.setProperty(\"--hb-p\", \"0\");\n    }, 1400);\n  }\n\n  function start() {\n    const el = ref.current;\n    if (!el || disabled || done || holding.current) return;\n    holding.current = true;\n    el.dataset.holding = \"true\";\n    const t0 = performance.now();\n    const total = Math.max(1, duration);\n    function tick(now: number) {\n      if (!holding.current || !el) return;\n      const p = Math.min(1, Math.max(0, (now - t0) / total));\n      el.style.setProperty(\"--hb-p\", p.toFixed(4));\n      if (p >= 1) return finish();\n      raf.current = requestAnimationFrame(tick);\n    }\n    raf.current = requestAnimationFrame(tick);\n  }\n\n  function stop() {\n    if (!holding.current) return;\n    holding.current = false;\n    cancelAnimationFrame(raf.current);\n    const el = ref.current;\n    if (!el) return;\n    el.dataset.holding = \"false\";\n    el.style.setProperty(\"--hb-p\", \"0\");\n  }\n\n  const vars = { \"--hb-c\": color, ...style } as React.CSSProperties;\n  const describedIds = describedBy ? `${describedBy} ${hintId}` : hintId;\n\n  return (\n    <>\n      <style href=\"hb-hold-button\" precedence=\"default\">{css}</style>\n      <button\n        ref={ref}\n        type={type}\n        className={`hb-hold ${className}`}\n        style={vars}\n        disabled={disabled}\n        data-done={done}\n        aria-describedby={describedIds}\n        onPointerDown={(e) => {\n          onPointerDown?.(e);\n          if (e.button === 0) start();\n        }}\n        onPointerUp={(e) => {\n          onPointerUp?.(e);\n          stop();\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          stop();\n        }}\n        onPointerCancel={(e) => {\n          onPointerCancel?.(e);\n          stop();\n        }}\n        onKeyDown={(e) => {\n          onKeyDown?.(e);\n          if (e.key !== \" \" && e.key !== \"Enter\") return;\n          e.preventDefault();\n          if (!e.repeat) start();\n        }}\n        onKeyUp={(e) => {\n          onKeyUp?.(e);\n          if (e.key !== \" \" && e.key !== \"Enter\") return;\n          e.preventDefault();\n          stop();\n        }}\n        onBlur={(e) => {\n          onBlur?.(e);\n          stop();\n        }}\n        onContextMenu={(e) => {\n          onContextMenu?.(e);\n          e.preventDefault();\n        }}\n        {...rest}\n      >\n        <span className=\"hb-hold-f\" aria-hidden=\"true\" />\n        <span className=\"hb-hold-l\">\n          <span className=\"hb-hold-a\">{children}</span>\n          <span className=\"hb-hold-b\">{confirmedLabel}</span>\n        </span>\n      </button>\n      <span id={hintId} className=\"hb-hold-sr\">\n        Press and hold to confirm\n      </span>\n      <span className=\"hb-hold-sr\" role=\"status\" aria-live=\"polite\">\n        {done ? confirmedLabel : \"\"}\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}