{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "loader-button-progress",
  "type": "registry:component",
  "title": "Loader Button Progress",
  "description": "A button that collapses into a thin progress bar on click, with the status and percentage riding above it. At 100 percent it grows back into a success pill and draws a check.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "loaders",
    "button",
    "progress",
    "deploy",
    "morph",
    "success",
    "interactive"
  ],
  "docs": "https://hyperblur.dev/effects/loader-button-progress",
  "files": [
    {
      "path": "registry/hyperblur/loader-button-progress.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/loader-button-progress.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\ntype Phase = \"idle\" | \"busy\" | \"done\";\n\nexport interface LoaderButtonProgressProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onClick\" | \"value\"> {\n  label?: string;\n  busyLabel?: string;\n  doneLabel?: string;\n  value?: number;\n  duration?: number;\n  resetAfter?: number;\n  autoPlay?: boolean;\n  width?: number;\n  accent?: string;\n  success?: string;\n  onStart?: () => void;\n  onComplete?: () => void;\n}\n\nconst curve: [number, number][] = [\n  [0, 0],\n  [0.22, 0.24],\n  [0.4, 0.33],\n  [0.7, 0.71],\n  [0.82, 0.78],\n  [1, 1],\n];\n\nfunction sample(t: number) {\n  for (let i = 1; i < curve.length; i++) {\n    if (t <= curve[i][0]) {\n      const [t0, v0] = curve[i - 1];\n      const [t1, v1] = curve[i];\n      const f = (t - t0) / (t1 - t0 || 1);\n      return v0 + (v1 - v0) * f * f * (3 - 2 * f);\n    }\n  }\n  return 1;\n}\n\nconst css = `\n.hb-vk12 {\n  position: relative;\n  display: inline-block;\n  width: var(--hb-vk12-w);\n  max-width: 100%;\n  height: 46px;\n  padding: 0;\n  margin: 0;\n  border: 0;\n  background: none;\n  color: #0a0a0a;\n  font: inherit;\n  font-size: 14px;\n  font-weight: 600;\n  letter-spacing: -0.005em;\n  cursor: pointer;\n  box-sizing: border-box;\n  -webkit-tap-highlight-color: transparent;\n  outline: none;\n  vertical-align: middle;\n}\n.hb-vk12 *, .hb-vk12 *::before, .hb-vk12 *::after { box-sizing: border-box; }\n.hb-vk12[data-phase=\"busy\"] { cursor: progress; }\n.hb-vk12:disabled { cursor: not-allowed; opacity: 0.5; }\n.hb-vk12-body {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 0;\n  bottom: 0;\n  border-radius: 999px;\n  overflow: hidden;\n  background: linear-gradient(180deg, #ffffff, #e4e4e4);\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -1px 0 rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.5), 0 8px 22px -8px rgba(255,255,255,0.25);\n  transition: top 520ms cubic-bezier(0.65, 0, 0.35, 1), background 360ms ease, box-shadow 360ms ease, transform 160ms ease;\n}\n.hb-vk12:hover .hb-vk12-body { box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.5), 0 10px 28px -8px rgba(255,255,255,0.4); }\n.hb-vk12:active[data-phase=\"idle\"] .hb-vk12-body { transform: scale(0.97); }\n.hb-vk12:focus-visible .hb-vk12-body { outline: 2px solid var(--hb-vk12-a); outline-offset: 3px; }\n.hb-vk12[data-phase=\"busy\"] .hb-vk12-body {\n  top: calc(100% - 6px);\n  background: #1c1c1c;\n  box-shadow: inset 0 1px 1px rgba(0,0,0,0.6), inset 0 0 0 1px #262626;\n}\n.hb-vk12[data-phase=\"done\"] .hb-vk12-body {\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-vk12-s) 88%, #fff), var(--hb-vk12-s));\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), 0 1px 2px rgba(0,0,0,0.5), 0 10px 26px -10px var(--hb-vk12-s);\n}\n.hb-vk12-fill {\n  position: absolute;\n  left: 0;\n  top: 0;\n  bottom: 0;\n  width: var(--hb-vk12-p);\n  border-radius: 999px;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-vk12-a) 60%, #0a0a0a), var(--hb-vk12-a));\n  box-shadow: 0 0 10px var(--hb-vk12-a);\n  opacity: 0;\n  transition: opacity 200ms ease;\n}\n.hb-vk12-fill::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.7), transparent);\n  background-size: 40% 100%;\n  background-repeat: no-repeat;\n  animation: hb-vk12-shine 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;\n}\n.hb-vk12[data-phase=\"busy\"] .hb-vk12-fill { opacity: 1; transition-delay: 300ms; }\n.hb-vk12-face {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  white-space: nowrap;\n  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1), opacity 260ms ease;\n}\n.hb-vk12-face svg { width: 16px; height: 16px; flex: none; }\n.hb-vk12-idle { opacity: 1; }\n.hb-vk12[data-phase=\"busy\"] .hb-vk12-idle, .hb-vk12[data-phase=\"done\"] .hb-vk12-idle { opacity: 0; transform: translateY(-10px); }\n.hb-vk12-busy {\n  inset: 0 2px auto 2px;\n  height: 34px;\n  justify-content: space-between;\n  color: #ededed;\n  font-size: 12.5px;\n  font-weight: 500;\n  opacity: 0;\n  transform: translateY(8px);\n}\n.hb-vk12-busy b { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--hb-vk12-a); }\n.hb-vk12[data-phase=\"busy\"] .hb-vk12-busy { opacity: 1; transform: none; transition-delay: 160ms; }\n.hb-vk12-done { color: #04130b; opacity: 0; transform: translateY(10px); }\n.hb-vk12[data-phase=\"done\"] .hb-vk12-done { opacity: 1; transform: none; transition-delay: 220ms; }\n.hb-vk12-done path {\n  stroke-dasharray: 16;\n  stroke-dashoffset: 16;\n}\n.hb-vk12[data-phase=\"done\"] .hb-vk12-done path {\n  stroke-dashoffset: 0;\n  transition: stroke-dashoffset 420ms cubic-bezier(0.65, 0, 0.35, 1) 380ms;\n}\n.hb-vk12-dots { display: inline-flex; gap: 3px; margin-left: 2px; }\n.hb-vk12-dots span {\n  width: 3px;\n  height: 3px;\n  border-radius: 50%;\n  background: currentColor;\n  animation: hb-vk12-dot 1.1s ease-in-out infinite;\n}\n.hb-vk12-dots span:nth-child(2) { animation-delay: 0.15s; }\n.hb-vk12-dots span:nth-child(3) { animation-delay: 0.3s; }\n.hb-vk12-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@keyframes hb-vk12-shine { from { background-position: -60% 0; } to { background-position: 160% 0; } }\n@keyframes hb-vk12-dot { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-vk12-body, .hb-vk12-face, .hb-vk12-fill, .hb-vk12-done path { transition: none !important; }\n  .hb-vk12-fill::after, .hb-vk12-dots span { animation: none; }\n}\n`;\n\nexport function LoaderButtonProgress({\n  label = \"Deploy\",\n  busyLabel = \"Deploying\",\n  doneLabel = \"Deployed\",\n  value,\n  duration = 3400,\n  resetAfter = 2200,\n  autoPlay = false,\n  width = 220,\n  accent = \"#2f7bff\",\n  success = \"#3ecf8e\",\n  onStart,\n  onComplete,\n  disabled,\n  className = \"\",\n  style,\n  ...rest\n}: LoaderButtonProgressProps) {\n  const controlled = typeof value === \"number\" && Number.isFinite(value);\n  const [phase, setPhase] = React.useState<Phase>(\"idle\");\n  const [auto, setAuto] = React.useState(0);\n  const completeRef = React.useRef(onComplete);\n  const startRef = React.useRef(onStart);\n\n  React.useEffect(() => {\n    completeRef.current = onComplete;\n    startRef.current = onStart;\n  }, [onComplete, onStart]);\n\n  const start = React.useCallback(() => {\n    setAuto(0);\n    setPhase(\"busy\");\n    startRef.current?.();\n  }, []);\n\n  React.useEffect(() => {\n    if (phase !== \"busy\") return;\n    let raf = 0;\n    if (controlled) {\n      if ((value as number) >= 100) {\n        raf = requestAnimationFrame(() => {\n          setPhase(\"done\");\n          completeRef.current?.();\n        });\n      }\n      return () => cancelAnimationFrame(raf);\n    }\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const total = reduce ? 600 : Math.max(800, duration);\n    let t0 = 0;\n    function tick(now: number) {\n      if (!t0) t0 = now;\n      const t = Math.min(1, (now - t0) / total);\n      setAuto(sample(t) * 100);\n      if (t >= 1) {\n        setPhase(\"done\");\n        completeRef.current?.();\n        return;\n      }\n      raf = requestAnimationFrame(tick);\n    }\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n  }, [phase, controlled, value, duration]);\n\n  React.useEffect(() => {\n    if (phase !== \"done\" || resetAfter <= 0) return;\n    const id = window.setTimeout(() => setPhase(\"idle\"), resetAfter);\n    return () => window.clearTimeout(id);\n  }, [phase, resetAfter]);\n\n  React.useEffect(() => {\n    if (!autoPlay || phase !== \"idle\" || disabled) return;\n    const id = window.setTimeout(start, 1100);\n    return () => window.clearTimeout(id);\n  }, [autoPlay, phase, disabled, start]);\n\n  const pct = Math.min(100, Math.max(0, controlled ? (value as number) : auto));\n  const vars = {\n    \"--hb-vk12-w\": `${width}px`,\n    \"--hb-vk12-p\": `${pct.toFixed(1)}%`,\n    \"--hb-vk12-a\": accent,\n    \"--hb-vk12-s\": success,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-loader-button-progress\" precedence=\"default\">{css}</style>\n      <button\n        type=\"button\"\n        className={`hb-vk12 ${className}`}\n        data-phase={phase}\n        disabled={disabled}\n        aria-disabled={phase !== \"idle\" || undefined}\n        aria-busy={phase === \"busy\"}\n        style={vars}\n        onClick={() => {\n          if (phase === \"idle\") start();\n        }}\n        {...rest}\n      >\n        <span className=\"hb-vk12-body\" aria-hidden=\"true\">\n          <span className=\"hb-vk12-fill\" />\n        </span>\n        <span className=\"hb-vk12-face hb-vk12-idle\" aria-hidden={phase !== \"idle\"}>\n          <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M4.5 12.5h-.3a3.2 3.2 0 0 1-.4-6.4 4.3 4.3 0 0 1 8.3-.6 3.1 3.1 0 0 1 .2 6.2\" />\n            <path d=\"M8 13.5V8.2M5.9 10.1 8 8l2.1 2.1\" />\n          </svg>\n          {label}\n        </span>\n        <span className=\"hb-vk12-face hb-vk12-busy\" aria-hidden=\"true\">\n          <span>\n            {busyLabel}\n            <span className=\"hb-vk12-dots\">\n              <span />\n              <span />\n              <span />\n            </span>\n          </span>\n          <b>{Math.floor(pct)}%</b>\n        </span>\n        <span className=\"hb-vk12-face hb-vk12-done\" aria-hidden=\"true\">\n          <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n            <path d=\"M3.5 8.4l3 3 6-6.4\" />\n          </svg>\n          {doneLabel}\n        </span>\n        <span className=\"hb-vk12-sr\" aria-live=\"polite\">\n          {phase === \"busy\" ? busyLabel : phase === \"done\" ? doneLabel : \"\"}\n        </span>\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}