# Stepper

> Ordered list of named steps with check marks for finished ones, a ringed current step and connecting lines.

- Kind: ui · Category: Navigation · Interactivity: script
- Install: `npx shadcn@latest add @haze/stepper`
- File: `src/components/haze/ui/stepper.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/stepper

## Use when
- Checkout, onboarding or setup flows with a fixed number of named steps
- Showing the reader how far along they are and what is left
- Horizontal on wide screens that must stack vertically on a phone

## Avoid when
- A single percentage; use progress
- Steps the reader can open in any order; use tabs

## Alternatives
- [progress](https://hazeui.com/ui/progress.md)
- [tabs](https://hazeui.com/ui/tabs.md)
- [breadcrumb](https://hazeui.com/ui/breadcrumb.md)
- [timeline](https://hazeui.com/ui/timeline.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| steps | `{ title: string; description?: string }[]` |  | yes | Steps in order, each with a title and an optional one-line description. |
| current | `number` |  | yes | 0-based index of the current step; earlier steps are complete. |
| orientation | `"horizontal" \| "vertical"` | "horizontal" | no | Horizontal rows up from sm; below sm both orientations stack. |
| label | `string` | "Progress" | no | Accessible name of the list. |
| completedLabel | `string` | "Completed" | no | Screen-reader text placed before the title of a finished step; a colon is added. Translate it together with label. |
| class | `string` |  | no | Extra classes on the list. |

## Accessibility
- The current step has aria-current="step"; finished steps start with hidden text (completedLabel, "Completed: " by default) so the check icon is not the only signal.
- Step numbers and check icons are aria-hidden; the title text is what is read out.
- The list has role="list" so Safari keeps its list semantics.
- In forced-colors mode backgrounds vanish, so each marker gets a border: thick for the current step, medium with a check for finished steps and dashed for upcoming ones.
- It is a plain ordered list of text, not a set of buttons, so it reports progress but does not navigate.

## Agent prompts

### Install and use

Install the Haze UI component "Stepper" with `npx shadcn@latest add @haze/stepper`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Stepper from "@/components/haze/ui/stepper.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/stepper.md

### Customize with real content

Adapt the Haze stepper ui for our product. Replace the demo values of these props with our real content: steps, current, orientation, label, completedLabel, class. Keep the layout, the heading level rules and these accessibility details: The current step has aria-current="step"; finished steps start with hidden text (completedLabel, "Completed: " by default) so the check icon is not the only signal. Step numbers and check icons are aria-hidden; the title text is what is read out. The list has role="list" so Safari keeps its list semantics. In forced-colors mode backgrounds vanish, so each marker gets a border: thick for the current step, medium with a check for finished steps and dashed for upcoming ones. It is a plain ordered list of text, not a set of buttons, so it reports progress but does not navigate. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using stepper, check it fits: use it when checkout, onboarding or setup flows with a fixed number of named steps; showing the reader how far along they are and what is left; horizontal on wide screens that must stack vertically on a phone. Avoid it when a single percentage; use progress; steps the reader can open in any order; use tabs. Alternatives: @haze/progress, @haze/tabs, @haze/breadcrumb, @haze/timeline.

## Example requests that should lead here
- Add a four-step checkout stepper with step two active
- Show a vertical setup stepper with a description under each step

## Source

```astro
---
import { Check } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Step {
  title: string;
  description?: string;
}

interface Props {
  steps: Step[];
  /** Index of the current step, 0-based. */
  current: number;
  orientation?: "horizontal" | "vertical";
  /** Accessible name of the list. */
  label?: string;
  /** Screen-reader text placed before the title of a finished step. */
  completedLabel?: string;
  class?: string;
}

const { steps, current, orientation = "horizontal", label = "Progress", completedLabel = "Completed", class: className } = Astro.props;
const horizontal = orientation === "horizontal";
const last = steps.length - 1;

const items = {
  horizontal: "flex gap-3 sm:flex-1 sm:flex-col sm:gap-2",
  vertical: "flex gap-3",
};
const rails = {
  horizontal: "flex flex-col items-center sm:w-full sm:flex-row",
  vertical: "flex flex-col items-center",
};
const lines = {
  horizontal: "min-h-6 w-px flex-1 sm:ml-2 sm:h-px sm:min-h-0 sm:w-auto",
  vertical: "min-h-6 w-px flex-1",
};
const texts = {
  horizontal: "pb-6 sm:pb-0 sm:pr-3",
  vertical: "pb-6",
};
---

