{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"horizontal-numbered-stepper-with-back-and-next","type":"registry:component","title":"Horizontal Numbered Stepper With Back and Next","description":"Free stepper component in React and plain HTML: numbered steps joined by lines that fill as you go, real Back and Next buttons and aria-current on the step.","dependencies":[],"files":[{"path":"components/we-inc/horizontal-numbered-stepper-with-back-and-next.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Steps of a shop set-up form. Each has a short label and the text shown below.\nconst steps = [\n  { label: \"Account\", title: \"Create your account\", body: \"Use the email you check most. We send order alerts and payout notices there.\" },\n  { label: \"Shop\", title: \"Name your shop\", body: \"Pick a name and a short description. You can change both later from Settings.\" },\n  { label: \"Payouts\", title: \"Connect a bank account\", body: \"Sales are paid out every Friday. We only need your account and sort code.\" },\n  { label: \"Review\", title: \"Check and open your shop\", body: \"Look over your details. When you open the shop, your first product page goes live.\" },\n];\n\nexport default function HorizontalNumberedStepperWithBackAndNext() {\n  const [current, setCurrent] = useState(1);\n  const heading = useRef<HTMLHeadingElement>(null);\n  const moved = useRef(false);\n  const last = steps.length - 1;\n\n  // Move focus to the new step's heading after Back or Next (not on first render).\n  useEffect(() => {\n    if (moved.current) heading.current?.focus();\n  }, [current]);\n\n  const go = (i: number) => {\n    moved.current = true;\n    setCurrent(Math.max(0, Math.min(last, i)));\n  };\n\n  return (\n    <div className=\"bg-blue-50 px-4 py-12 sm:px-8\">\n      <div className=\"mx-auto max-w-2xl rounded-2xl bg-white p-6 shadow-sm ring-1 ring-blue-100 sm:p-8\">\n        <ol className=\"flex items-start\">\n          {steps.map((s, i) => {\n            const done = i < current;\n            const now = i === current;\n            return (\n              <li key={s.label} aria-current={now ? \"step\" : undefined} className=\"relative flex flex-1 flex-col items-center\">\n                {i < last && (\n                  <span aria-hidden=\"true\" className=\"absolute left-[calc(50%+20px)] right-[calc(-50%+20px)] top-4 h-0.5 overflow-hidden rounded bg-slate-200\">\n                    <span className={`block h-full origin-left bg-blue-600 transition-transform duration-500 ease-out motion-reduce:transition-none ${done ? \"scale-x-100\" : \"scale-x-0\"}`} />\n                  </span>\n                )}\n                <button\n                  type=\"button\"\n                  disabled={i > current}\n                  onClick={() => go(i)}\n                  className={`relative z-10 grid h-9 w-9 place-items-center rounded-full text-sm font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 ${done ? \"bg-blue-600 text-white hover:bg-blue-700\" : now ? \"bg-white text-blue-700 ring-2 ring-blue-600\" : \"bg-slate-100 text-slate-600\"}`}\n                >\n                  {done ? (\n                    <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M5 12l5 5 9-10\" /></svg>\n                  ) : (\n                    i + 1\n                  )}\n                  <span className=\"sr-only\">{`${s.label}, ${done ? \"completed\" : now ? \"current step\" : \"not started\"}`}</span>\n                </button>\n                <span className={`mt-2 text-xs font-medium sm:text-sm ${now ? \"text-slate-900\" : \"text-slate-600\"}`} aria-hidden=\"true\">{s.label}</span>\n              </li>\n            );\n          })}\n        </ol>\n\n        <div className=\"mt-8 min-h-[96px]\">\n          <p className=\"text-sm font-medium text-blue-700\">Step {current + 1} of {steps.length}</p>\n          <h2 ref={heading} tabIndex={-1} className=\"mt-1 rounded text-xl font-semibold text-slate-900 focus:outline-none\">{steps[current].title}</h2>\n          <p className=\"mt-2 text-slate-600\">{steps[current].body}</p>\n        </div>\n\n        <div className=\"mt-6 flex justify-between border-t border-slate-100 pt-5\">\n          <button type=\"button\" onClick={() => go(current - 1)} disabled={current === 0} className=\"h-11 rounded-lg px-4 text-sm font-medium text-slate-700 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600\">Back</button>\n          <button type=\"button\" onClick={() => go(current + 1)} className=\"h-11 rounded-lg bg-blue-600 px-5 text-sm font-semibold text-white hover:bg-blue-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2\">\n            {current === last ? \"Open shop\" : \"Next\"}\n          </button>\n        </div>\n      </div>\n    </div>\n  );\n}\n"}]}
