Wardian docs

Components and Arrange

Wardian has a small library of interface parts. Like shadcn/ui, you copy them into your app, and then they are your code. Every app that uses them looks and works alike, and still works on a host that has no library at all.

See each one live, in light and dark, with its markup, at Components in Wardian's app list, or at /ui/.

Add components#

wardian add button field card toast apps/my-app
wardian add --list

wardian add copies each component's files into the package's ui/ folder, with ui/theme.css.

It never replaces a file that is already there unless you give --force. So your changes to a component are safe.

The components#

ComponentWhat it isFiles
buttonbuttons in five variants and three sizesbutton.css
fieldtext inputs, selects, text areas, labels and hints, widths that fit the content (.size-xs … .size-full), right-aligned numbers (.num) and units beside a field (w-affix)field.css
carda bordered box with a title, a description, content and a footercard.css
badgea small label for a state or a countbadge.css
tablea data table with a sticky header and right-aligned numberstable.css
switchan on/off switch made from a checkboxswitch.css
tabstabs with arrow-key movement between themtabs.css, tabs.js
dialoga modal dialog, and WardianUI.confirm()dialog.css, dialog.js
toastshort messages in the corner: WardianUI.toast()toast.css, toast.js
tooltipa hint on hover and keyboard focustooltip.css, tooltip.js
progressthe <wardian-progress> bar (also built in)progress.js
arrangeArrange for a page apparrange.js
typea light display serif for headlines, ledes and large figurestype.css
surfacefrosted glass panes over a slow greenhouse lightsurface.css
bentotiles of different widths that follow the grid's own widthbento.css
receiptone shared message, shown the same in both apps: WardianUI.receipt()receipt.css, receipt.js
agentan app's AI with a skill and tools, in the suite's out-of-sight ai app: WardianUI.agentApp(), WardianUI.agent()agent.js

Classes start with w-. Variants and sizes are attributes:

<button class="w-button">Run</button>
<button class="w-button" data-variant="outline" data-size="sm">Reset</button>
<button class="w-button" data-variant="destructive">Delete</button>

The variants are secondary, outline, ghost, destructive and success; the sizes are sm, lg and icon.

The scripted parts have small calls:

WardianUI.toast('Saved', { variant: 'success' });
if (await WardianUI.confirm('Delete this habit?', { destructive: true })) remove();

Change the look#

One file, ui/theme.css, sets the colours, corners and spacing for every component, through tokens. Change the tokens, not each class:

:root {
  --w-primary: #2f6b50;
  --w-primary-fg: #ffffff;
  --w-radius: 12px;
}
TokenSets
--w-bg, --w-fgpage background and text
--w-muted, --w-muted-bgquiet text and quiet backgrounds
--w-border, --w-ringlines and the focus ring
--w-primary, --w-primary-fgthe main action
--w-secondary, --w-secondary-fgthe other actions
--w-destructive, --w-successdanger and success
--w-radius, --w-radius-lgcorners; the large one for glass, tiles and receipts
--w-space-1 … --w-space-6spacing, 4 px to 32 px
--w-font, --w-font-mono, --w-font-display, --w-text-sm, --w-text, --w-text-lgtype
--w-glass-opacity, --w-glass-edge, --w-blurhow much glass hides, its edge, and its blur
--w-glow-1 … --w-glow-3the three lights of the wallpaper

theme.css has a dark set of the same tokens, used when the viewer's system is dark.

Glass, display type and tiles#

Four parts give a page depth and a voice. They change nothing until you use their classes. The display title and lede are for a page that stands alone, like this report; an app inside Wardian does not open with its own name (see Design an app).

<body class="w-wallpaper">
  <h1 class="w-display">Checkout latency</h1>
  <p class="w-lede">Seven days of requests, from the last Splunk search.</p>
  <div class="w-bento">
    <article class="w-tile w-glass" data-span="8">
      <header><h3 class="w-tile-title">Throughput</h3><p class="w-tile-note">Requests per second</p></header>
      <div class="w-tile-body"><p class="w-figure">10,970<small>req/s</small></p></div>
      <footer><button class="w-button" data-variant="glass">Details</button></footer>
    </article>
  </div>
</body>
const sent = await ctx.channel('splunk.table').send(table, { name: 'Checkout latency' });
box.replaceChildren(WardianUI.receipt({ ...sent, channel: 'splunk.table', data: table }, { direction: 'sent' }));
{ "name": "ai", "caps": ["claude:sample", "asset"], "provides": ["ask", "chat"], "needs": ["log.errors"], "scripts": ["ui/agent.js"] }

apps/ai/tools.json:

{ "format": 1, "tools": [{ "name": "top_hosts", "description": "The hosts with the most errors. Use it before naming a host.",
  "input": { "type": "object", "properties": { "limit": { "type": "integer", "minimum": 1, "maximum": 20 } }, "required": ["limit"] },
  "enabled": true, "proposed": false }] }
