Show which step is current and which steps remain. The generator helper can take the caller through the sequence.
Stepper example
Example.jsx
import { Stepper } from "./ui/stepper";
import "./example.css";
export default function* Example() {
const steps = [
{ id: "draft", title: "Draft" },
{ id: "review", title: "Review" },
{ id: "publish", title: "Publish" },
];
let index = 0;
for (;;)
yield (
<section>
<Stepper steps={steps} currentStep={index} onStepClick={(i) => (index = i)} />
<button onClick={() => (index = (index + 1) % steps.length)}>
{index === 2 ? "Start again" : "Continue"}
</button>
<output>{steps[index].title}</output>
</section>
);
}
example.css
@media screen and (prefers-reduced-motion: no-preference) {
#example button:is(.v-primary, .v-secondary):enabled {
transition: transform 120ms ease-out;
}
#example button:is(.v-primary, .v-secondary):enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button:is(.v-primary, .v-secondary):enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
--example-seed: var(--aster-primary);
--example-secondary-text: var(--aster-on-surface-subtle);
}
body {
--aster-primary: color-mix(in srgb, var(--example-seed) 84%, var(--aster-on-surface));
--aster-on-surface-subtle: color-mix(in srgb, var(--example-secondary-text) 84%, var(--aster-on-surface));
--aster-input-border: color-mix(in srgb, var(--aster-on-surface) 55%, var(--aster-surface));
margin: 0;
padding: clamp(0.8rem, 4vw, 1.5rem);
color: var(--aster-on-surface);
background: var(--aster-surface-muted);
font: 1rem/1.5 var(--aster-font-sans);
}
#example {
display: grid;
gap: 0.8rem;
min-width: 0;
align-content: start;
}
#example > button,
.sample > button {
justify-self: start;
}
.sample,
.tile {
background: var(--aster-surface);
border: 1px solid var(--aster-border);
border-radius: var(--aster-radius-lg);
}
.sample {
display: grid;
gap: 0.8rem;
padding: clamp(0.85rem, 3vw, 1.35rem);
box-shadow: var(--aster-shadow-xs);
min-width: 0;
}
.tile {
padding: 1rem;
min-width: 0;
}
h2,
h3,
p,
dl,
ul {
margin-block: 0;
}
h2,
h3 {
letter-spacing: -0.025em;
line-height: 1.2;
}
h2 {
font-size: 1.25rem;
}
h3 {
font-size: 1rem;
}
.sample > header,
.identity > div,
.receipt {
display: grid;
gap: 0.25rem;
}
.sample > header p,
.tile p,
small {
color: var(--aster-on-surface-muted);
}
small {
font-size: 0.82rem;
}
.split,
.actions,
.identity {
display: flex;
align-items: center;
gap: 0.65rem;
flex-wrap: wrap;
}
.split {
justify-content: space-between;
padding-block: 0.4rem;
border-bottom: 1px solid var(--aster-border);
}
.split:last-child {
border-bottom: 0;
}
.metric {
font-size: 2rem;
letter-spacing: -0.06em;
}
.facts {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.45rem 1rem;
}
.facts dt {
color: var(--aster-on-surface-muted);
}
.facts dd {
margin: 0;
font-weight: 600;
}
.type-sample {
font:
2rem/1.2 Georgia,
serif;
}
.listing {
padding-inline-start: 1.25rem;
}
.ink-strip {
height: 1.2rem;
background: var(--aster-primary);
border-radius: var(--aster-radius-sm);
}
.ink-proof {
display: grid;
gap: 0.15rem;
border-left: 0.6rem solid;
padding-left: 0.8rem;
}
.ink-proof strong {
font-size: 1.25rem;
letter-spacing: 0.06em;
}
.glyph {
display: inline-grid;
place-items: center;
width: 2rem;
height: 2rem;
border-radius: var(--aster-radius-sm);
color: var(--aster-on-primary-subtle);
background: var(--aster-primary-subtle);
}
.cover-box {
width: min(100%, 18rem);
}
.cover {
display: flex;
min-height: 7.5rem;
height: 100%;
padding: 1rem 1.25rem;
flex-direction: column;
justify-content: space-between;
gap: 1.6rem;
color: #fff;
background: repeating-linear-gradient(150deg, transparent 0 8px, #fff2 8px 9px), #204a48;
}
.cover strong {
font:
italic 2.45rem/1 Georgia,
serif;
}
.cover span {
font: 0.78rem var(--aster-font-mono);
}
.cover.grove {
background-color: #3d4b27;
}
.cover.dune {
background-color: #7c4428;
}
button:not([class]),
.entry {
font: inherit;
font-size: 0.875rem;
padding: 0.45rem 0.8rem;
border: 1px solid var(--aster-border-strong);
border-radius: var(--aster-radius-control);
background: var(--aster-surface);
color: var(--aster-on-surface);
}
button:not([class]) {
cursor: pointer;
font-weight: 600;
}
button:not([class]):hover:enabled {
background: var(--aster-primary-subtle);
}
button:disabled {
cursor: default;
}
:focus-visible {
outline: 2px solid var(--aster-primary);
outline-offset: 3px;
}
output:not(:empty) {
display: block;
color: var(--aster-on-primary-subtle);
font-weight: 600;
font-size: 0.9rem;
}
Site-owned component source and scoped styles
src/ui/stepper
import './theme.css';
import { Check } from '@lucide/icons';
import { scope, signal, type View } from '@fierst/aster';
import { Icon } from './icon';
import { Button } from './button';
const stepScope = scope`
:scope {
display: flex;
flex-direction: column;
gap: 0.75rem;
list-style: none;
margin: 0;
padding: 0;
font-family: var(--aster-font-sans);
}
@media (min-width: 640px) {
:scope {
flex-direction: row;
align-items: flex-start;
gap: 0;
}
}
.st-item {
display: flex;
align-items: flex-start;
gap: 0.65rem;
flex: 1;
min-width: 0;
position: relative;
}
@media (min-width: 640px) {
.st-item {
flex-direction: column;
align-items: flex-start;
padding-right: 1rem;
}
.st-item:not(:last-child)::after {
content: '';
position: absolute;
top: 13px;
left: 34px;
right: 10px;
height: 1px;
background: var(--aster-border);
}
.st-item.is-done:not(:last-child)::after { background: var(--aster-primary); }
}
.st-dot {
width: 28px;
height: 28px;
border-radius: 9999px;
border: 1.5px solid var(--aster-border-strong);
background: var(--aster-surface);
color: var(--aster-on-surface-muted);
font-size: 0.78rem;
font-weight: 600;
display: inline-grid;
place-items: center;
flex-shrink: 0;
position: relative;
z-index: 1;
transition: background-color var(--aster-dur-fast), border-color var(--aster-dur-fast), color var(--aster-dur-fast);
}
.st-item.is-active .st-dot {
border-color: var(--aster-primary);
color: var(--aster-primary);
background: var(--aster-primary-subtle);
}
.st-item.is-done .st-dot {
border-color: var(--aster-primary);
background: var(--aster-primary);
color: var(--aster-on-primary);
}
.st-copy { display: grid; gap: 0.1rem; min-width: 0; }
.st-title { font-size: 0.84rem; font-weight: 600; color: var(--aster-on-surface); }
.st-item.is-upcoming .st-title { color: var(--aster-on-surface-muted); font-weight: 500; }
.st-desc { font-size: 0.76rem; color: var(--aster-on-surface-muted); }
`;
const wizScope = scope`
:scope {
display: grid;
gap: 1.15rem;
padding: 1.25rem;
border-radius: var(--aster-radius-lg);
border: 1px solid var(--aster-border);
background: var(--aster-surface);
box-shadow: var(--aster-shadow-xs);
}
.wiz-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
padding-top: 0.85rem;
border-top: 1px solid var(--aster-border);
}
`;
export interface StepItem {
id: string;
title: string;
description?: string;
}
export function Stepper({
steps,
currentStep,
onStepClick,
class: extraClass,
}: {
steps: readonly StepItem[];
currentStep: number;
onStepClick?: (index: number) => void;
class?: string;
}) {
return (
<ol class={[stepScope, extraClass].filter(Boolean).join(' ')} aria-label="Progress steps">
{steps.map((step, idx) => {
const done = idx < currentStep;
const active = idx === currentStep;
const upcoming = idx > currentStep;
return (
<li
key={step.id}
aria-current={active ? 'step' : undefined}
class={[
'st-item',
done ? 'is-done' : '',
active ? 'is-active' : '',
upcoming ? 'is-upcoming' : '',
]
.filter(Boolean)
.join(' ')}
>
<button
type="button"
class="st-dot"
disabled={!onStepClick || upcoming}
style={onStepClick && !upcoming ? 'cursor:pointer' : 'cursor:default'}
aria-label={`Step ${idx + 1}: ${step.title}`}
onClick={() => onStepClick && !upcoming && onStepClick(idx)}
>
{done ? <Icon icon={Check} size={14} strokeWidth={2.5} /> : idx + 1}
</button>
<div class="st-copy">
<span class="st-title">{step.title}</span>
{step.description ? <span class="st-desc">{step.description}</span> : null}
</div>
</li>
);
})}
</ol>
);
}
export interface WizardStepDef<TState> {
id: string;
title: string;
description?: string;
render: (state: TState, update: (patch: Partial<TState>) => void) => View;
canProceed?: (state: TState) => boolean;
}
/**
* Aster-native `yield*` Multi-Step Wizard Flow!
* Walks the user through typed steps and returns the completed state (or `null` if cancelled):
* const config = yield* runWizard(steps, { name: '', region: 'pdx' });
*/
export function* runWizard<TState extends Record<string, any>>(
steps: readonly WizardStepDef<TState>[],
initial: TState,
opts: { finishLabel?: string; cancelLabel?: string } = {},
): Generator<View, TState | null, any> {
const stepIdx = signal(0);
const state = signal<TState>({ ...initial });
const status = signal<'active' | 'done' | 'cancelled'>('active');
const update = (patch: Partial<TState>) => {
state.update((prev) => ({ ...prev, ...patch }));
};
while (status() === 'active') {
const idx = stepIdx();
const curState = state();
const cur = steps[idx];
const isLast = idx === steps.length - 1;
const ok = cur?.canProceed ? cur.canProceed(curState) : true;
yield (
<div class={wizScope}>
<Stepper steps={steps} currentStep={idx} onStepClick={(i) => stepIdx.set(i)} />
<div>{cur ? cur.render(curState, update) : null}</div>
<div class="wiz-footer">
<Button
variant="ghost"
onClick={() => {
if (idx === 0) status.set('cancelled');
else stepIdx.set(idx - 1);
}}
>
{idx === 0 ? (opts.cancelLabel ?? 'Cancel') : 'Back'}
</Button>
<Button
variant="primary"
disabled={!ok}
onClick={() => {
if (isLast) status.set('done');
else stepIdx.set(idx + 1);
}}
>
{isLast ? (opts.finishLabel ?? 'Complete') : 'Continue'}
</Button>
</div>
</div>
);
}
return status() === 'cancelled' ? null : state();
}
Install
sh
npx @fierst/ui@1.0.2 add stepperRegistry dependencies: theme, icon, button. Package dependencies: @lucide/icons.
Exports from ./ui/stepper: StepItem, Stepper, WizardStepDef, runWizard.
Download the registry source for stepper 1.0.2.
API contracts
ts
export interface StepItem {
id: string;
title: string;
description?: string;
}
export function Stepper({
steps,
currentStep,
onStepClick,
class: extraClass,
}: {
steps: readonly StepItem[];
currentStep: number;
onStepClick?: (index: number) => void;
class?: string;
})
export interface WizardStepDef<TState> {
id: string;
title: string;
description?: string;
render: (state: TState, update: (patch: Partial<TState>) => void) => View;
canProceed?: (state: TState) => boolean;
}
export function* runWizard<TState extends Record<string, any>>(
steps: readonly WizardStepDef<TState>[],
initial: TState,
opts: { finishLabel?: string; cancelLabel?: string } = {},
): Generator<View, TState | null, any>