<ol role="list" data-haze-stepper aria-label={label} class={cn("flex flex-col", horizontal && "sm:flex-row", className)}>
  {
    steps.map((step, i) => {
      const done = i < current;
      const active = i === current;
      return (
        <li aria-current={active ? "step" : undefined} data-state={done ? "done" : active ? "active" : "upcoming"} class={cn("group", items[orientation])}>
          <div class={rails[orientation]}>
            <span
              class={cn(
                "flex size-7 shrink-0 items-center justify-center rounded-full border border-transparent text-xs/4 font-medium tabular-nums transition-[background-color,border-color,color,box-shadow] duration-200 ease-snappy motion-reduce:transition-none",
                "bg-card text-muted-foreground inset-ring inset-ring-frame-strong forced-colors:border-dashed",
                "group-data-[state=active]:text-foreground group-data-[state=active]:inset-ring-2 group-data-[state=active]:inset-ring-foreground group-data-[state=active]:outline-4 group-data-[state=active]:-outline-offset-0 group-data-[state=active]:outline-muted group-data-[state=active]:forced-colors:border-4 group-data-[state=active]:forced-colors:border-solid",
                "group-data-[state=done]:bg-primary group-data-[state=done]:text-primary-foreground group-data-[state=done]:inset-ring-0 group-data-[state=done]:forced-colors:border-2 group-data-[state=done]:forced-colors:border-solid",
              )}
            >
              <Check class={cn("size-3.5", !done && "hidden", "group-data-[state=done]:block motion-safe:group-data-[pop]:animate-pop")} stroke-width={3} aria-hidden="true" />
              <span aria-hidden="true" class="group-data-[state=done]:hidden">{i + 1}</span>
            </span>
            {i < last && <span aria-hidden="true" class={cn("my-1 bg-border transition-[background-color] duration-300 ease-snappy group-data-[state=done]:bg-primary motion-reduce:transition-none", lines[orientation], "forced-colors:bg-[CanvasText]", horizontal && "sm:my-0 sm:mr-2")} />}
          </div>
          <div class={cn("min-w-0 pt-1", i === last && "pb-0", texts[orientation], i === last && "pb-0")}>
            <p class="text-[0.8125rem]/5 font-medium tracking-[-0.01em] text-muted-foreground transition-colors duration-200 ease-snappy group-data-[state=active]:text-foreground group-data-[state=done]:text-foreground motion-reduce:transition-none">
              <span class={cn("sr-only", !done && "hidden", "group-data-[state=done]:inline")}>{completedLabel}: </span>{step.title}
            </p>
            {step.description && <p class="mt-0.5 text-xs/5 text-muted-foreground">{step.description}</p>}
          </div>
        </li>
      );
    })
  }
</ol>

<script>
  // Steps that are done on load stay still; a step whose data-state changes to "done" later pops its check once.
  function initSteppers() {
    document.querySelectorAll<HTMLElement>("[data-haze-stepper]:not([data-enhanced])").forEach((root) => {
      root.setAttribute("data-enhanced", "");
      new MutationObserver((records) => {
        for (const record of records) {
          const step = record.target as HTMLElement;
          if (step.dataset.state !== "done" || record.oldValue === "done") continue;
          if (matchMedia("(prefers-reduced-motion: reduce)").matches) continue;
          step.setAttribute("data-pop", "");
          const svg = step.querySelector("svg");
          const clear = () => { clearTimeout(timer); step.removeAttribute("data-pop"); svg?.removeEventListener("animationend", clear); svg?.removeEventListener("animationcancel", clear); };
          const timer = window.setTimeout(clear, 370);
          svg?.addEventListener("animationend", clear);
          svg?.addEventListener("animationcancel", clear);
        }
      }).observe(root, { subtree: true, attributes: true, attributeFilter: ["data-state"], attributeOldValue: true });
    });
  }
  initSteppers();
  if (!document.documentElement.hasAttribute("data-haze-stepper-listener")) {
    document.documentElement.setAttribute("data-haze-stepper-listener", "");
    document.addEventListener("astro:page-load", initSteppers);
  }
</script>
```
