{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hold-to-confirm",
  "type": "registry:component",
  "title": "Hold to Confirm",
  "description": "Press and hold to confirm: a ring fills, the button shakes more and more, and it vibrates on completion. Works with mouse, touch or keyboard.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Buttons"
  ],
  "docs": "Installed in components/furin/hold-to-confirm/. Docs, live controls and props table: https://furin.dev/components/hold-to-confirm/",
  "files": [
    {
      "path": "registry/hold-to-confirm/HoldToConfirm.tsx",
      "content": "\"use client\";\nimport { useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, KeyboardEvent, PointerEvent, ReactNode } from \"react\";\nimport \"./HoldToConfirm.css\";\n\nexport interface HoldToConfirmProps {\n  /** Texto de abajo mientras no se presiona. */\n  children?: ReactNode;\n  /** Texto mientras se mantiene presionado. */\n  holdingLabel?: string;\n  /** Texto cuando se confirma. */\n  confirmedLabel?: string;\n  /** Instrucciones para lectores de pantalla (no se ven). */\n  instructions?: string;\n  /** Milisegundos que hay que mantener presionado. */\n  duration?: number;\n  /** Color del anillo y del brillo. */\n  color?: string;\n  /** Color del anillo cuando se confirma. */\n  confirmedColor?: string;\n  /** Diámetro del botón, en px. */\n  size?: number;\n  /** Milisegundos para volver al estado inicial tras confirmar (0 = se queda confirmado). */\n  resetAfter?: number;\n  /** Icono propio; si falta se usa un bote de basura. */\n  icon?: ReactNode;\n  /** Desactiva el botón. */\n  disabled?: boolean;\n  /** Se llama al completar la pausa. */\n  onConfirm?: () => void;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst R = 46;\nconst C = 2 * Math.PI * R;\n\n/** Botón de mantener presionado: un anillo se llena, la tecla tiembla cada vez más y al completar vibra y se confirma. Funciona con ratón, toque y teclado (mantén Espacio o Enter). */\nexport function HoldToConfirm({\n  children = \"Hold to delete\",\n  holdingLabel = \"Keep holding…\",\n  confirmedLabel = \"Deleted\",\n  instructions = \"Press and hold the button, or the Space key, until the ring is complete.\",\n  duration = 1200,\n  color = \"#ff5a64\",\n  confirmedColor = \"#34d399\",\n  size = 96,\n  resetAfter = 2200,\n  icon,\n  disabled = false,\n  onConfirm,\n  className = \"\",\n  style,\n}: HoldToConfirmProps) {\n  const uid = useId().replace(/:/g, \"\");\n  const btnRef = useRef<HTMLButtonElement>(null);\n  const arcRef = useRef<SVGCircleElement>(null);\n  const headRef = useRef<SVGCircleElement>(null);\n  const [phase, setPhase] = useState<\"idle\" | \"holding\" | \"done\">(\"idle\");\n  const phaseRef = useRef<\"idle\" | \"holding\" | \"done\">(\"idle\");\n  const st = useRef({ p: 0, p0: 0, t0: 0, holding: false, raf: 0, last: 0, timer: 0, id: -1 });\n  const reduced = useRef(false);\n  const cfg = useRef({ duration, resetAfter, onConfirm });\n  cfg.current = { duration, resetAfter, onConfirm };\n\n  const setPh = (v: \"idle\" | \"holding\" | \"done\") => { phaseRef.current = v; setPhase(v); };\n\n  const paint = useCallback(() => {\n    const s = st.current;\n    const p = s.p;\n    arcRef.current?.setAttribute(\"stroke-dashoffset\", String(C * (1 - p)));\n    const a = p * Math.PI * 2;\n    headRef.current?.setAttribute(\"cx\", String(50 + R * Math.sin(a)));\n    headRef.current?.setAttribute(\"cy\", String(50 - R * Math.cos(a)));\n    headRef.current?.setAttribute(\"opacity\", p > 0.01 && p < 0.999 ? \"1\" : \"0\");\n    const b = btnRef.current;\n    if (!b) return;\n    b.style.setProperty(\"--furin-hold-to-confirm-p\", p.toFixed(4));\n    // Temblor creciente: se siente que algo está por ceder.\n    const amp = p > 0.45 && p < 1 ? Math.pow((p - 0.45) / 0.55, 1.6) * 2.2 : 0;\n    b.style.setProperty(\"--furin-hold-to-confirm-jx\", `${((Math.random() - 0.5) * 2 * amp).toFixed(2)}px`);\n    b.style.setProperty(\"--furin-hold-to-confirm-jy\", `${((Math.random() - 0.5) * 2 * amp).toFixed(2)}px`);\n  }, []);\n\n  const complete = useCallback(() => {\n    const s = st.current;\n    s.holding = false;\n    s.p = 1;\n    paint();\n    setPh(\"done\");\n    cfg.current.onConfirm?.();\n    if (typeof navigator !== \"undefined\" && \"vibrate\" in navigator) { try { navigator.vibrate([18, 40, 30]); } catch { /* sin vibración */ } }\n    window.clearTimeout(s.timer);\n    if (cfg.current.resetAfter > 0) {\n      s.timer = window.setTimeout(() => { setPh(\"idle\"); wake(); }, cfg.current.resetAfter);\n    }\n  }, [paint]); // eslint-disable-line react-hooks/exhaustive-deps\n\n  const tick = useCallback((now: number) => {\n    const s = st.current;\n    s.raf = 0;\n    const dt = Math.min(0.05, (now - s.last) / 1000 || 0.016);\n    s.last = now;\n    if (phaseRef.current === \"done\") { paint(); return; }\n    if (s.holding) {\n      // El avance se mide con el reloj, no con los cuadros: si la pestaña se atora, la pausa dura lo mismo.\n      s.p = Math.min(1, s.p0 + (performance.now() - s.t0) / cfg.current.duration);\n      paint();\n      if (s.p >= 1) { complete(); return; }\n    } else if (s.p > 0) {\n      // Al soltar antes de tiempo el anillo se vacía rápido, con un poco de inercia.\n      s.p = Math.max(0, s.p - dt * (0.9 + s.p * 3.2));\n      if (s.p < 0.002) s.p = 0;\n      paint();\n      if (s.p === 0) { if (phaseRef.current === \"holding\") setPh(\"idle\"); return; }\n    } else { paint(); return; }\n    s.raf = requestAnimationFrame(tick);\n  }, [paint, complete]);\n\n  const wake = useCallback(() => {\n    const s = st.current;\n    if (!s.raf) { s.last = performance.now(); s.raf = requestAnimationFrame(tick); }\n  }, [tick]);\n\n  useEffect(() => {\n    reduced.current = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    paint();\n    const s = st.current;\n    return () => { cancelAnimationFrame(s.raf); window.clearTimeout(s.timer); };\n  }, [paint]);\n\n  const start = () => {\n    if (disabled || phaseRef.current === \"done\") return;\n    const s = st.current;\n    s.holding = true;\n    s.p0 = s.p;\n    s.t0 = performance.now();\n    setPh(\"holding\");\n    wake();\n  };\n  const cancel = () => {\n    const s = st.current;\n    if (!s.holding) return;\n    s.holding = false;\n    wake();\n  };\n\n  const onDown = (e: PointerEvent<HTMLButtonElement>) => {\n    if (e.pointerType === \"mouse\" && e.button !== 0) return;\n    try { e.currentTarget.setPointerCapture(e.pointerId); } catch { /* ya capturado */ }\n    st.current.id = e.pointerId;\n    start();\n  };\n  const onKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {\n    if ((e.key === \" \" || e.key === \"Enter\") && !e.repeat) { e.preventDefault(); start(); }\n  };\n  const onKeyUp = (e: KeyboardEvent<HTMLButtonElement>) => {\n    if (e.key === \" \" || e.key === \"Enter\") { e.preventDefault(); cancel(); }\n  };\n\n  const vars = {\n    \"--furin-hold-to-confirm-size\": `${size}px`,\n    \"--furin-hold-to-confirm-color\": color,\n    \"--furin-hold-to-confirm-ok\": confirmedColor,\n  } as CSSProperties;\n  const label = phase === \"done\" ? confirmedLabel : phase === \"holding\" ? holdingLabel : children;\n\n  return (\n    <div className={`furin-hold-to-confirm ${className}`} style={{ ...vars, ...style }} data-phase={phase}>\n      <button\n        ref={btnRef}\n        type=\"button\"\n        className={`furin-hold-to-confirm__btn${phase === \"done\" ? \" is-done\" : \"\"}`}\n        disabled={disabled}\n        aria-describedby={`${uid}-hint`}\n        onPointerDown={onDown}\n        onPointerUp={cancel}\n        onPointerCancel={cancel}\n        onKeyDown={onKeyDown}\n        onKeyUp={onKeyUp}\n        onBlur={cancel}\n        onContextMenu={(e) => e.preventDefault()}\n      >\n        <span className=\"furin-hold-to-confirm__glow\" aria-hidden=\"true\" />\n        <svg className=\"furin-hold-to-confirm__ring\" viewBox=\"0 0 100 100\" aria-hidden=\"true\">\n          <defs>\n            <linearGradient id={`${uid}-g`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n              <stop offset=\"0\" stopColor=\"color-mix(in srgb, var(--furin-hold-to-confirm-color) 60%, #fff)\" />\n              <stop offset=\"1\" stopColor=\"var(--furin-hold-to-confirm-color)\" />\n            </linearGradient>\n          </defs>\n          <circle cx=\"50\" cy=\"50\" r={R} fill=\"none\" className=\"furin-hold-to-confirm__track\" strokeWidth=\"4\" />\n          <circle ref={arcRef} cx=\"50\" cy=\"50\" r={R} fill=\"none\" className=\"furin-hold-to-confirm__arc\" stroke={`url(#${uid}-g)`} strokeWidth=\"4.6\" strokeLinecap=\"round\" strokeDasharray={C} strokeDashoffset={C} transform=\"rotate(-90 50 50)\" />\n          <circle ref={headRef} r=\"3.4\" fill=\"#fff\" className=\"furin-hold-to-confirm__head\" opacity=\"0\" cx=\"50\" cy=\"4\" />\n        </svg>\n        <span className=\"furin-hold-to-confirm__face\">\n          <span className=\"furin-hold-to-confirm__icon\" aria-hidden=\"true\">\n            {icon ?? (\n              <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                <path d=\"M4.5 7h15M9.5 7V4.8h5V7M6.5 7l.8 12.2c.1.9.8 1.6 1.7 1.6h6c.9 0 1.6-.7 1.7-1.6L17.5 7M10 11v6M14 11v6\" />\n              </svg>\n            )}\n          </span>\n          <svg className=\"furin-hold-to-confirm__check\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"m6 12.5 4 4 8-9\" pathLength=\"1\" />\n          </svg>\n        </span>\n        <span className=\"furin-hold-to-confirm__burst\" aria-hidden=\"true\" />\n      </button>\n      <span className=\"furin-hold-to-confirm__label\" aria-live=\"polite\">{label}</span>\n      <span id={`${uid}-hint`} className=\"furin-hold-to-confirm__sr\">{instructions}</span>\n    </div>\n  );\n}\n\nexport default HoldToConfirm;\n",
      "type": "registry:component",
      "target": "components/furin/hold-to-confirm/HoldToConfirm.tsx"
    },
    {
      "path": "registry/hold-to-confirm/HoldToConfirm.css",
      "content": ".furin-hold-to-confirm {\n  display: inline-flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 18px;\n  font-family: Geist, -apple-system, BlinkMacSystemFont, \"SF Pro Text\", system-ui, sans-serif;\n}\n.furin-hold-to-confirm__btn {\n  --furin-hold-to-confirm-p: 0;\n  --furin-hold-to-confirm-jx: 0px;\n  --furin-hold-to-confirm-jy: 0px;\n  position: relative;\n  width: var(--furin-hold-to-confirm-size);\n  height: var(--furin-hold-to-confirm-size);\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: none;\n  color: rgb(255 255 255 / 0.82);\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  outline: none;\n  /* Se comprime a medida que se llena el anillo. */\n  transform: translate(var(--furin-hold-to-confirm-jx), var(--furin-hold-to-confirm-jy)) scale(calc(1 - var(--furin-hold-to-confirm-p) * 0.07));\n  transition: scale 0.4s cubic-bezier(0.3, 1.7, 0.5, 1);\n}\n.furin-hold-to-confirm__btn:disabled { opacity: 0.4; cursor: not-allowed; }\n.furin-hold-to-confirm__btn:focus-visible { box-shadow: 0 0 0 3px rgb(255 255 255 / 0.55); }\n/* Resplandor del color que crece con el progreso. */\n.furin-hold-to-confirm__glow {\n  position: absolute;\n  inset: -22%;\n  border-radius: 50%;\n  background: radial-gradient(circle, color-mix(in srgb, var(--furin-hold-to-confirm-color) 70%, transparent), transparent 62%);\n  opacity: calc(var(--furin-hold-to-confirm-p) * 0.55);\n  pointer-events: none;\n}\n.is-done .furin-hold-to-confirm__glow { background: radial-gradient(circle, color-mix(in srgb, var(--furin-hold-to-confirm-ok) 70%, transparent), transparent 62%); opacity: 0.55; transition: opacity 0.4s; }\n.furin-hold-to-confirm__face {\n  position: absolute;\n  inset: 9%;\n  display: grid;\n  place-items: center;\n  border-radius: 50%;\n  background:\n    radial-gradient(90% 70% at 50% 8%, rgb(255 255 255 / 0.14), transparent 62%),\n    radial-gradient(circle at 50% 40%, #272a33, #15171c 78%);\n  box-shadow:\n    inset 0 1px 0 rgb(255 255 255 / 0.22),\n    inset 0 -6px 10px rgb(0 0 0 / 0.5),\n    0 0 0 1px rgb(255 255 255 / 0.06),\n    0 10px 18px -6px rgb(0 0 0 / 0.75);\n}\n.furin-hold-to-confirm__btn:active:not(.is-done) .furin-hold-to-confirm__face { box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.12), inset 0 -3px 8px rgb(0 0 0 / 0.5), 0 0 0 1px rgb(255 255 255 / 0.06), 0 4px 10px -4px rgb(0 0 0 / 0.75); }\n.furin-hold-to-confirm__icon { display: grid; place-items: center; width: 34%; height: 34%; transition: transform 0.3s, opacity 0.2s; }\n.furin-hold-to-confirm__icon svg { width: 100%; height: 100%; }\n.furin-hold-to-confirm__btn[data-x] .furin-hold-to-confirm__icon { color: var(--furin-hold-to-confirm-color); }\n.furin-hold-to-confirm__check {\n  position: absolute;\n  width: 38%;\n  height: 38%;\n  color: var(--furin-hold-to-confirm-ok);\n  opacity: 0;\n}\n.furin-hold-to-confirm__check path { stroke-dasharray: 1; stroke-dashoffset: 1; }\n.is-done .furin-hold-to-confirm__icon { transform: scale(0.4); opacity: 0; }\n.is-done .furin-hold-to-confirm__check { opacity: 1; }\n.is-done .furin-hold-to-confirm__check path { animation: furin-hold-to-confirm-draw 0.45s 0.12s cubic-bezier(0.5, 0, 0.2, 1) forwards; }\n.furin-hold-to-confirm__ring { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.furin-hold-to-confirm__track { stroke: rgb(255 255 255 / 0.1); }\n.furin-hold-to-confirm__arc { filter: drop-shadow(0 0 5px color-mix(in srgb, var(--furin-hold-to-confirm-color) 80%, transparent)); }\n.furin-hold-to-confirm__head { filter: drop-shadow(0 0 4px var(--furin-hold-to-confirm-color)) drop-shadow(0 0 8px var(--furin-hold-to-confirm-color)); }\n.is-done .furin-hold-to-confirm__arc { stroke: var(--furin-hold-to-confirm-ok); filter: drop-shadow(0 0 7px var(--furin-hold-to-confirm-ok)); transition: stroke 0.2s; }\n/* Vibración al completar: sacudida que se amortigua. */\n.is-done { animation: furin-hold-to-confirm-shake 0.55s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }\n/* Onda de choque. */\n.furin-hold-to-confirm__burst {\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  border: 2px solid var(--furin-hold-to-confirm-ok);\n  opacity: 0;\n  pointer-events: none;\n}\n.is-done .furin-hold-to-confirm__burst { animation: furin-hold-to-confirm-burst 0.7s cubic-bezier(0.2, 0.6, 0.2, 1) forwards; }\n.furin-hold-to-confirm__label {\n  min-height: 1.2em;\n  font: 500 14px/1.2 Geist, system-ui, sans-serif;\n  letter-spacing: 0.005em;\n  color: rgb(255 255 255 / 0.55);\n  transition: color 0.25s;\n}\n[data-phase=\"holding\"] .furin-hold-to-confirm__label { color: rgb(255 255 255 / 0.9); }\n[data-phase=\"done\"] .furin-hold-to-confirm__label { color: var(--furin-hold-to-confirm-ok); }\n.furin-hold-to-confirm__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n@keyframes furin-hold-to-confirm-draw { to { stroke-dashoffset: 0; } }\n@keyframes furin-hold-to-confirm-burst { 0% { opacity: 0.9; transform: scale(1); } 100% { opacity: 0; transform: scale(2); border-width: 0.5px; } }\n@keyframes furin-hold-to-confirm-shake {\n  0%, 100% { translate: 0 0; rotate: 0deg; }\n  10% { translate: -6px 0; rotate: -2deg; } 22% { translate: 5px 0; rotate: 1.6deg; } 34% { translate: -4px 0; rotate: -1.2deg; }\n  46% { translate: 3px 0; rotate: 0.8deg; } 58% { translate: -2px 0; rotate: -0.5deg; } 72% { translate: 1px 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .is-done { animation: none; }\n  .furin-hold-to-confirm__btn { transition: none; }\n  .is-done .furin-hold-to-confirm__burst { animation: none; }\n}\n",
      "type": "registry:file",
      "target": "components/furin/hold-to-confirm/HoldToConfirm.css"
    }
  ]
}
