{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "download-button",
  "type": "registry:component",
  "title": "Download Button",
  "description": "A button that narrows into a progress bar, advances at an uneven pace like a real network, and ends in a checkmark. With href, it really downloads the file.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Buttons"
  ],
  "docs": "Installed in components/furin/download-button/. Docs, live controls and props table: https://furin.dev/components/download-button/",
  "files": [
    {
      "path": "registry/download-button/DownloadButton.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport \"./DownloadButton.css\";\n\nexport interface DownloadButtonProps {\n  /** Texto del botón en reposo. */\n  label?: string;\n  /** Texto cuando termina. */\n  doneLabel?: string;\n  /** Nombre del archivo que se muestra mientras \"baja\". */\n  fileName?: string;\n  /** Tamaño del archivo que se muestra mientras \"baja\". */\n  fileSize?: string;\n  /** Duración de la descarga simulada, en milisegundos. */\n  duration?: number;\n  /** Si lo pones, al terminar se descarga ese archivo de verdad. */\n  href?: string;\n  /** Milisegundos que se queda en \"listo\" antes de volver al inicio (0 = se queda). */\n  resetAfter?: number;\n  /** Color del botón en reposo. */\n  color?: string;\n  /** Color del estado \"listo\". */\n  doneColor?: string;\n  /** Se llama cuando empieza la descarga. */\n  onStart?: () => void;\n  /** Se llama cuando termina. */\n  onComplete?: () => void;\n  /** Segundos entre descargas automáticas (0 = apagado; se detiene al interactuar). */\n  autoplay?: number;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\ntype Fase = \"idle\" | \"bajando\" | \"listo\";\n\n/** Botón de descarga: se afina hasta ser una barra de progreso, avanza a ritmo irregular como una red real y termina en una palomita. */\nexport function DownloadButton({\n  label = \"Download\",\n  doneLabel = \"Done\",\n  fileName = \"furin-kit.zip\",\n  fileSize = \"4.2 MB\",\n  duration = 3200,\n  href,\n  resetAfter = 2600,\n  color = \"#F3F4F7\",\n  doneColor = \"#6EE0A6\",\n  onStart,\n  onComplete,\n  autoplay = 0,\n  className = \"\",\n  style,\n}: DownloadButtonProps) {\n  const [fase, setFase] = useState<Fase>(\"idle\");\n  const [aviso, setAviso] = useState(\"\");\n  const relleno = useRef<HTMLSpanElement>(null);\n  const pctTxt = useRef<HTMLSpanElement>(null);\n  const barra = useRef<HTMLDivElement>(null);\n  const progreso = useRef(0);\n  const raf = useRef(0);\n  const timer = useRef(0);\n  const tocado = useRef(false);\n  const live = useRef({ duration, onComplete, resetAfter, href, fileName });\n  live.current = { duration, onComplete, resetAfter, href, fileName };\n\n  const pinta = (p: number) => {\n    progreso.current = p;\n    if (relleno.current) relleno.current.style.transform = `scaleX(${(p / 100).toFixed(4)})`;\n    if (pctTxt.current) pctTxt.current.textContent = `${Math.floor(p)}%`;\n    const b = barra.current;\n    if (b) b.setAttribute(\"aria-valuenow\", String(Math.floor(p)));\n  };\n\n  const cancelar = () => {\n    cancelAnimationFrame(raf.current);\n    window.clearTimeout(timer.current);\n    pinta(0);\n    setFase(\"idle\");\n    setAviso(\"Download canceled\");\n  };\n\n  const empezar = () => {\n    tocado.current = true;\n    if (fase === \"bajando\") { cancelar(); return; }\n    if (fase === \"listo\") return;\n    onStart?.();\n    arrancar();\n  };\n\n  const arrancar = () => {\n    window.clearTimeout(timer.current);\n    pinta(0);\n    setFase(\"bajando\");\n    setAviso(`Downloading ${live.current.fileName}`);\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let p = 0, t0 = performance.now(), last = t0, avisado = 0;\n    const seed = Math.random() * 10;\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, Math.max(0, (now - last) / 1000));\n      last = now;\n      // Ritmo irregular: arranque lento, ráfagas, un par de pausas y un final que se arrastra, como una red de verdad.\n      const t = (now - t0) / 1000 + seed;\n      const ruido = 0.35 + 0.65 * Math.abs(Math.sin(t * 1.9) * Math.sin(t * 0.7 + 1.3)) + 0.5 * Math.max(0, Math.sin(t * 3.1));\n      const freno = p > 86 ? 0.45 : p < 8 ? 0.6 : 1;\n      p = Math.min(100, p + (100 / (live.current.duration / 1000)) * dt * ruido * freno * (reduce ? 3 : 1.15));\n      pinta(p);\n      const hito = Math.floor(p / 25);\n      if (hito > avisado && p < 100) { avisado = hito; setAviso(`${hito * 25}%`); }\n      if (p >= 100) { termina(); return; }\n      raf.current = requestAnimationFrame(frame);\n    };\n    raf.current = requestAnimationFrame(frame);\n  };\n\n  const termina = () => {\n    pinta(100);\n    setFase(\"listo\");\n    setAviso(`Download complete: ${live.current.fileName}`);\n    live.current.onComplete?.();\n    if (live.current.href) {\n      const a = document.createElement(\"a\");\n      a.href = live.current.href;\n      a.download = live.current.fileName;\n      a.rel = \"noopener\";\n      document.body.appendChild(a);\n      a.click();\n      a.remove();\n    }\n    if (live.current.resetAfter > 0) {\n      timer.current = window.setTimeout(() => { setFase(\"idle\"); pinta(0); }, live.current.resetAfter);\n    }\n  };\n\n  useEffect(() => () => { cancelAnimationFrame(raf.current); window.clearTimeout(timer.current); }, []);\n\n  // Descargas automáticas para la demo; se detienen en cuanto alguien toca el botón.\n  useEffect(() => {\n    if (!autoplay) return;\n    const id = window.setInterval(() => {\n      if (tocado.current || document.hidden) return;\n      if (faseRef.current === \"idle\") arrancar();\n    }, autoplay * 1000);\n    return () => window.clearInterval(id);\n  }, [autoplay]); // eslint-disable-line react-hooks/exhaustive-deps\n  const faseRef = useRef(fase);\n  faseRef.current = fase;\n\n  const vars = { \"--furin-dl-color\": color, \"--furin-dl-done\": doneColor } as CSSProperties;\n  const nombreAcc = fase === \"bajando\" ? `Cancel download of ${fileName}` : fase === \"listo\" ? `${doneLabel}: ${fileName}` : `${label} ${fileName}`;\n  return (\n    <div className={`furin-download-button is-${fase} ${className}`} style={{ ...vars, ...style }}>\n      {/* Datos del archivo: aparecen sobre la barra mientras baja. */}\n      <div className=\"furin-download-button__info\" aria-hidden=\"true\">\n        <span className=\"furin-download-button__archivo\">{fileName} <i>{fileSize}</i></span>\n        <span ref={pctTxt} className=\"furin-download-button__pct\">0%</span>\n      </div>\n      <button type=\"button\" className=\"furin-download-button__boton\" onClick={empezar} aria-label={nombreAcc} aria-disabled={fase === \"listo\"}>\n        <span className=\"furin-download-button__relleno-wrap\" aria-hidden=\"true\">\n          <span ref={relleno} className=\"furin-download-button__relleno\" />\n        </span>\n        <span className=\"furin-download-button__contenido\" aria-hidden=\"true\">\n          <svg className=\"furin-download-button__flecha\" viewBox=\"0 0 20 20\">\n            <path d=\"M10 3.6v9.2M5.8 9l4.2 4.2L14.2 9M4.4 16.4h11.2\" />\n          </svg>\n          <span className=\"furin-download-button__txt\">{label}</span>\n        </span>\n        <span className=\"furin-download-button__listo\" aria-hidden=\"true\">\n          <svg viewBox=\"0 0 20 20\"><path d=\"M4.6 10.4 8.4 14.2 15.6 6\" pathLength=\"1\" /></svg>\n          <span>{doneLabel}</span>\n        </span>\n      </button>\n      <div ref={barra} className=\"furin-download-button__sr\" role=\"progressbar\" aria-label={`${fileName} download progress`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={0} hidden={fase !== \"bajando\"} />\n      <span className=\"furin-download-button__sr\" role=\"status\" aria-live=\"polite\">{aviso}</span>\n    </div>\n  );\n}\n\nexport default DownloadButton;\n",
      "type": "registry:component",
      "target": "components/furin/download-button/DownloadButton.tsx"
    },
    {
      "path": "registry/download-button/DownloadButton.css",
      "content": ".furin-download-button {\n  --furin-dl-color: #f3f4f7;\n  --furin-dl-done: #6ee0a6;\n  --furin-dl-ease: cubic-bezier(0.34, 1.35, 0.55, 1);\n  position: relative;\n  width: min(240px, 90%);\n  height: 76px;\n  font-family: Geist, system-ui, -apple-system, sans-serif;\n  color: #0b0c0f;\n}\n.furin-download-button__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n\n/* Info del archivo sobre la barra */\n.furin-download-button__info { position: absolute; left: 2px; right: 2px; top: 6px; display: flex; justify-content: space-between; align-items: baseline; opacity: 0; transform: translateY(8px); transition: opacity 0.3s, transform 0.5s var(--furin-dl-ease); pointer-events: none; }\n.is-bajando .furin-download-button__info { opacity: 1; transform: none; transition-delay: 0.15s; }\n.furin-download-button__archivo { font: 500 12.5px/1 Geist, system-ui, sans-serif; color: rgba(255, 255, 255, 0.78); }\n.furin-download-button__archivo i { font: 400 11px \"JetBrains Mono\", ui-monospace, monospace; font-style: normal; margin-left: 6px; color: rgba(255, 255, 255, 0.4); }\n.furin-download-button__pct { font: 500 12.5px/1 \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, monospace; font-variant-numeric: tabular-nums; color: #fff; }\n\n/* Botón: una pastilla que, al descargar, se afina hasta ser una barra y, al terminar, vuelve a crecer. */\n.furin-download-button__boton {\n  position: absolute;\n  left: 0; right: 0; bottom: 6px;\n  height: 52px;\n  display: block;\n  padding: 0;\n  appearance: none;\n  border: 0;\n  border-radius: 999px;\n  overflow: hidden;\n  background: var(--furin-dl-color);\n  color: #0b0c0f;\n  cursor: pointer;\n  font: 600 15px/1 Geist, system-ui, sans-serif;\n  letter-spacing: -0.01em;\n  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 12px 26px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0, 0, 0, 0.1);\n  transition: height 0.55s var(--furin-dl-ease), background-color 0.4s ease, box-shadow 0.4s ease, transform 0.25s var(--furin-dl-ease);\n  -webkit-tap-highlight-color: transparent;\n}\n.furin-download-button__boton:hover { transform: scale(1.015); }\n.furin-download-button__boton:active { transform: scale(0.97); }\n.furin-download-button__boton:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.9); outline-offset: 3px; }\n.is-bajando .furin-download-button__boton { height: 8px; bottom: 25px; background: rgba(255, 255, 255, 0.13); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06); cursor: pointer; }\n.is-bajando .furin-download-button__boton:hover { transform: none; }\n.is-listo .furin-download-button__boton { background: var(--furin-dl-done); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 12px 30px -10px color-mix(in srgb, var(--furin-dl-done) 55%, transparent), 0 0 0 1px rgba(0, 0, 0, 0.08); cursor: default; }\n\n.furin-download-button__relleno-wrap { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; opacity: 0; transition: opacity 0.25s; }\n.is-bajando .furin-download-button__relleno-wrap { opacity: 1; transition-delay: 0.2s; }\n.furin-download-button__relleno { position: absolute; inset: 0; transform: scaleX(0); transform-origin: left center; border-radius: inherit; background: linear-gradient(90deg, #cfd5ff, #fff); box-shadow: 0 0 14px rgba(255, 255, 255, 0.6); }\n\n.furin-download-button__contenido, .furin-download-button__listo { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; transition: opacity 0.25s ease, transform 0.5s var(--furin-dl-ease); }\n.furin-download-button__flecha { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.4s var(--furin-dl-ease); }\n.furin-download-button__boton:hover .furin-download-button__flecha { transform: translateY(2px); }\n.is-bajando .furin-download-button__contenido { opacity: 0; transform: scale(0.85); }\n.is-listo .furin-download-button__contenido { opacity: 0; transform: translateY(-14px); }\n\n.furin-download-button__listo { opacity: 0; transform: translateY(14px); }\n.is-listo .furin-download-button__listo { opacity: 1; transform: none; transition-delay: 0.12s; }\n.furin-download-button__listo svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }\n.furin-download-button__listo path { stroke-dasharray: 1; stroke-dashoffset: 1; }\n.is-listo .furin-download-button__listo path { stroke-dashoffset: 0; transition: stroke-dashoffset 0.45s cubic-bezier(0.65, 0, 0.35, 1) 0.3s; }\n\n@media (prefers-reduced-motion: reduce) {\n  .furin-download-button__boton, .furin-download-button__info, .furin-download-button__contenido, .furin-download-button__listo, .furin-download-button__flecha, .furin-download-button__listo path { transition: none !important; }\n}\n",
      "type": "registry:file",
      "target": "components/furin/download-button/DownloadButton.css"
    }
  ]
}