// apps/ai/app.js: provide at once, so an early call finds the method; agentApp waits for Claude.
Kernel.register({ name: 'ai', caps: ['claude:sample', 'asset'], provides: ['ask', 'chat'], needs: ['log.errors'], init(ctx) {
  const ai = WardianUI.agentApp(ctx, { maxSteps: 6, run: { top_hosts: ({ limit }) => ctx.call('log', 'errors', { limit }) } });
  // ask and chat never throw: an error's code would not cross ctx.call. chat answers Wardian's Ask
  // with { reply, blocks?, suggest?, steps }: blocks are tables, figures, lists or checks Ask draws.
  ctx.provide({ ask: ({ task }) => ai.ask(task), chat: ({ messages }, call) => ai.chat(messages, call) });
} });

// A visible app: { answer, steps }, or { error: { code, message } } to show the plain path.
const r = await ctx.call('ai', 'ask', { task });

WardianUI.agent({ sample, skill, tools: [{ name, description, input, run }] }) is the loop itself, for an AI whose skill and tools are not meant to be edited.

A glass suite#

A suite is several frames, and glass cannot see out of its frame. So a suite asks Wardian for the light instead: put "surface": "glass" in suite.json, and w-glass on each panel's wrap.

{
  "surface": "glass",
  "styles": ["ui/theme.css", "ui/card.css", "ui/type.css", "ui/surface.css", "style.css"],
  "apps": [{ "name": "today", "slot": "main", "wrap": "<section class=\"w-card w-glass panel\">" }]
}

Wardian then paints one light behind every frame and makes each frame see-through. The light uses Wardian's colours, not your copy of theme.css. A page app needs none of this: it puts w-wallpaper on its own <body>. Every example app with a page or a suite uses glass; new apps from wardian new start the same way, with no title of their own.

Design an app#

The components make the parts; these rules make the app. Wardian's Make an app and the hosted builder follow them, and so do the examples.

The method#

