stnd.build

@stnd/ui

Circle 1 — Core Framework (Inviolable Pillar) · Stable · Load-Bearing

Role: Zero-dependency accessible UI primitives and components (Dialog, Toast, Accordion, Popover, Combobox, Tabs, Tree, Breadcrumb, Dropdown, ContextMenu, Header, Footer, Panel).

When to use: Import interactive primitives and UI components when native HTML tags aren’t enough. See the Components chapter for live demos.

Quick Start (TL;DR)

---
import Dialog from "@stnd/ui/Dialog.astro";
---
<Dialog id="settings-modal" title="Settings">
  <p>Modal content</p>
</Dialog>

Shared UI components for the Standard Ecosystem.


Most buttons/badges/cards should just be a CSS class on plain HTML (see @stnd/styles) — no JS, no import. This package is only for the handful of things that genuinely need interactivity: a dropdown that manages keyboard navigation, a confirm dialog you can await, a right-click menu. If you’re reaching for a component here and it’s not doing something stateful or ARIA-heavy, check whether a CSS class already does the job.

Use it (the confirm dialog, the most common one):

import { confirm } from "@stnd/ui/dialog.js";
const ok = await confirm({ title: "Delete this?", intent: "danger" });

Overview

@stnd/ui provides a collection of reusable, accessible, and high-quality UI components built for Astro and Svelte 5. These components are designed to work seamlessly with @stnd/styles and follow the Standard design principles.

The Philosophy: CSS First, Components Second

Standard is built on the philosophy of keeping the codebase as clean, fast, and static as possible. Before importing a component from @stnd/ui, ask yourself: Can this be done with just HTML and @stnd/styles?

Many UI elements you see in the Playground (like Buttons, Badges, Cards, and Inputs) are not components. They are simple CSS classes applied to standard HTML elements.

Why?

Example: Buttons & Badges (CSS Only)

You do not need a <Button> or <Badge> component. Just use the global classes provided by @stnd/styles:

<!-- Primary Button -->
<button class="btn">Save Changes</button>

<!-- Ghost Button -->
<button class="btn ghost">Cancel</button>

<!-- Success Badge -->
<span class="badge success">Active</span>

When to use @stnd/ui Components?

You should only import components from this package when you need:

  1. Complex interactivity (e.g., Dropdown, ContextMenu).
  2. State management (e.g., DialogManager, ComboBox).
  3. Advanced Accessibility / ARIA management (e.g., Accordion).
  4. Complex composition (e.g., Accordion, Scroller, TableOfContents).

Icons and Lottie animations are not in this package — they live in
@stnd/icon (import Icon from "@stnd/icon/Icon.astro"). See its README.


Component API Reference

Astro Components (Zero JS)

Minimalist responsive application and website header with brand wordmark, desktop menu, mobile navigation, and action slots.

Flexible website footer with brand column, navigation links, copyright, and slots (brand, description, copyright, studio, bottom-left, bottom-right).

<Accordion />

Accessible, collapsible content sections.

The trail to the current page. The last item is the current page: not a link, aria-current="page".

<Empty />

What a list or a page says when there is nothing to show yet.

<Stat />

One figure and what it measures.

No component needed: a progress bar is the native <progress>, and a loading placeholder is the
.skeleton class (both live in @stnd/styles, see the forms and components pages).


Svelte 5 Components (Hydrated)

<Alert />

Semantic feedback banners.

<Alert class="warning" title="Watch out!" icon="⚠">
  This action cannot be undone.
</Alert>

<Tabs />

A row of tabs and the panel of the selected one. Arrow keys, Home and End move between tabs; only the selected panel is rendered.

<Tabs {tabs} bind:value label="Period">
  {#snippet panel(tab)}...{/snippet}
</Tabs>

<OtpInput />

The boxes of a one-time code: focus moves on as you type, back on Backspace, a pasted code fills them all.

<Tree />

A nested list that opens and closes by branch, on native <details>.

Accessible, keyboard-navigable dropdown menus.

Related Sub-components:

<ContextMenu />

Viewport-aware right-click menus.

<DataTable />

A table whose column headers sort on click. Click a header (or press Enter/Space on it) to cycle ascending → descending → original order. Output is a plain <table> styled by @stnd/styles; the sort state is exposed through aria-sort and announced politely to screen readers.

<DataTable
  {rows}
  rowKey="id"
  locale="fr"
  columns={[
    { key: "name", header: "Station" },
    { key: "bikes", header: "Bikes", numeric: true },
    { key: "trend", header: "Trend", sortable: false },
  ]}
>
  {#snippet cell({ row, column, value })}
    {#if column.key === "trend"}<Sparkline data={row.trend} />{:else}{value}{/if}
  {/snippet}
</DataTable>

The comparison logic lives in sort.js (sortRows, compare, nextDirection) and works on any array without the component.

<Dialog />

A general-purpose native modal shell for forms and arbitrary content. This complements AlertDialog and confirm() without imposing confirmation semantics.

<Dialog bind:open label="Preferences" onclose={discardDraft}
  style="--dialog-width: 580px; --dialog-max-height: 88vh">
  <!-- Form content and semantic buttons belong to the consumer. -->
</Dialog>

<Popover />

An anchored, non-modal popup for forms and mixed controls. Use Dropdown for action menus instead.

<Popover label="Display options" align="end">
  {#snippet trigger(attributes)}
    <button class="btn ghost" {...attributes}>Display</button>
  {/snippet}
  <!-- Native inputs and content-specific buttons. -->
</Popover>

Dialog Manager

The DialogManager allows you to trigger accessible confirmation dialogs programmatically from any script using a simple Promise-based API. This prevents littering your DOM with hidden modal HTML.

AlertDialog can also be composed directly inside an existing Dialog when confirmation belongs to that form. Its title provides the accessible dialog name, keyboard events stay within the confirmation instead of reaching parent form shortcuts, and a programmatic close after confirmation does not also call the cancellation callback.

1. Mount the Manager

Ensure <DialogManagerComponent client:load /> is mounted once in your root layout (Standard does this by default).

2. Call the API

import { confirm } from "@stnd/ui/dialog.js";

const isConfirmed = await confirm({
  title: "Delete this item?",
  description: "This action cannot be undone. Are you sure?",
  confirmLabel: "Yes, Delete",
  cancelLabel: "Cancel",
  intent: "danger" // "neutral" | "danger"
});

if (isConfirmed) {
  // Proceed with deletion
}