{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "multi-step-loader",
  "title": "Multi-step loader",
  "description": "Card or overlay that ticks through steps like \"Reserving slot…\" with spinners, drawn checkmarks and a filling rail, ending on an animated success state.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json",
    "https://goodui.dev/r/success-check.json"
  ],
  "files": [
    {
      "path": "registry/components/feedback/multi-step-loader.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { SuccessCheck } from \"@/components/goodui/success-check\"\nimport { GooduiTokens, ease, spring as springs } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n@keyframes pc-multi-step-loader-spin { to { transform: rotate(360deg) } }\n.pc-multi-step-loader-spin { animation: pc-multi-step-loader-spin .8s linear infinite; transform-box: view-box; transform-origin: center; }\n@media (prefers-reduced-motion: reduce) { .pc-multi-step-loader-spin { animation-duration: 2.4s } }\n`\n\nexport type MultiStep = string | { label: React.ReactNode; description?: React.ReactNode }\n\n/** Built-in text: the \"Step x of n\" line (also read by screen readers) and the fallback \"Done\" announcement. */\nexport type MultiStepLoaderLabels = { stepOf: (step: number, count: number) => string; done: string }\nconst DEFAULT_LABELS: MultiStepLoaderLabels = { stepOf: (step, count) => `Step ${step} of ${count}`, done: \"Done\" }\n\nconst FOCUSABLE =\n  'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])'\n\nexport type MultiStepLoaderProps = Omit<React.ComponentProps<\"div\">, \"children\" | \"title\"> & {\n  /** Steps in order: a string, or { label, description } where the description shows under the active step. */\n  steps: MultiStep[]\n  /** Controlled active step (0-based). steps.length means everything is done. */\n  step?: number\n  /** Auto-advance while true (uncontrolled only). */\n  running?: boolean\n  /** Ms per step when auto-advancing. A number per step is allowed. */\n  stepDuration?: number | number[]\n  /** Called with the new step index when auto-advancing (uncontrolled mode only). */\n  onStepChange?: (step: number) => void\n  /** Called once every step is done. */\n  onComplete?: () => void\n  /** Heading while the steps run. */\n  title?: React.ReactNode\n  /** Heading on the final success state, next to an animated check. */\n  successTitle?: React.ReactNode\n  /** Line under successTitle. */\n  successDescription?: React.ReactNode\n  /** Rendered under the success message, e.g. a \"View booking\" button. */\n  successAction?: React.ReactNode\n  /** \"overlay\" covers the page with a blurred backdrop and a centered card. */\n  variant?: \"card\" | \"overlay\"\n  /** \"line\" (default) is one surface whose text and width morph per step; \"list\" shows every step as a checklist. */\n  display?: \"line\" | \"list\"\n  /** Overlay only. */\n  open?: boolean\n  /** Overlay only. Esc and the backdrop close it once all steps are done. */\n  onOpenChange?: (open: boolean) => void\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<MultiStepLoaderLabels>\n}\n\nfunction normalize(s: MultiStep) {\n  return typeof s === \"string\" ? { label: s, description: undefined } : s\n}\n\n/** One ring for the whole run: the arc grows with progress, closes at the end and the check draws inside it. */\nfunction LineIcon({ progress, done, reduce }: { progress: number; done: boolean; reduce: boolean }) {\n  const [spin, setSpin] = React.useState(!done)\n  if (!done && !spin) setSpin(true)\n  return (\n    <motion.svg\n      viewBox=\"0 0 24 24\"\n      fill=\"none\"\n      aria-hidden=\"true\"\n      className={cn(\"size-6 shrink-0 overflow-visible transition-colors duration-300\", done ? \"text-emerald-600 dark:text-emerald-400\" : \"text-primary\")}\n      animate={done && !reduce ? { scale: [1, 1.14, 1] } : { scale: 1 }}\n      transition={{ duration: 0.42, delay: done ? 0.22 : 0, ease: ease.out }}\n    >\n      <motion.circle cx=\"12\" cy=\"12\" r=\"11\" fill=\"currentColor\" initial={false} animate={{ opacity: done ? 0.16 : 0 }} transition={{ duration: reduce ? 0 : 0.3 }} />\n      <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeOpacity=\".16\" strokeWidth=\"2.5\" />\n      <g className={spin ? \"pc-multi-step-loader-spin\" : undefined}>\n        <motion.circle\n          cx=\"12\"\n          cy=\"12\"\n          r=\"9\"\n          stroke=\"currentColor\"\n          strokeWidth=\"2.5\"\n          strokeLinecap=\"round\"\n          transform=\"rotate(-90 12 12)\"\n          initial={false}\n          animate={{ pathLength: done ? 1 : Math.max(0.2, progress) }}\n          transition={reduce ? { duration: 0 } : { duration: 0.36, ease: ease.out }}\n          onAnimationComplete={() => {\n            if (done) setSpin(false)\n          }}\n        />\n      </g>\n      <motion.path\n        d=\"M7.5 12.5l3 3 6-6.5\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2.5\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        initial={{ pathLength: 0, opacity: 0 }}\n        animate={{ pathLength: done ? 1 : 0, opacity: done ? 1 : 0 }}\n        transition={reduce ? { duration: 0 } : { duration: 0.26, delay: done ? 0.22 : 0, ease: ease.out, opacity: { duration: 0.01, delay: done ? 0.22 : 0 } }}\n      />\n    </motion.svg>\n  )\n}\n\nfunction StepIcon({ state, index, reduce }: { state: \"done\" | \"active\" | \"pending\"; index: number; reduce: boolean }) {\n  return (\n    <span className=\"relative grid size-6 shrink-0 place-items-center\">\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        {state === \"done\" ? (\n          <motion.span\n            key=\"done\"\n            className=\"absolute inset-0 grid place-items-center rounded-full bg-emerald-500 text-white dark:bg-emerald-500\"\n            initial={reduce ? { opacity: 0 } : { scale: 0.4, opacity: 0 }}\n            animate={{ scale: 1, opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={reduce ? { duration: 0 } : springs.play}\n          >\n            <svg viewBox=\"0 0 24 24\" className=\"size-3.5\" fill=\"none\" aria-hidden=\"true\">\n              <motion.path\n                d=\"M5 12.5l4.5 4.5L19 7.5\"\n                stroke=\"currentColor\"\n                strokeWidth={3}\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                initial={{ pathLength: reduce ? 1 : 0, opacity: reduce ? 1 : 0 }}\n                animate={{ pathLength: 1, opacity: 1 }}\n                transition={reduce ? { duration: 0 } : { duration: 0.28, delay: 0.08, ease: \"easeOut\", opacity: { duration: 0.01, delay: 0.08 } }}\n              />\n            </svg>\n          </motion.span>\n        ) : state === \"active\" ? (\n          <motion.span key=\"active\" className=\"absolute inset-0\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}>\n            <svg viewBox=\"0 0 24 24\" className=\"pc-multi-step-loader-spin size-6 text-primary\" fill=\"none\" aria-hidden=\"true\">\n              <circle cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" strokeOpacity=\".18\" strokeWidth=\"2.5\" />\n              <path d=\"M22 12A10 10 0 0 0 12 2\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" />\n            </svg>\n          </motion.span>\n        ) : (\n          <motion.span\n            key=\"pending\"\n            className=\"absolute inset-0 grid place-items-center rounded-full border text-[11px] font-medium text-muted-foreground\"\n            exit={{ opacity: 0 }}\n          >\n            {index + 1}\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  )\n}\n\nfunction LoaderCard({\n  steps,\n  step: stepProp,\n  running = true,\n  stepDuration = 1100,\n  onStepChange,\n  onComplete,\n  title = \"Working on it\",\n  successTitle = \"All done\",\n  successDescription,\n  successAction,\n  titleId,\n  display = \"line\",\n  labels,\n  className,\n  ...props\n}: Omit<MultiStepLoaderProps, \"variant\" | \"open\" | \"onOpenChange\"> & { titleId?: string }) {\n  const l = useLabels(\"multi-step-loader\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const [internal, setInternal] = React.useState(0)\n  const controlled = stepProp !== undefined\n  const step = Math.min(controlled ? stepProp : internal, steps.length)\n  const done = step >= steps.length\n  const items = steps.map(normalize)\n\n  const changeRef = React.useRef(onStepChange)\n  const completeRef = React.useRef(onComplete)\n  React.useEffect(() => {\n    changeRef.current = onStepChange\n    completeRef.current = onComplete\n  })\n\n  // Depend on the number, not the array, so an inline array does not restart the timer on every render.\n  const ms = Array.isArray(stepDuration) ? (stepDuration[internal] ?? 1100) : stepDuration\n  React.useEffect(() => {\n    if (controlled || !running || internal >= steps.length) return\n    const id = window.setTimeout(() => {\n      setInternal((s) => s + 1)\n      changeRef.current?.(internal + 1)\n    }, ms)\n    return () => window.clearTimeout(id)\n  }, [controlled, running, internal, steps.length, ms])\n\n  React.useEffect(() => {\n    if (done) completeRef.current?.()\n  }, [done])\n\n  const spring = reduce ? { duration: 0 } : springs.morph\n  const current = items[step]\n\n  if (display === \"line\") {\n    const shown = done ? { label: successTitle, description: successDescription } : current\n    const swap = {\n      initial: reduce ? { opacity: 0 } : { opacity: 0, y: 12, filter: \"blur(4px)\" },\n      animate: { opacity: 1, y: 0, filter: \"blur(0px)\" },\n      exit: reduce ? { opacity: 0 } : { opacity: 0, y: -12, filter: \"blur(4px)\" },\n    }\n    return (\n      <motion.div\n        layout\n        transition={spring}\n        style={{ borderRadius: 18 }}\n        className={cn(\"relative mx-auto w-fit max-w-[min(24rem,100%)] min-w-60 overflow-hidden bg-card text-card-foreground shadow-[var(--pc-e2)]\", className)}\n        {...(props as React.ComponentProps<typeof motion.div>)}\n      >\n        <GooduiTokens />\n        <style href=\"pc-multi-step-loader\" precedence=\"default\">\n          {CSS}\n        </style>\n        <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">\n          {done ? (typeof successTitle === \"string\" ? successTitle : l.done) : typeof current?.label === \"string\" ? current.label : l.stepOf(step + 1, steps.length)}\n        </span>\n        <span id={titleId} className=\"sr-only\">\n          {done ? successTitle : title}\n        </span>\n        <motion.div layout=\"position\" transition={spring} className=\"flex items-center gap-3 py-3 ps-3.5 pe-4\">\n          <LineIcon progress={steps.length ? (step + 1) / steps.length : 0} done={done} reduce={reduce} />\n          <div className=\"relative min-w-0\">\n            <AnimatePresence mode=\"popLayout\" initial={false}>\n              <motion.div key={done ? \"done\" : step} {...swap} transition={{ duration: reduce ? 0 : 0.24, ease: ease.out }}>\n                <div className=\"text-sm leading-5 font-medium\">{shown?.label}</div>\n                {shown?.description && <div className=\"text-xs leading-4 text-muted-foreground\">{shown.description}</div>}\n              </motion.div>\n            </AnimatePresence>\n          </div>\n          {!done && <span className=\"ms-auto shrink-0 ps-2 text-xs text-muted-foreground tabular-nums\">{l.stepOf(step + 1, steps.length)}</span>}\n        </motion.div>\n        {done && successAction && (\n          <motion.div\n            className=\"flex justify-end gap-2 border-t border-[var(--pc-hair)] px-3 py-2.5\"\n            initial={reduce ? { opacity: 0 } : { opacity: 0, filter: \"blur(4px)\" }}\n            animate={{ opacity: 1, filter: \"blur(0px)\" }}\n            transition={{ duration: reduce ? 0 : 0.24, delay: reduce ? 0 : 0.2 }}\n          >\n            {successAction}\n          </motion.div>\n        )}\n        <motion.div\n          aria-hidden=\"true\"\n          className={cn(\"absolute inset-x-0 bottom-0 h-0.5 origin-left rtl:origin-right\", done ? \"bg-emerald-500\" : \"bg-primary\")}\n          initial={false}\n          animate={{ scaleX: steps.length ? step / steps.length : 0, opacity: done ? 0 : 1 }}\n          transition={reduce ? { duration: 0 } : { scaleX: spring, opacity: { duration: 0.3, delay: 0.3 } }}\n        />\n      </motion.div>\n    )\n  }\n\n  return (\n    <div className={cn(\"w-full max-w-sm overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-[var(--pc-e1)]\", className)} {...props}>\n      <GooduiTokens />\n      <style href=\"pc-multi-step-loader\" precedence=\"default\">\n        {CSS}\n      </style>\n      <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">\n        {done ? (typeof successTitle === \"string\" ? successTitle : l.done) : typeof current?.label === \"string\" ? current.label : l.stepOf(step + 1, steps.length)}\n      </span>\n\n      <div className=\"relative overflow-hidden border-b px-5 pt-5 pb-4\">\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          {done ? (\n            <motion.div\n              key=\"done\"\n              className=\"flex items-center gap-3\"\n              initial={reduce ? { opacity: 0 } : { opacity: 0, y: 12 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={{ opacity: 0 }}\n              transition={spring}\n            >\n              <SuccessCheck size={40} />\n              <div className=\"min-w-0\">\n                <div id={titleId} className=\"font-semibold\">\n                  {successTitle}\n                </div>\n                {successDescription && <div className=\"text-sm text-muted-foreground\">{successDescription}</div>}\n              </div>\n            </motion.div>\n          ) : (\n            <motion.div key=\"progress\" initial={false} exit={reduce ? { opacity: 0 } : { opacity: 0, y: -12 }} transition={spring}>\n              <div id={titleId} className=\"font-semibold\">\n                {title}\n              </div>\n              <div className=\"mt-0.5 text-sm text-muted-foreground tabular-nums\">{l.stepOf(Math.min(step + 1, steps.length), steps.length)}</div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n        <div className=\"absolute inset-x-0 bottom-0 h-0.5 bg-muted\">\n          <motion.div\n            className={cn(\"h-full origin-left rtl:origin-right\", done ? \"bg-emerald-500\" : \"bg-primary\")}\n            initial={false}\n            animate={{ scaleX: steps.length ? step / steps.length : 0 }}\n            transition={spring}\n          />\n        </div>\n      </div>\n\n      <ol className=\"px-5 py-4\">\n        {items.map((s, i) => {\n          const state = i < step ? \"done\" : i === step ? \"active\" : \"pending\"\n          return (\n            <li key={i} className=\"relative flex gap-3 pb-4 last:pb-0\">\n              {i < items.length - 1 && (\n                <span aria-hidden=\"true\" className=\"absolute start-[11px] top-7 bottom-1 w-0.5 overflow-hidden rounded-full bg-muted\">\n                  <motion.span\n                    className=\"block h-full w-full origin-top bg-emerald-500\"\n                    initial={false}\n                    animate={{ scaleY: i < step ? 1 : 0 }}\n                    transition={reduce ? { duration: 0 } : { duration: 0.35, ease: \"easeOut\", delay: 0.1 }}\n                  />\n                </span>\n              )}\n              <StepIcon state={state} index={i} reduce={reduce} />\n              <div className=\"min-w-0 flex-1 pt-0.5\">\n                <div\n                  className={cn(\n                    \"text-sm transition-colors duration-300\",\n                    state === \"active\" ? \"font-medium text-foreground\" : state === \"done\" ? \"text-foreground/80\" : \"text-muted-foreground\",\n                  )}\n                >\n                  {s.label}\n                </div>\n                <AnimatePresence initial={false}>\n                  {state === \"active\" && s.description && (\n                    <motion.div\n                      key=\"desc\"\n                      className=\"overflow-hidden text-xs text-muted-foreground\"\n                      initial={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}\n                      animate={reduce ? { opacity: 1 } : { height: \"auto\", opacity: 1 }}\n                      exit={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}\n                      transition={reduce ? { duration: 0 } : { duration: 0.22, ease: \"easeOut\" }}\n                    >\n                      <div className=\"pt-0.5\">{s.description}</div>\n                    </motion.div>\n                  )}\n                </AnimatePresence>\n              </div>\n            </li>\n          )\n        })}\n      </ol>\n\n      <AnimatePresence initial={false}>\n        {done && successAction && (\n          <motion.div\n            key=\"action\"\n            className=\"overflow-hidden\"\n            initial={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}\n            animate={reduce ? { opacity: 1 } : { height: \"auto\", opacity: 1 }}\n            transition={reduce ? { duration: 0 } : { duration: 0.25, ease: \"easeOut\", delay: 0.2 }}\n          >\n            <div className=\"flex justify-end gap-2 border-t px-5 py-3\">{successAction}</div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  )\n}\n\n/**\n * One line that morphs through the steps, its ring closing into a check at the end; display=\"list\" is the checklist form.\n * Inline card or overlay.\n * The overlay is a modal dialog: it takes focus, traps Tab inside and gives focus back when it closes.\n */\nexport function MultiStepLoader({ variant = \"card\", open = true, onOpenChange, ...props }: MultiStepLoaderProps) {\n  const reduce = useReducedMotion() ?? false\n  const titleId = React.useId()\n  const dialogRef = React.useRef<HTMLDivElement>(null)\n  const [finished, setFinished] = React.useState(false)\n  const { onComplete } = props\n\n  React.useEffect(() => {\n    if (variant !== \"overlay\" || !open) return\n    setFinished(false)\n    const previous = document.activeElement as HTMLElement | null\n    dialogRef.current?.focus()\n    return () => previous?.focus?.()\n  }, [variant, open])\n\n  if (variant === \"card\") return <LoaderCard {...props} />\n\n  const close = () => {\n    if (finished) onOpenChange?.(false)\n  }\n\n  return (\n    <AnimatePresence>\n      <GooduiTokens />\n      {open && (\n        <motion.div\n          key=\"overlay\"\n          className=\"fixed inset-0 z-50 grid place-items-center bg-background/60 p-4 backdrop-blur-sm\"\n          initial={{ opacity: 0 }}\n          animate={{ opacity: 1 }}\n          exit={{ opacity: 0 }}\n          transition={{ duration: reduce ? 0 : 0.2 }}\n          onClick={(e) => {\n            if (e.target === e.currentTarget) close()\n          }}\n        >\n          <motion.div\n            ref={dialogRef}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-labelledby={titleId}\n            tabIndex={-1}\n            className=\"w-full max-w-sm outline-none\"\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\") {\n                e.stopPropagation()\n                close()\n                return\n              }\n              // Keep Tab inside the modal; with nothing focusable yet, focus stays on the dialog itself.\n              if (e.key !== \"Tab\" || !dialogRef.current) return\n              const items = Array.from(dialogRef.current.querySelectorAll<HTMLElement>(FOCUSABLE))\n              if (!items.length) return e.preventDefault()\n              const first = items[0]!\n              const last = items[items.length - 1]!\n              const active = document.activeElement\n              if (e.shiftKey && (active === first || active === dialogRef.current)) {\n                e.preventDefault()\n                last.focus()\n              } else if (!e.shiftKey && active === last) {\n                e.preventDefault()\n                first.focus()\n              }\n            }}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.95, y: 8 }}\n            animate={{ opacity: 1, scale: 1, y: 0 }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.97 }}\n            transition={reduce ? { duration: 0 } : springs.ui}\n          >\n            <LoaderCard\n              {...props}\n              titleId={titleId}\n              className={cn(\"shadow-[var(--pc-e3)]\", props.className)}\n              onComplete={() => {\n                setFinished(true)\n                onComplete?.()\n              }}\n            />\n          </motion.div>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/multi-step-loader.tsx"
    }
  ],
  "categories": [
    "components",
    "feedback"
  ],
  "type": "registry:component"
}
