Toast
A transient notification that announces itself and slips away; color and meaning on independent axes, in a live-region stack.
Live demo
Toast surfaces brief, transient feedback without stealing focus. Two axes drive it independently.
severity (success, warn, danger, info) carries the meaning: the status glyph and the live-region politeness, so danger/warn announce assertively. tone carries the color, from the full palette. A severity paints its standard color by default (danger reads red), but a tone overrides it, and a color-only toast (a non-status tone, no severity) shows no glyph and announces politely. A xtyle-toast-region is a fixed live-region container with an imperative toast(opts) method that pushes cards; each carries one of two variants: soft, an overlay card with a colored edge, or solid, a fully filled card. Toasts enter and leave with a tokened transition, auto-dismiss after a configurable delay that pauses while the pointer or focus rests on them, and may carry a single action button and a close button. A standalone xtyle-toast element is also exposed for declarative, statically-placed notices.
When to use
How this component composes with the rest of the set.
Props
10 props, straight from the manifest.
| Prop | Type | Default | Bindings | Description |
|---|---|---|---|---|
severity color (info when neither is set); set it to recolor a severity or to tint a color-only notice. | ||||
danger/warn announce assertively). Omit for a color-only toast with no glyph. A bare status-named tone implies the matching severity. | ||||
toast(opts) API; the slot carries it declaratively. | ||||
0 keeps the toast until dismissed. Pauses on hover/focus. (Imperative API.) | ||||
false (closable="false" in raw HTML) to drop it, and pair that with a duration so the toast can still leave. | ||||
Events
What the component emits, and what rides along on event.detail. The name in the
first column is the one addEventListener takes.
| Event | Detail | Bindings | Description |
|---|---|---|---|
Methods
What you can call on the element itself — the half of the surface a prop or an event cannot express. A control driven by a gesture, or one whose state the platform owns, opens here. Astro renders on the server and hands back no instance, so no method is reachable from it.
| Method | Returns | Bindings | Description |
|---|---|---|---|
Appearance
Variants
soft
An overlay surface card with a tone-colored border and tone-colored icon.
solid
Filled with the tone color, with on-fill ink and icon.
States
enter
Mount transition: the toast fades and slides into place over --duration-base.
leave
Dismiss transition: the toast fades and slides out before removal.
action-hover
Pointer over the action button: overlay paints the hover tint.
focus-visible
Keyboard focus on the action or close button: a token ring plus a transparent outline promoted in forced-colors mode.
Anatomy
The named parts that make up the component. A ::part() handle is reachable from your own stylesheet; the class beside it is the component's internal selector, which a shadow boundary keeps to itself.
toast-region
The fixed, non-focus-stealing live-region container that stacks and announces toasts.
toast
A single notification card carrying the variant and tone classes.
icon
The severity glyph, shown when a severity is set, drawn in the card color (soft) or the on-fill ink (solid). Project an icon slot to override it (declarative xtyle-toast / Toast).
message
The notification text; the content that gets announced.
action
An optional inline action button that runs a callback then dismisses the toast.
close
The dismiss button in the top corner.
Tokens & coverage
What the component consumes, checked live against what the algorithm produces.
Live coverage check against the xtyle-default register
(derive(xtyleDefault, { anchors }) →
coverComponent(manifest, register)). Every token this component
consumes must be a key the algorithm produces.
--accent--accent-2--accent-2-fg--accent-3--accent-3-fg--accent-4--accent-4-fg--accent-fg--black--black-fg--blue--blue-fg--border-normal--border-thick--border-thin--brown--brown-fg--cyan--cyan-fg--danger--danger-fg--duration-base--duration-fast--ease-emphasized--ease-standard--fg-0--font-sans--gray--gray-fg--green--green-fg--info--info-fg--layer-toast--leading-normal--leading-tight--neutral--neutral-fg--orange--orange-fg--pink--pink-fg--purple--purple-fg--radius-md--radius-sm--red--red-fg--ring--shadow--space-0--space-1--space-3--space-4--space-5--space-6--state-hover--state-press--success--success-fg--surface-overlay--surface-overlay-border--text-body--text-lg--text-sm--warn--warn-fg--weight-medium--weight-semibold--white--white-fg--yellow--yellow-fgSlots
The toast message (declarative xtyle-toast / Toast).
Overrides the built-in severity glyph on a declarative toast; fill it to show your own icon (not available through the imperative toast(opts) API).
Accessibility
Code
Tones, variants, and the imperative region
Push toasts from a region, or place a standalone toast declaratively. The four status tones span both variants.
<xtyle-toast-region id="toasts" placement="bottom-right"></xtyle-toast-region>
<script type="module">
const region = document.getElementById("toasts");
region.toast({ message: "Settings saved." });
region.toast({
tone: "success",
variant: "solid",
message: "Your profile is live.",
});
region.toast({
tone: "danger",
message: "Upload failed.",
actionLabel: "Retry",
onAction: () => retryUpload(),
});
region.toast({
tone: "info",
message: "Sync paused while offline.",
duration: 0,
});
region.toast({
severity: "success",
message: "Copied to clipboard.",
closable: false,
duration: 2000,
});
</script><script lang="ts">
import { Toast } from "@xtyle/svelte";
</script>
<Toast tone="success" variant="soft">Settings saved.</Toast>
<Toast tone="danger" actionLabel="Retry" onaction={() => retryUpload()}>
Upload failed.
</Toast>
<Toast tone="info" closable={false}>Sync paused while offline.</Toast>---
import { Toast } from "@xtyle/astro";
---
<Toast tone="success" variant="soft">Settings saved.</Toast>
<Toast tone="danger" actionLabel="Retry">Upload failed.</Toast>
<Toast tone="info" closable={false}>Sync paused while offline.</Toast>