Switch example
import { signal } from "@fierst/aster";
import { Switch } from "./ui/switch";
import "./example.css";
export default function* Example() {
const notify = signal(false);
for (;;)
yield (
<section class="sample">
<h2>Editorial notifications</h2>
<Switch label="Email updates" checked={notify()} onChange={(value) => notify.set(value)} />
<output>
{notify()
? "Notify the editor when proofs arrive."
: "New proofs appear only in the review queue."}
</output>
</section>
);
}
@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
import './theme.css';
import { scope, type Ctx } from '@fierst/aster';
const switchScope = scope`
:scope {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.85rem;
cursor: pointer;
user-select: none;
touch-action: manipulation;
}
:scope.is-disabled { opacity: 0.5; cursor: not-allowed; }
.copy { display: grid; gap: 0.1rem; }
.label { font-size: 0.875rem; font-weight: 500; color: var(--aster-on-surface); }
.desc { font-size: 0.8125rem; color: var(--aster-on-surface-muted); }
.track {
position: relative;
width: 40px;
height: 22px;
padding: 2px;
border-radius: 9999px;
border: 1px solid transparent;
background: var(--aster-border-strong);
display: inline-flex;
align-items: center;
cursor: inherit;
flex-shrink: 0;
transition:
background-color var(--aster-dur-med) var(--aster-ease-standard),
box-shadow var(--aster-dur-fast) var(--aster-ease-standard);
}
.track:focus-visible { outline: none; box-shadow: var(--aster-focus-ring); }
.track.is-on { background: var(--aster-primary); }
.thumb {
width: 16px;
height: 16px;
border-radius: 9999px;
background: var(--aster-on-primary);
box-shadow: var(--aster-shadow-sm);
transition: transform var(--aster-dur-med) var(--aster-ease-spring);
}
.track:not(.is-on) .thumb { background: #ffffff; }
.track.is-on .thumb { transform: translateX(18px); }
`;
export function* Switch(
props: {
checked?: boolean;
defaultChecked?: boolean;
label?: string;
description?: string;
disabled?: boolean;
onChange?: (checked: boolean) => void;
class?: string;
},
ctx: Ctx,
) {
let internal = props.defaultChecked ?? false;
for (props of ctx) {
const isControlled = props.checked !== undefined;
const isOn = isControlled ? Boolean(props.checked) : internal;
const toggle = () => {
if (props.disabled) return;
const next = !isOn;
if (!isControlled) internal = next;
props.onChange?.(next);
};
yield (
<div
class={[switchScope, props.class].filter(Boolean).join(' ')}
class:is-disabled={Boolean(props.disabled)}
onClick={toggle}
>
{props.label || props.description ? (
<div class="copy">
{props.label ? <span class="label">{props.label}</span> : null}
{props.description ? <span class="desc">{props.description}</span> : null}
</div>
) : null}
<button
type="button"
role="switch"
aria-checked={isOn}
aria-label={props.label ?? 'Toggle'}
disabled={props.disabled}
class="track"
class:is-on={isOn}
onClick={(e: MouseEvent) => {
e.stopPropagation();
toggle();
}}
>
<span class="thumb" aria-hidden="true" />
</button>
</div>
);
}
}
Install, inspect and update owned files
| Command or option | Behavior |
|---|---|
vp dlx @fierst/ui@1.0.2 list |
List slugs, descriptions and direct registry dependencies. |
vp dlx @fierst/ui@1.0.2 init |
Install the shared theme controller, CSS and Lucide icon helper. |
vp dlx @fierst/ui@1.0.2 add dialog toast |
Resolve both items and their transitive registry dependencies once, then copy their files. You can use add without init. |
--dir src/controls |
Change the destination from src/ui. Use the same directory for related items so sibling imports resolve. |
--registry ./public/r |
Read index.json and item manifests from a local directory. The default registry ships in the npm package. |
--registry https://ui.fierst.dev/r |
Read manifests from an HTTP(S) base URL. |
--force |
Replace existing target files, including resolved dependencies. Without this flag existing files are skipped. |
Run the npm dependency command printed by the installer. Registry dependencies are other source items, while package dependencies such as @lucide/icons belong in the consuming project. Use a versioned invocation such as npx @fierst/ui@1.0.2 add dialog for reproducible installs from the bundled registry. To update edited components, install the new version into a separate directory, compare the files and merge the changes you want. Include theme and icon dependencies in that comparison.
The Node API is available after installing @fierst/ui as a development dependency. Both functions return promises.
import { addComponents, listRegistryItems } from '@fierst/ui/bin/aster-ui.mjs';
const items = await listRegistryItems();
const result = await addComponents(['dialog', 'toast'], process.cwd(), {
uiDir: 'src/ui',
force: false,
});
console.log(items.length, result.resolved, result.dependencies, result.copied, result.skipped);Inspect the local registry index and dialog manifest to see the files the CLI will resolve. Pass a registry path or URL to listRegistryItems(source) or use { registry: source } with addComponents. The index lists each item's name, type, title, description, dependency arrays and file targets. Each item manifest includes the source content and SHA-256 digest for each file. The installer checks supplied digests and resolves dependencies before copying. If resolution fails, check the slug and registry base; for a checksum error rebuild or replace the inconsistent manifest.
Render and update components
Use TSX with the Aster Vite plugin and jsxImportSource: "@fierst/aster". Render components as JSX, including components implemented as generator functions. Aster supplies their context. In the reference, View denotes renderable content, ? marks an optional prop, and destructuring defaults show the value used when omitted. For example, the Switch contract lists the boolean delivered to its change callback. Some wrap native events; others deliver the next value directly.
For a controlled switch, keep the value in the parent. For a standalone switch, pass defaultChecked for the initial value and optionally observe changes with onChange.
import { signal } from '@fierst/aster';
import { Switch } from './ui/switch';
export function* Preferences() {
const enabled = signal(true);
for (;;) {
yield (
<Switch label="Email updates" checked={enabled()} onChange={(next) => enabled.set(next)} />
);
}
}For a form, install form input button, give the input a name, and handle the submit event. Form prevents the browser's default navigation. Input associates its label, hint and error with the field. Give icon-only buttons an accessible name. Use a title on dialogs and meaningful row keys for dynamic data.
import { Form, FormActions } from './ui/form';
import { Input } from './ui/input';
import { Button } from './ui/button';
export function ContactForm({ save }: { save: (email: string) => void }) {
return (
<Form
onSubmit={(event) => {
const data = new FormData(event.currentTarget as HTMLFormElement);
save(String(data.get('email')));
}}
>
<Input id="email" name="email" type="email" label="Email address" required />
<FormActions>
<Button type="submit">Save</Button>
</FormActions>
</Form>
);
}Dialogs, decisions and notifications
Render a controlled overlay when the parent owns its open state. For a multi-step interaction, delegate from an Aster generator with yield*. The helper yields views until a decision arrives, then execution resumes with the result. Set the trigger back to idle before rendering the next frame.
import { signal } from '@fierst/aster';
import { confirmDialog } from './ui/dialog';
import { Toaster, toast } from './ui/toast';
export function* Review() {
const reviewing = signal(false);
for (;;) {
if (reviewing()) {
const approved = yield* confirmDialog({ title: 'Approve the draft?' });
reviewing.set(false);
if (approved) toast.success('Draft approved');
}
yield (
<>
<button onClick={() => reviewing.set(true)}>Review draft</button>
<Toaster />
</>
);
}
}Mount one Toaster for application notifications. showToast returns an id for dismissToast. The default duration is 3500 ms; a duration of zero keeps the toast until dismissal or displacement. The store retains up to five items.
| Helper | Registry item | Result |
|---|---|---|
| confirmDialog | dialog | true on confirmation, false on cancellation or dismissal |
| confirmDestructive | alert-dialog | boolean decision, with optional typed confirmation phrase |
| pickCommand | command | selected CommandItem or null |
| pickDate | calendar | selected YYYY-MM-DD string or null |
| runWizard | stepper | final state object or null on cancel; each step renders from state and can supply canProceed |
| promptDrawer | drawer | selected action id or null |
| runTour | tour | true on completion, false on skip or an empty tour |
| requestApproval | approval-card | true on approval, false on rejection |
Display records and charts
Install data-table line-chart for a sortable table and SVG chart. Column keys identify row fields. Supply a custom column render function for formatted cells. Line and area charts accept ordered label/value points.
import { DataTable } from './ui/data-table';
import { AreaChart } from './ui/line-chart';
const rows = [
{ day: 'Monday', requests: 12 },
{ day: 'Tuesday', requests: 18 },
];
export function Traffic() {
return (
<>
<DataTable
rows={rows}
rowKey={(row) => row.day}
columns={[
{ key: 'day', header: 'Day' },
{ key: 'requests', header: 'Requests', sortable: true },
]}
/>
<AreaChart
label="Requests by day"
data={rows.map((row) => ({ label: row.day, value: row.requests }))}
/>
</>
);
}Connect AI and human review workflows
Feed application messages to ChatMessage, response text to StreamingText, reasoning to ReasoningBlock, and tool activity to ToolCallCard. Use PromptInput.onSubmit(prompt) to start your request, update its streaming prop while generating, and wire onStop to your cancellation handler. Present sources with CitationBadge and SourceList, suggested prompts with SuggestionChips, and metering with TokenUsageBar.
Map workflow records to WorkflowGraph nodes with a stable id, label, optional detail and status. Status values are pending, running, waiting, done, replayed, and failed. Use ApprovalCard callbacks or yield* requestApproval(...) to collect a decision. Your application connects it to the corresponding workflow run and handles persistence, authorization, retries and tool execution. In the approval card example, make each choice and inspect the callback that records it. Then open the workflow graph to see how changing a node's status changes its presentation.