Toast
A transient notification panel reporting the outcome of an action, in one of five semantic tones.
View code
<div mix={[hstack({ gap: 2, align: "center" })]}>
<Button
mix={[
on("click", () =>
pageToaster().add({ color: "success", title: "Status page published" }),
),
]}
>
Publish
</Button>
<Button
color="danger"
variant="outline"
mix={[
on("click", () =>
pageToaster().add({
color: "danger",
title: "Couldn't upload checks.yml",
description: "Unknown key “retires”. Fix it and try again.",
}),
),
]}
>
Upload a bad file
</Button>
</div>
{/* Once, in the app layout: */}
<Toasts labels={{ region: "Notifications", dismiss: "Dismiss" }} />Demo apps
Whole pages built only from @sdxc/ui, each for an invented product with its own palette and type. They open in a new tab.
- Food deliveryBocadoBocado, an invented food delivery app: restaurants by cuisine and delivery time, search with filters, menus with options, a cart, checkout and live order tracking on a drawn map./showcase/bocado/demo
- Issue trackerCairnCairn, an invented issue tracker: grouped issue lists with filters in the address, a drag-and-drop board, projects on a roadmap, cycles with burn-up charts and an inbox./showcase/cairn/demo
- Social networkChorusChorus, an invented social network: a live timeline with pictures, link cards, polls and threads, profiles, grouped notifications, search and messages./showcase/chorus/demo
- Code hostDeltaDelta, a code host whose one repository is its own source: a file tree beside the code, line links, blame and the commits list, every file and commit read from git when the site is built./showcase/delta/demo
- Online storeHangwellHangwell, an invented poster shop: collections with facet filters, product pages with format, size and frame pickers and a room preview, a bag, a checkout that adapts to print files, order tracking, downloads and returns./showcase/hangwell/demo
- CMSInkwellInkwell, a demo CMS built from @sdxc/ui/app: posts with count tabs and quick edit, an editor with a quiet save status and a loud Publish, media and settings./showcase/inkwell/demo
- Music streamingMurmurMurmur, an invented music service: home shelves, search by genre, a library, albums, playlists and artists, with a player that keeps playing while you browse./showcase/murmur/demo
- Team chatParleyParley, an invented team chat: channels and direct messages with unread and mention badges, threads, reactions, edits, pins, search, a quick switcher and teammates who type and post live./showcase/parley/demo
- Photo and video networkPinholePinhole, an invented social network for photographs and short videos: a feed under a story tray, full-screen stories, a vertical reels feed, profiles with highlights, Explore and posts with comments./showcase/pinhole/demo
- Ops dashboardPulsePulse, an invented ops dashboard: Northwind's services with live filters, a peek sheet and a bulk bar, metrics that switch one chart, incidents, deploys and settings./showcase/pulse/demo
- Support inboxRelayRelay, an invented support inbox: mailboxes, conversations and the open conversation on one screen, with contacts, reports and settings./showcase/relay/demo
- CalendarSundialSundial, an invented calendar: day, week and month views, an agenda, events you drag, resize and create on the grid, a second time zone, and a find-a-time view across a team in five zones./showcase/sundial/demo
- Chat assistantTernTern, an invented chat assistant: conversations with streamed replies, code and tables, projects, a canvas, sharing and settings./showcase/tern/demo
- Banking & budgetsTuppenceTuppence, an invented personal bank: multi-currency accounts, a statement by day with search and splits, spending and budgets, savings pots, bills ahead, cards that freeze and a transfer flow, all with fake money./showcase/tuppence/demo
- Streaming serviceVesperVesper, an invented streaming service: profiles, a home of sideways shelves under a billboard, series with seasons and episodes, search, My List and a theater player./showcase/vesper/demo
- Travel bookingWayfernWayfern, an invented travel app: stays, flights, cars and packages from one search, results on a real map, seat maps and boarding passes, and one itinerary of trips that exports to calendars./showcase/wayfern/demo
Every demo, landings and docs sites alike, is listed in the showcase.
Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { Toast } from "@sdxc/ui/app";Renders a single toast panel, tinted, bordered, and shadowed by
Toast.Props.color, with role and aria-atomic defaulted
(overridable); pair a mix-driven enterExit(), since it holds still.
Composition
The parts the component publishes, each a static property of the host.
ToastToast.IconRenders Toast.IconProps.children as the toast's leading icon, hidden from assistive technology since the toast's color and text already carry its meaning; swap in Toast.Loader while pending.Toast.LoaderRenders Toast.LoaderProps.children as the toast's loading graphic, laid out identically to Toast.Icon so swapping between them keeps the layout stable; pair aspin()mixfactory for its rotating loop.Toast.ContentRenders Toast.ContentProps.children as the toast's body block: a column flex container that shrinks to fit alongside a leading icon or trailing action, holding Toast.Title and Toast.Description.Toast.TitleRenders Toast.TitleProps.children as the toast's heading, in a native<h3>sized and weighted as a small, single-line label above the toast's description.Toast.DescriptionRenders Toast.DescriptionProps.children as the toast's supporting message, in a native<p>set slightly translucent against the toast's foreground color so it reads as secondary to Toast.Title.Toast.ActionRenders Toast.ActionProps.children as the toast's primary trailing control;typedefaults to"button", ordered before the consumer's attributes socommand/commandforstill run; usetype="submit"for a form.Toast.CancelRenders Toast.CancelProps.children as a neutral-tinted, secondary trailing control;typedefaults to"button", ordered before the consumer's attributes socommand/commandforstill run.Toast.CloseRenders a dismiss control for the ancestor Toast: an icon-only<button>removable via a consumer's mixin or thecommandfor/commandpair;type="button"precedes those attributes so the pairing still runs.Toast.RegionRenders the fixed viewport stacking every queued Toast at a corner via Toast.RegionProps.placement;pointer-eventsstaysnoneso clicks pass through to content behind, restored per toast.
Examples
Stack
View code
<Button
mix={[
on("click", () => {
for (let name of monitors) pageToaster().add({ title: `${name} paused` });
}),
]}
>
Pause five monitors
</Button>
<Toasts labels={{ region: "Notifications", dismiss: "Dismiss" }} max={3} />Undo after a delete
- Checkout API
- Search
- Webhooks
View code
function remove(name: string) {
let index = monitors.indexOf(name);
monitors = monitors.filter((monitor) => monitor !== name);
void handle.update();
pageToaster().add(
{
title: "Monitor deleted",
description: name,
action: {
label: "Undo",
onAction: () => {
monitors.splice(index, 0, name);
void handle.update();
},
},
},
{ duration: TOAST_UNDO_DURATION },
);
}Promise
View code
pageToaster().promise(saveMonitor(), {
loading: { title: "Saving monitor", loading: true },
success: { title: "Monitor saved", color: "success" },
error: { title: "Couldn't save monitor. Try again.", color: "danger" },
});Flash from the server
View code
// In the layout's controller:
let flash = session.get("toast"); // set by the redirecting action
// { id: "6f1c…", color: "success", title: "Monitor deleted",
// action: { label: "Undo", form: { action: "/monitors/restore", fields: { id } } } }
<Toasts
labels={{ region: "Notifications", dismiss: "Dismiss" }}
initial={flash ? [flash] : []}
/>Action and cancel
Upload of checks.yml failed
View code
let open = true;
function close() {
open = false;
void handle.update();
}
open ? (
<Toast
id="upload-failed"
color="danger"
live="assertive"
mix={[
dismiss({ duration: null }),
on<HTMLDivElement, "ui:dismiss">("ui:dismiss", close),
]}
>
<Toast.Content>
<Toast.Title>Upload of checks.yml failed</Toast.Title>
</Toast.Content>
<Toast.Action mix={[on<HTMLButtonElement, "click">("click", close)]}>Retry</Toast.Action>
<Toast.Cancel commandfor="upload-failed" command="--ui-dismiss">
Dismiss
</Toast.Cancel>
</Toast>
) : (
<Button
variant="outline"
mix={[
on<HTMLButtonElement, "click">("click", () => {
open = true;
void handle.update();
}),
]}
>
Show the failure again
</Button>
)Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
color | "brand" | "neutral" | "success" | "warning" | "danger" | — | No | Semantic tone of the toast. Default: "neutral". |
live | "polite" | "assertive" | "off" | — | No | aria-live politeness for the toast's content. Default: "polite". |
children | RemixNode | — | Yes | The toast's compound parts: Toast.Icon, Toast.Content, Toast.Action, or any other content. |
Also accepts everything in TagProps<"div">.
Toast.Icon
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The icon graphic, typically a single SVG icon. |
Also accepts everything in TagProps<"div">.
Toast.Loader
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The loading graphic shown in place of Toast.Icon while the toast represents pending work. |
Also accepts everything in TagProps<"div">.
Toast.Content
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The toast's title, description, or other body content. |
Also accepts everything in TagProps<"div">.
Toast.Title
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The toast's heading text. |
Also accepts everything in TagProps<"h3">.
Toast.Description
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The toast's supporting message text. |
Also accepts everything in TagProps<"p">.
Toast.Action
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The action's label. |
Also accepts everything in TagProps<"button">.
Toast.Cancel
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | RemixNode | — | Yes | The cancel control's label. |
Also accepts everything in TagProps<"button">.
Toast.Close
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
"aria-label" | string | — | Yes | Accessible label for the icon-only control — required, since the button carries no visible text for assistive technology to read. |
Also accepts everything in TagProps<"button">.
Toast.Region
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
placement | "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end" | — | No | Corner of the viewport the stack renders in. Default: "bottom-end". |
max | number | — | No | Most toasts shown at once; older ones wait out of sight until a newer one leaves. Default: 3. |
stack | "peek" | "list" | — | No | "peek" folds older toasts behind the newest, scaled to 0.95 and 0.9, and fans them out while the pointer or focus is on the stack; "list" always shows them one under another. Default: "peek". |
children | RemixNode | — | No | Every currently queued Toast. |
Also accepts everything in TagProps<"div">.
Types
| Name | Values | What it decides |
|---|---|---|
Color | "brand" | "neutral" | "success" | "warning" | "danger" | Semantic tone driving the host element's border, tint, and foreground color through the --ui-* variables for that color. |
Live | "polite" | "assertive" | "off" | aria-live politeness applied to the host element. |
Placement | "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end" | Corner of the viewport Toast.Region renders in. |
Stack | "peek" | "list" | How Toast.Region lays out more than one toast. |
Also exported
Other components this module publishes.
pageToaster