Walk through a short sequence of instructions. The calling generator can resume once the tour ends.
Tour example
Example.jsx
import { TourCard } from "./ui/tour";
import "./example.css";
export default function* Example() {
const steps = [
{ id: "setup", title: "Configure", description: "Choose your project settings." },
{ id: "review", title: "Publish", description: "Review the build output." },
];
let index = 0;
for (;;)
yield index >= steps.length ? (
<button onClick={() => (index = 0)}>Restart tour</button>
) : (
<TourCard
step={steps[index]}
index={index}
total={steps.length}
onPrev={() => (index = 0)}
onNext={() => index++}
onClose={() => (index = steps.length)}
/>
);
}
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/tour
import './theme.css';
import { X } from '@lucide/icons';
import { scope, signal, type View } from '@fierst/aster';
import { Button } from './button';
import { Icon } from './icon';
const tourScope = scope`
:scope {
width: min(360px, calc(100vw - 1.5rem));
padding: 1rem 1.1rem;
border-radius: var(--aster-radius-lg);
display: grid;
gap: 0.7rem;
font-family: var(--aster-font-sans);
}
.tr-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.tr-step { font-family: var(--aster-font-mono); font-size: 0.72rem; font-weight: 600; color: var(--aster-primary); }
.tr-title { margin: 0.15rem 0 0; font-size: 0.95rem; font-weight: 600; color: var(--aster-on-surface); }
.tr-body { margin: 0; font-size: 0.84rem; color: var(--aster-on-surface-muted); line-height: 1.5; }
.tr-close {
width: 26px;
height: 26px;
border: none;
border-radius: var(--aster-radius-xs);
background: transparent;
color: var(--aster-on-surface-muted);
display: inline-grid;
place-items: center;
cursor: pointer;
}
.tr-close:hover { background: var(--aster-surface-muted); color: var(--aster-on-surface); }
.tr-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding-top: 0.35rem; }
`;
export interface TourStep {
id: string;
title: string;
description: string;
}
export function TourCard({
step,
index,
total,
onPrev,
onNext,
onClose,
class: extraClass,
}: {
step: TourStep;
index: number;
total: number;
onPrev?: () => void;
onNext?: () => void;
onClose?: () => void;
class?: string;
}) {
const isLast = index >= total - 1;
return (
<div
role="dialog"
aria-label={step.title}
class={['aster-surface-popover', tourScope, extraClass].filter(Boolean).join(' ')}
>
<div class="tr-head">
<div>
<span class="tr-step">
Step {index + 1} of {total}
</span>
<h2 class="tr-title">{step.title}</h2>
</div>
{onClose ? (
<button type="button" class="tr-close" aria-label="Close tour" onClick={onClose}>
<Icon icon={X} size={14} />
</button>
) : null}
</div>
<p class="tr-body">{step.description}</p>
<div class="tr-foot">
<Button size="sm" variant="ghost" disabled={index <= 0} onClick={onPrev}>
Back
</Button>
<Button size="sm" variant="primary" onClick={onNext}>
{isLast ? 'Finish' : 'Next'}
</Button>
</div>
</div>
);
}
/**
* Aster-native `yield*` Onboarding Tour Flow!
* Returns `true` if the user completed the tour, or `false` if skipped early.
*/
export function* runTour(steps: readonly TourStep[]): Generator<View, boolean, any> {
const idx = signal(0);
const status = signal<'active' | 'done' | 'skipped'>('active');
while (status() === 'active' && idx() < steps.length) {
const cur = idx();
yield (
<TourCard
step={steps[cur]}
index={cur}
total={steps.length}
onPrev={() => idx.set(Math.max(0, cur - 1))}
onNext={() => {
if (cur >= steps.length - 1) status.set('done');
else idx.set(cur + 1);
}}
onClose={() => status.set('skipped')}
/>
);
}
return status() === 'done';
}
Install
sh
npx @fierst/ui@1.0.2 add tourRegistry dependencies: theme, icon, button. Package dependencies: @lucide/icons.
Exports from ./ui/tour: TourStep, TourCard, runTour.
Download the registry source for tour 1.0.2.
API contracts
ts
export interface TourStep {
id: string;
title: string;
description: string;
}
export function TourCard({
step,
index,
total,
onPrev,
onNext,
onClose,
class: extraClass,
}: {
step: TourStep;
index: number;
total: number;
onPrev?: () => void;
onNext?: () => void;
onClose?: () => void;
class?: string;
})
export function* runTour(steps: readonly TourStep[]): Generator<View, boolean, any>