<!-- Generated by scripts/sync.mjs from templates/stepper.md and apps/playground/src/stepper. Do not edit. -->

# Stepper

A stepper shows where someone is in a multi-step process: onboarding, checkout, a long form split across pages. It's a row of numbered steps, each done, current or upcoming, joined by a line. Set doesn't ship one, so it's a gap to fill with the system: a Set component where one fits, custom markup for the rest, and tokens for every design value.

```tsx
import "./Stepper.css";

import { Icon } from "@monospaced/set-react";

type Step = { label: string; number: number };
type StepState = "current" | "done" | "upcoming";

export const steps: Step[] = [
  { number: 1, label: "Plan" },
  { number: 2, label: "Build" },
  { number: 3, label: "Ship" },
];

function getStepState(index: number, currentStep: number): StepState {
  if (currentStep >= steps.length) return "done";
  if (index < currentStep) return "done";
  if (index === currentStep) return "current";
  return "upcoming";
}

export function Stepper({ currentStep }: { currentStep: number }) {
  return (
    <ol className="app-stepper">
      {steps.map(({ number, label }, index) => {
        const state = getStepState(index, currentStep);

        return (
          <li
            key={number}
            className="step"
            data-state={state}
            {...(state === "current" ? { "aria-current": "step" } : {})}
          >
            <span className="bubble" aria-hidden="true">
              <span className="bubble-number">{number}</span>
              <span className="bubble-icon">
                <Icon name="check" size="xs" />
              </span>
            </span>
            <span className="label">
              {label}
              {state === "done" ? (
                <span className="visually-hidden">, completed</span>
              ) : null}
              {state === "current" ? (
                <span className="visually-hidden">, current step</span>
              ) : null}
            </span>
          </li>
        );
      })}
    </ol>
  );
}
```

```css
:where(.set) .app-stepper {
  --app-stepper-size: var(--set-spacing-vertical-800);

  display: flex;
  list-style: none;
  margin: 0;
  padding-inline: 0;

  .bubble {
    background-color: var(--set-color-background-subtle);
    block-size: var(--app-stepper-size);
    border-radius: calc(var(--app-stepper-size) * var(--set-radius-ratio-lg));
    color: var(--set-color-foreground-muted-text);
    display: grid;
    font: var(--set-typography-text-body-xs-font);
    font-variant-numeric: tabular-nums;
    font-variation-settings: var(
      --set-typography-font-variation-settings-default
    );
    font-weight: var(--set-typography-font-weight-bold);
    inline-size: var(--app-stepper-size);
    place-items: center;
    position: relative;
    transition:
      background-color var(--set-motion-duration-200)
        var(--set-motion-easing-ease-in-out),
      color var(--set-motion-duration-200) var(--set-motion-easing-ease-in-out);
  }

  .bubble-icon,
  .bubble-number {
    grid-area: 1 / 1;
  }

  .bubble-icon {
    opacity: 0;
    scale: 0.7;
    transition:
      opacity var(--set-motion-duration-200) var(--set-motion-easing-ease-out),
      scale var(--set-motion-duration-200) var(--set-motion-easing-ease-out);

    @media (prefers-reduced-motion: reduce) {
      scale: 1;
      transition: opacity var(--set-motion-duration-200)
        var(--set-motion-easing-ease-out);
    }
  }

  .label {
    color: var(--set-color-foreground-muted-text);
    font: var(--set-typography-text-body-xs-font);
    font-variation-settings: var(
      --set-typography-font-variation-settings-default
    );
    font-weight: var(--set-typography-font-weight-medium);
    inline-size: max-content;
  }

  .step {
    display: grid;
    flex: 1;
    gap: var(--set-spacing-vertical-400);
    grid-template-columns: var(--app-stepper-size);
    isolation: isolate;
    justify-content: center;
    justify-items: center;
    position: relative;

    &::after {
      background-color: var(--set-color-border-subtle);
      block-size: var(--set-layout-border-width-thick);
      content: "";
      inline-size: 100%;
      inset-block-start: calc(
        (var(--app-stepper-size) / 2) -
          (var(--set-layout-border-width-thick) / 2)
      );
      inset-inline-start: 50%;
      position: absolute;
      z-index: -1;
    }

    &:first-child {
      justify-content: start;
    }

    &:first-child::after {
      inline-size: calc(150% - (var(--app-stepper-size) / 2));
      inset-inline-start: calc(var(--app-stepper-size) / 2);
    }

    &:nth-last-child(2)::after {
      inline-size: calc(150% - (var(--app-stepper-size) / 2));
    }

    &:last-child {
      justify-content: end;
    }

    &:last-child::after {
      display: none;
    }

    &[data-state="done"]::after {
      background-color: var(--set-color-foreground-default);
    }
  }

  .step[data-state="current"] .bubble,
  .step[data-state="done"] .bubble {
    background-color: var(--set-color-foreground-default);
    color: var(--set-color-foreground-contrast);
  }

  .step[data-state="done"] .bubble-icon {
    opacity: 1;
    scale: 1;
  }

  .step[data-state="done"] .bubble-number {
    opacity: 0;
  }

  .step[data-state="current"] .label,
  .step[data-state="done"] .label {
    color: var(--set-color-foreground-default);
  }
}
```

## Notes

- **`Icon` is the one leaf a component covers.** It handles the checkmark's sizing and color inheritance. The number and the icon both render on every step, and CSS reveals the one the state calls for.
- **Why not `Text` for the number and label?** The design needs specific weights and tabular figures, and `Text` doesn't expose `font-weight` or `font-variant-numeric`. So the example drops to a plain `span`, takes the body-xs composite font token, and overrides only the deviations.
- **`data-state` is the seam between markup and styling.** State semantics live on the element, and each visual state is a CSS rule keyed off the attribute. An `error` state would be one more value in the data and one more CSS block, colored with `--set-color-intent-danger-*`.
- **One size, from one token.** `--app-stepper-size` is set once from a vertical spacing token, so the bubble follows the vertical rhythm and both sides match. It's round by convention, as step markers are, with a radius of `--set-radius-ratio-lg` times its size. The property is defined and consumed in the same file, which keeps it local to the component and satisfies the `set/set-known-tokens` lint rule.
- **The step is a one-column grid as wide as the bubble.** Centring the label in that column places it under the bubble whether the step is justified to the start, the centre or the end, in either writing direction, so the first and last labels need no offset of their own. A label wider than the bubble overhangs the row's ends by half the difference, so keep end labels short or give the row room.
- **Transitions, not keyframes.** A transition doesn't run on first render, so completed steps don't animate in as the page loads; the checkmark only moves when a step becomes done. Under `prefers-reduced-motion: reduce` the scale is dropped and the fade stands in.
- **Accessibility.** `aria-current="step"` marks the active step. The bubble is `aria-hidden` because the state is already carried by `aria-current` and by the `.visually-hidden` text appended to each label. `.visually-hidden` ships from `Root`, so there's nothing to redefine.
