{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slide-to-confirm",
  "type": "registry:component",
  "title": "Slide to Confirm",
  "description": "A physics-driven handle you drag to the end to confirm; release early and it springs back with a bounce. Accessible as a slider.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Buttons"
  ],
  "docs": "Installed in components/furin/slide-to-confirm/. Docs, live controls and props table: https://furin.dev/components/slide-to-confirm/",
  "files": [
    {
      "path": "registry/slide-to-confirm/SlideToConfirm.tsx",
      "content": "\"use client\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, KeyboardEvent, PointerEvent, ReactNode } from \"react\";\nimport \"./SlideToConfirm.css\";\n\nexport interface SlideToConfirmProps {\n  /** Texto del carril. */\n  children?: ReactNode;\n  /** Texto cuando se confirma. */\n  confirmedLabel?: string;\n  /** Color de arranque de la estela que deja el pomo. */\n  color?: string;\n  /** Color de cierre de la estela. */\n  colorTo?: string;\n  /** Color de la estela al confirmar. */\n  confirmedColor?: string;\n  /** Ancho máximo del carril, en px. */\n  width?: number;\n  /** Alto del carril, en px. */\n  height?: number;\n  /** Qué tan lejos hay que llegar para confirmar, de 0.5 a 1. */\n  threshold?: number;\n  /** Milisegundos para volver al inicio tras confirmar (0 = se queda confirmado). */\n  resetAfter?: number;\n  /** Desactiva el control. */\n  disabled?: boolean;\n  /** Se llama al confirmar. */\n  onConfirm?: () => void;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\n/** Deslizar para confirmar: un pomo con física que se arrastra hasta el final; si se suelta antes regresa con resorte y rebote. Accesible como slider (flechas, Fin/Enter). */\nexport function SlideToConfirm({\n  children = \"Slide to confirm\",\n  confirmedLabel = \"Confirmed\",\n  color = \"#5b6cff\",\n  colorTo = \"#8b5cf6\",\n  confirmedColor = \"#34d399\",\n  width = 330,\n  height = 66,\n  threshold = 0.92,\n  resetAfter = 2400,\n  disabled = false,\n  onConfirm,\n  className = \"\",\n  style,\n}: SlideToConfirmProps) {\n  const trackRef = useRef<HTMLDivElement>(null);\n  const knobRef = useRef<HTMLDivElement>(null);\n  const [phase, setPhase] = useState<\"idle\" | \"done\">(\"idle\");\n  const [pct, setPct] = useState(0);\n  const phaseRef = useRef<\"idle\" | \"done\">(\"idle\");\n  const s = useRef({ x: 0, v: 0, tx: 0, max: 1, dragging: false, grab: 0, last: 0, raf: 0, id: -1, timer: 0, lastX: 0, lastT: 0, vel: 0, pct: 0 });\n  const reduced = useRef(false);\n  const cfg = useRef({ threshold, resetAfter, onConfirm });\n  cfg.current = { threshold, resetAfter, onConfirm };\n  const pad = 6;\n\n  const paint = useCallback(() => {\n    const t = trackRef.current, k = knobRef.current;\n    if (!t || !k) return;\n    const q = s.current;\n    const p = q.max > 0 ? Math.max(0, Math.min(1, q.x / q.max)) : 0;\n    const stretch = Math.min(0.14, Math.abs(q.vel) / 9000);\n    k.style.transform = `translate3d(${q.x.toFixed(2)}px,0,0) scale(${(1 + stretch).toFixed(3)}, ${(1 - stretch * 0.6).toFixed(3)})`;\n    t.style.setProperty(\"--furin-slide-to-confirm-p\", p.toFixed(4));\n    t.style.setProperty(\"--furin-slide-to-confirm-x\", `${q.x.toFixed(2)}px`);\n    const rounded = Math.round(p * 100);\n    if (rounded !== q.pct) { q.pct = rounded; setPct(rounded); }\n  }, []);\n\n  const measure = useCallback(() => {\n    const t = trackRef.current, k = knobRef.current;\n    if (!t || !k) return;\n    s.current.max = Math.max(1, t.clientWidth - k.offsetWidth - pad * 2);\n    if (phaseRef.current === \"done\") { s.current.tx = s.current.max; s.current.x = s.current.max; }\n    paint();\n  }, [paint]);\n\n  const finish = useCallback(() => {\n    const q = s.current;\n    if (phaseRef.current === \"done\") return;\n    phaseRef.current = \"done\";\n    setPhase(\"done\");\n    q.tx = q.max;\n    cfg.current.onConfirm?.();\n    if (typeof navigator !== \"undefined\" && \"vibrate\" in navigator) { try { navigator.vibrate(24); } catch { /* sin vibración */ } }\n    window.clearTimeout(q.timer);\n    if (cfg.current.resetAfter > 0) {\n      q.timer = window.setTimeout(() => { phaseRef.current = \"idle\"; setPhase(\"idle\"); q.tx = 0; wake(); }, cfg.current.resetAfter);\n    }\n    wake();\n  }, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n  const tick = useCallback((now: number) => {\n    const q = s.current;\n    q.raf = 0;\n    const dt = Math.min(0.033, (now - q.last) / 1000 || 0.016);\n    q.last = now;\n    let moving = true;\n    if (q.dragging) {\n      // El pomo sigue al dedo; la velocidad se suaviza para el estiramiento.\n      q.vel += (((q.x - q.lastX) / Math.max(dt, 0.001)) - q.vel) * Math.min(1, dt * 18);\n      q.lastX = q.x;\n    } else {\n      const done = phaseRef.current === \"done\";\n      const k = done ? 260 : 210, c = done ? 26 : 15;\n      const sub = 3, h = dt / sub;\n      for (let i = 0; i < sub; i++) {\n        q.v += (k * (q.tx - q.x) - c * q.v) * h;\n        q.x += q.v * h;\n        // El borde izquierdo es una pared: el pomo rebota contra ella.\n        if (q.x < 0) { q.x = 0; q.v = Math.abs(q.v) * 0.38; }\n        if (q.x > q.max) { q.x = q.max; q.v = -Math.abs(q.v) * 0.2; }\n      }\n      q.vel = q.v;\n      if (Math.abs(q.tx - q.x) < 0.1 && Math.abs(q.v) < 2) { q.x = q.tx; q.v = 0; q.vel = 0; moving = false; }\n      if (done && q.x >= q.max - 0.5) moving = Math.abs(q.v) > 2;\n    }\n    paint();\n    if (moving) q.raf = requestAnimationFrame(tick);\n  }, [paint]);\n\n  const wake = useCallback(() => {\n    const q = s.current;\n    if (reduced.current && !q.dragging) { q.x = q.tx; q.v = 0; q.vel = 0; paint(); return; }\n    if (!q.raf) { q.last = performance.now(); q.raf = requestAnimationFrame(tick); }\n  }, [paint, tick]);\n\n  // Mientras se arrastra, los eventos se escuchan en la ventana: el dedo puede salirse del pomo sin soltarlo.\n  const onWinMove = useCallback((e: globalThis.PointerEvent) => {\n    const q = s.current;\n    if (!q.dragging || q.id !== e.pointerId) return;\n    q.x = Math.max(0, Math.min(q.max, e.clientX - q.grab));\n    q.tx = q.x;\n  }, []);\n  const onWinUp = useCallback((e: globalThis.PointerEvent) => {\n    const q = s.current;\n    if (!q.dragging || q.id !== e.pointerId) return;\n    window.removeEventListener(\"pointermove\", onWinMove);\n    window.removeEventListener(\"pointerup\", onWinUp);\n    window.removeEventListener(\"pointercancel\", onWinUp);\n    q.dragging = false;\n    knobRef.current?.removeAttribute(\"data-drag\");\n    q.v = q.vel;\n    const p = q.x / q.max;\n    if (e.type !== \"pointercancel\" && (p >= cfg.current.threshold || (q.vel > 1500 && p > 0.5))) finish();\n    else q.tx = 0;\n    wake();\n  }, [finish, wake, onWinMove]);\n\n  const onDown = (e: PointerEvent<HTMLDivElement>) => {\n    if (disabled || phaseRef.current === \"done\") return;\n    if (e.pointerType === \"mouse\" && e.button !== 0) return;\n    const q = s.current;\n    q.dragging = true; q.id = e.pointerId;\n    q.grab = e.clientX - q.x;\n    q.lastX = q.x; q.vel = 0; q.v = 0;\n    knobRef.current?.setAttribute(\"data-drag\", \"true\");\n    window.addEventListener(\"pointermove\", onWinMove);\n    window.addEventListener(\"pointerup\", onWinUp);\n    window.addEventListener(\"pointercancel\", onWinUp);\n    wake();\n  };\n\n  useEffect(() => {\n    reduced.current = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    measure();\n    const ro = new ResizeObserver(measure);\n    if (trackRef.current) ro.observe(trackRef.current);\n    const q = s.current;\n    return () => { ro.disconnect(); cancelAnimationFrame(q.raf); window.clearTimeout(q.timer); window.removeEventListener(\"pointermove\", onWinMove); window.removeEventListener(\"pointerup\", onWinUp); window.removeEventListener(\"pointercancel\", onWinUp); };\n  }, [measure, onWinMove, onWinUp]);\n\n  const onKey = (e: KeyboardEvent<HTMLDivElement>) => {\n    if (disabled || phaseRef.current === \"done\") return;\n    const q = s.current;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") { e.preventDefault(); q.tx = Math.min(q.max, q.tx + q.max * 0.12); if (q.tx / q.max >= cfg.current.threshold) finish(); wake(); }\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") { e.preventDefault(); q.tx = Math.max(0, q.tx - q.max * 0.12); wake(); }\n    else if (e.key === \"Home\") { e.preventDefault(); q.tx = 0; wake(); }\n    else if (e.key === \"End\" || e.key === \"Enter\") { e.preventDefault(); finish(); }\n  };\n\n  const vars = {\n    \"--furin-slide-to-confirm-w\": `${width}px`,\n    \"--furin-slide-to-confirm-h\": `${height}px`,\n    \"--furin-slide-to-confirm-pad\": `${pad}px`,\n    \"--furin-slide-to-confirm-a\": color,\n    \"--furin-slide-to-confirm-b\": colorTo,\n    \"--furin-slide-to-confirm-ok\": confirmedColor,\n  } as CSSProperties;\n\n  return (\n    <div\n      ref={trackRef}\n      className={`furin-slide-to-confirm ${className}`}\n      style={{ ...vars, ...style }}\n      data-phase={phase}\n      data-disabled={disabled ? \"true\" : undefined}\n      role=\"slider\"\n      tabIndex={disabled ? -1 : 0}\n      aria-label={typeof children === \"string\" ? children : \"Slide to confirm\"}\n      aria-valuemin={0}\n      aria-valuemax={100}\n      aria-valuenow={phase === \"done\" ? 100 : pct}\n      aria-valuetext={phase === \"done\" ? confirmedLabel : `${pct}%`}\n      aria-disabled={disabled}\n      onKeyDown={onKey}\n    >\n      <div className=\"furin-slide-to-confirm__fill\" aria-hidden=\"true\" />\n      <span className=\"furin-slide-to-confirm__label\" aria-hidden=\"true\">{children}</span>\n      <span className=\"furin-slide-to-confirm__done\" aria-hidden=\"true\">{confirmedLabel}</span>\n      <div ref={knobRef} className=\"furin-slide-to-confirm__knob\" onPointerDown={onDown}>\n        <svg className=\"furin-slide-to-confirm__arrow\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M5 12h13M13 6.5 18.5 12 13 17.5\" /></svg>\n        <svg className=\"furin-slide-to-confirm__check\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"m6 12.5 4 4 8-9\" pathLength=\"1\" /></svg>\n        <span className=\"furin-slide-to-confirm__burst\" />\n      </div>\n    </div>\n  );\n}\n\nexport default SlideToConfirm;\n",
      "type": "registry:component",
      "target": "components/furin/slide-to-confirm/SlideToConfirm.tsx"
    },
    {
      "path": "registry/slide-to-confirm/SlideToConfirm.css",
      "content": ".furin-slide-to-confirm {\n  --furin-slide-to-confirm-p: 0;\n  --furin-slide-to-confirm-x: 0px;\n  position: relative;\n  width: min(var(--furin-slide-to-confirm-w), calc(100% - 40px));\n  height: var(--furin-slide-to-confirm-h);\n  border-radius: 999px;\n  overflow: hidden;\n  display: grid;\n  place-items: center;\n  background: linear-gradient(180deg, #0e1015, #171a21);\n  box-shadow: inset 0 2px 6px rgb(0 0 0 / 0.7), inset 0 0 0 1px rgb(255 255 255 / 0.07), 0 1px 0 rgb(255 255 255 / 0.06), 0 16px 28px -14px rgb(0 0 0 / 0.8);\n  font-family: Geist, -apple-system, BlinkMacSystemFont, \"SF Pro Text\", system-ui, sans-serif;\n  user-select: none;\n  -webkit-user-select: none;\n  touch-action: pan-y;\n  outline: none;\n}\n.furin-slide-to-confirm:focus-visible { box-shadow: inset 0 2px 6px rgb(0 0 0 / 0.7), inset 0 0 0 1px rgb(255 255 255 / 0.07), 0 0 0 3px rgb(255 255 255 / 0.55); }\n.furin-slide-to-confirm[data-disabled=\"true\"] { opacity: 0.45; }\n/* Estela de color que el pomo va dejando atrás. */\n.furin-slide-to-confirm__fill {\n  position: absolute;\n  left: 0;\n  top: 0;\n  bottom: 0;\n  width: calc(var(--furin-slide-to-confirm-x) + var(--furin-slide-to-confirm-h) - var(--furin-slide-to-confirm-pad));\n  border-radius: 999px;\n  background:\n    linear-gradient(180deg, rgb(255 255 255 / 0.22), transparent 55%),\n    linear-gradient(90deg, color-mix(in srgb, var(--furin-slide-to-confirm-a) 40%, transparent), var(--furin-slide-to-confirm-b));\n  opacity: calc(var(--furin-slide-to-confirm-p) * 4);\n  box-shadow: 0 0 24px color-mix(in srgb, var(--furin-slide-to-confirm-b) 60%, transparent);\n  transition: background 0.35s;\n}\n[data-phase=\"done\"] .furin-slide-to-confirm__fill { background: linear-gradient(180deg, rgb(255 255 255 / 0.25), transparent 55%), linear-gradient(90deg, color-mix(in srgb, var(--furin-slide-to-confirm-ok) 55%, transparent), var(--furin-slide-to-confirm-ok)); opacity: 1; box-shadow: 0 0 30px color-mix(in srgb, var(--furin-slide-to-confirm-ok) 60%, transparent); }\n.furin-slide-to-confirm__label,\n.furin-slide-to-confirm__done {\n  position: relative;\n  padding-left: calc(var(--furin-slide-to-confirm-h) * 0.55);\n  font: 500 16px/1 Geist, system-ui, sans-serif;\n  letter-spacing: -0.005em;\n  white-space: nowrap;\n  pointer-events: none;\n  grid-area: 1 / 1;\n}\n/* Texto con un brillo que lo recorre, como en los desbloqueos de móvil. */\n.furin-slide-to-confirm__label {\n  color: transparent;\n  background: linear-gradient(100deg, rgb(255 255 255 / 0.38) 38%, rgb(255 255 255 / 0.95) 50%, rgb(255 255 255 / 0.38) 62%) 0 0 / 250% 100%;\n  -webkit-background-clip: text;\n  background-clip: text;\n  animation: furin-slide-to-confirm-shine 2.6s linear infinite;\n  opacity: calc(1 - var(--furin-slide-to-confirm-p) * 1.7);\n  transform: translateX(calc(var(--furin-slide-to-confirm-p) * 26px));\n}\n.furin-slide-to-confirm__done { color: #fff; font-weight: 600; opacity: 0; transform: translateX(12px); transition: opacity 0.3s 0.15s, transform 0.4s 0.15s cubic-bezier(0.2, 0.8, 0.2, 1); text-shadow: 0 1px 6px rgb(0 0 0 / 0.25); }\n[data-phase=\"done\"] .furin-slide-to-confirm__done { opacity: 1; transform: none; padding-left: 0; padding-right: calc(var(--furin-slide-to-confirm-h) * 0.5); justify-self: center; }\n[data-phase=\"done\"] .furin-slide-to-confirm__label { opacity: 0; }\n.furin-slide-to-confirm__knob {\n  position: absolute;\n  left: var(--furin-slide-to-confirm-pad);\n  top: var(--furin-slide-to-confirm-pad);\n  width: calc(var(--furin-slide-to-confirm-h) - var(--furin-slide-to-confirm-pad) * 2);\n  height: calc(var(--furin-slide-to-confirm-h) - var(--furin-slide-to-confirm-pad) * 2);\n  display: grid;\n  place-items: center;\n  border-radius: 50%;\n  color: #1a1c24;\n  cursor: grab;\n  touch-action: none;\n  background:\n    radial-gradient(90% 70% at 50% 8%, rgb(255 255 255 / 0.95), rgb(255 255 255 / 0) 60%),\n    linear-gradient(180deg, #f6f7fb, #cfd3de);\n  box-shadow: inset 0 1px 0 #fff, inset 0 -3px 5px rgb(60 70 100 / 0.25), 0 1px 2px rgb(0 0 0 / 0.5), 0 8px 14px -3px rgb(0 0 0 / 0.55);\n  transform-origin: 0 50%;\n  will-change: transform;\n}\n.furin-slide-to-confirm__knob[data-drag=\"true\"] { cursor: grabbing; box-shadow: inset 0 1px 0 #fff, inset 0 -3px 5px rgb(60 70 100 / 0.25), 0 1px 2px rgb(0 0 0 / 0.5), 0 12px 20px -3px rgb(0 0 0 / 0.65); }\n[data-phase=\"done\"] .furin-slide-to-confirm__knob { cursor: default; color: #0b6b4b; }\n.furin-slide-to-confirm__arrow, .furin-slide-to-confirm__check { position: absolute; width: 44%; height: 44%; transition: opacity 0.2s, transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }\n.furin-slide-to-confirm__check { opacity: 0; transform: scale(0.4); }\n.furin-slide-to-confirm__check path { stroke-dasharray: 1; stroke-dashoffset: 1; }\n[data-phase=\"done\"] .furin-slide-to-confirm__arrow { opacity: 0; transform: scale(0.4); }\n[data-phase=\"done\"] .furin-slide-to-confirm__check { opacity: 1; transform: none; }\n[data-phase=\"done\"] .furin-slide-to-confirm__check path { animation: furin-slide-to-confirm-draw 0.4s 0.1s cubic-bezier(0.5, 0, 0.2, 1) forwards; }\n.furin-slide-to-confirm__burst { position: absolute; inset: 0; border-radius: 50%; border: 2px solid #fff; opacity: 0; pointer-events: none; }\n[data-phase=\"done\"] .furin-slide-to-confirm__burst { animation: furin-slide-to-confirm-burst 0.6s ease-out; }\n@keyframes furin-slide-to-confirm-shine { from { background-position: 120% 0; } to { background-position: -120% 0; } }\n@keyframes furin-slide-to-confirm-draw { to { stroke-dashoffset: 0; } }\n@keyframes furin-slide-to-confirm-burst { 0% { opacity: 0.9; transform: scale(1); } 100% { opacity: 0; transform: scale(2.4); } }\n@media (prefers-reduced-motion: reduce) {\n  .furin-slide-to-confirm__label { animation: none; background-position: 50% 0; }\n  .furin-slide-to-confirm__done, .furin-slide-to-confirm__arrow, .furin-slide-to-confirm__check { transition: none; }\n}\n",
      "type": "registry:file",
      "target": "components/furin/slide-to-confirm/SlideToConfirm.css"
    }
  ]
}