Every new app and every change goes through four stages, in order, the way a professional product team works.

  1. Blueprint. README.md comes first, written for the person who will use the app (the store shows it as the app's About page):

    • one paragraph: who it is for and the job it does;
    • What you put in: the field spec, one line per input: label, data type, unit, allowed range or format, default, required or optional. Interest rate: decimal, % a year, 0 to 30, default 6, required.
    • What it shows: each result, its unit, how it is worked out;
    • How it behaves: the first screen (with sample data), the empty state, errors, anything slow, what is kept between visits.

    A change updates the README first.

  2. Design. A Layout section in the README: the panels in reading order (inputs, results, details); each input's control, width, validation rule and message; which fields share a row; the tab order; each view's one main action; every panel's sample, empty, loading and error states. Then goldfish reviews of the plan (below), and the README fixed.

  3. Approve. The builder stops and shows you the plan: what it will build, what the reviewers changed, and each open decision with the option it recommends. Nothing is coded until you answer "go" or say what to change.

  4. Develop. Add the components; then a data module with no DOM: one parse function per input, turning text into a typed value or a clear error, and the calculations, shared by the page and any import; then markup in reading order, styles, wiring. Realistic sample data, said to be sample data; no TODOs or dead controls.

  5. Validate. Read every file back against the checklist below, fix every miss, get goldfish reviews of the files against the README and fix what they find, run wardian check, and say what was validated.

Fresh reviews#

Whoever wrote the plan knows too much to see its gaps. So Make an app works in the Elephant-Goldfish Model (ADR-2610281000, ADR-2610281200): the builder that talked with you is the elephant and writes the plan; goldfish reviewers, who have none of the conversation, only the package, each check it through one lens; and you settle the decisions and approve the plan before any code is written. The method and the idea behind the review's lenses come from EGM, by Google's EGM team (github.com/google/elephant-goldfish-model, Apache-2.0), after Dave Rensin's essay "Elephants, Goldfish, and the New Golden Age of Software Engineering"; thank you to them.

Each finding is a must, should or could; the builder fixes every must and should. The decisions they raise come to you with the plan; those raised by the build review, the builder takes as recommended and tells you after the save, so you can ask for the other.

Wardian holds the method whatever the model does: for a new app it refuses to write code until the plan has been reviewed and you have answered, and refuses to save until a build review has run for your latest request; the fixes after it are its resolution, not a reason to review again. In Make an app the builder calls the fresh_review tool; with Claude Code, the app-factory skill uses the EGM plugin's review for suites and apps with AI.

Forms: types, sizes and validation#

The control enforces the type, so a wrong value is hard to type:

DataControl and attributes
whole numbertype="number" inputmode="numeric" step="1", min, max
decimal, money, ratetype="number" inputmode="decimal", step (0.01 for money), min, max; the unit beside the field in a w-affix, never in the value
percentageas decimal, min="0" max="100", % beside it
date, month, timetype="date", "month", "time", with min and max
short texttype="text" with maxlength, and autocomplete where it applies
email, web address, phonetype="email", "url", "tel"
long texttextarea, rows 4 to 8, maxlength if it is limited
one of 2 to 5a radio group, every option visible
one of 6 or moreselect; with many, or free entry, an input with a datalist
on or offswitch
a fileinput type="file" with accept

Every field has a visible label (w-label; a placeholder is never the label), required when it is, and a w-hint for its format, unit or range when that is not obvious.

A field's width says what goes in it. The library's widths: .size-xs (7 characters: ages, percentages), .size-sm (11: amounts, dates, codes), .size-md (20: names), .size-lg (32: email, web addresses, titles) and .size-full (long text, search). On a narrow screen every field takes the full width. .num right-aligns a number with even-width digits.

<div class="w-field">
  <label class="w-label" for="rate">Interest rate</label>
  <div class="w-affix">
    <input class="w-input size-xs num" id="rate" type="number" inputmode="decimal"
           step="0.01" min="0" max="30" required aria-describedby="rate-hint">
    <span>% a year</span>
  </div>
  <p class="w-hint" id="rate-hint">From 0 to 30</p>
</div>

Validate in the right place, at the right time:

Alignment, states and keyboard#

The Validate checklist#

  1. Blueprint: the README's field spec covers every input and matches what was built.
  2. Types: every input's control and attributes enforce its type and range.
  3. Sizes: every field has a width that fits its content; no short field spans the panel.
  4. Validation: on change and on submit; errors under the field with aria-invalid, aria-describedby and a message saying what is allowed; nothing typed lost; no results from invalid input.
  5. Alignment: labels above fields on one edge; spacing from the scale; controls in a row share height and baseline; numbers right-aligned.
  6. States: focus, hover, pressed, disabled (with its reason), busy, empty, error and success each visible.
  7. Keyboard: tab order equals reading order; no positive tabindex; Enter and Escape behave; focus returns after dialogs and goes to the first error on submit.
  8. Look: glass on; the app's name not repeated inside it; library components only; no hand-set colours.
  9. Content: realistic sample data, said to be sample data; plain words; units; no placeholders or TODOs.
  10. Width: reads well at 360 px and in a wide window, with nothing scrolling sideways.

The look#

Glass, and straight to the point. A page app:

<body class="w-wallpaper">
  <div data-arrange-grid>
    <div data-arrange-column="side">
      <section class="w-card w-glass" data-panel="add" data-panel-label="Add a habit">…</section>
    </div>
    <div data-arrange-column="main">
      <div class="w-bento" data-panel="week" data-panel-label="This week">
        <article class="w-tile w-glass" data-span="8">…</article>
        <article class="w-tile w-glass" data-span="4">
          <header><h3 class="w-tile-title">Longest streak</h3></header>
          <div class="w-tile-body"><p class="w-figure">12<small>days</small></p></div>
        </article>
      </div>
    </div>
  </div>
</body>

The progress bar#

<wardian-progress> is built into every suite frame and into /sdk/wardian.js, so it needs no copy. Use it for any work longer than a second, instead of drawing your own.

const bar = ctx.$('wardian-progress');
bar.start('Simulating');
bar.update({ value: done, max: total, detail: `${done} of ${total}` });
bar.done('Finished');           // or bar.fail('Stopped')
bar.addEventListener('cancel', () => worker.terminate());
AttributeDoes
label, detailthe text above and beside the bar
value, maxfill the bar; without value, it shows work of unknown length
elapseda running clock
cancelablea Stop button that fires cancel

It has the progressbar role, and it stops moving when the viewer asks for reduced motion.

Arrange#

Every app offers Arrange: each viewer may reorder its panels, move them between two columns, hide them, or use one column. The layout belongs to the viewer. Wardian keeps it in its data folder, and the package never changes.

<div data-arrange-grid>
  <div data-arrange-column="side">
    <section data-panel="input" data-panel-label="Your text">…</section>
  </div>
  <div data-arrange-column="main">
    <section data-panel="stats">…</section>
    <section data-panel="hash">…</section>
  </div>
</div>
<script src="ui/arrange.js"></script>

A page is sandboxed and cannot keep the layout itself. So arrange.js asks the host page to keep it, through postMessage. Outside Wardian, the layout lasts until the page closes.

A hidden panel still runs. An app must never depend on where a panel sits, or on being visible. Results must never wait on a panel the viewer may hide.

The frame and zoom#

Each panel of a suite or a page app sits in a glass frame. The frame's top strip holds the zoom button, so the button never covers the panel. Press it, and the panel grows to fill the app; the rest of the page goes dim behind it. Press it again, press Esc, or click beside the panel, and it shrinks back to its place. One panel is zoomed at a time, and the zoom is not kept in the layout. Viewers who ask for less motion see it change size at once.

A zoomed suite part is told so, and its box (the element with data-app) fills the frame. A page app's panel fills the frame itself. Either way the app gets a bigger window, so draw from the size you have, and redraw when it changes. Module apps have no frame and no zoom: their cards sit on Wardian's own page.

The title inside Wardian#

Wardian shows the app's name and description above the app, so a new app has no title of its own. An older app that carries one keeps working: inside Wardian a suite's header is hidden for you, and a page app's title is hidden when it is marked:

<header class="top" data-app-title>
  <h1 class="w-display">Text tools</h1>
  <p class="w-lede">Type, paste or open a text file.</p>
</header>

Opened on its own, in a new tab, or saved as a web page, the app shows its title.

This page is docs/site/components.md in the repository. Something wrong or missing? Change that file.