Skip to content

Toast

Terminal-styled toast notification system. Imperative toast() API callable from anywhere. Supports tone shortcuts (severity), four layout variants, promise handling, and position-aware animations.

Preview

Installation

$pnpm exec dgadd add ui/toast
[Installs to]src/components/ui/toast[Item]ui/toast

dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.

UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.

Usage

tsx
"use client";import { Button } from "@/components/ui/button";import { toast } from "@/components/ui/toast";export default function ToastDefault() {  return (    <div className="flex flex-wrap gap-2">      <Button        variant="primary"        size="sm"        onClick={() => toast.success("Saved", { message: "Changes saved successfully." })}      >        Success      </Button>      <Button        variant="destructive"        size="sm"        onClick={() => toast.error("Error", { message: "Something went wrong." })}      >        Error      </Button>      <Button        variant="secondary"        size="sm"        onClick={() => toast.warning("Warning", { message: "This action cannot be undone." })}      >        Warning      </Button>      <Button        variant="ghost"        size="sm"        onClick={() => toast.info("Info", { message: "A new version is available." })}      >        Info      </Button>    </div>  );}

Examples

All Tones

Preview

Layout Variants

Preview

With Actions

Preview

Positions

Preview

Promise

Preview

Loading

Preview

API Reference

Toaster

NameTypeDefaultDescription
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Corner where toasts stack. Drives positioning classes and slide-in direction.
hotkeystring"F8"Key that moves DOM focus to the toast region. For timed toasts this hotkey (or Tab) is the intended keyboard route — they are exempt from arrow entry because focus on a timer-unmounted element would strand the user; persistent toasts are additionally entered through focusToastRegion, and inside the region ArrowUp/ArrowDown walk the controls either way. Matched against KeyboardEvent.key and ignored while an editable element has focus. Defaults to F8, the Radix viewport hotkey.
labelstring"Notifications"Accessible name for the toast region landmark.

toast (function)

NameTypeDefaultDescription
titlerequiredstringPrimary toast title (first positional argument).
tone"success" | "error" | "warning" | "info" | "loading""info"Severity tone. Drives icon, color, and auto-dismiss behavior. Error and loading tones persist when duration is omitted, except in the `hud` variant which auto-dismisses on the default timer.
variant"card" | "hud" | "viewfinder" | "countdown""card"Visual style variant / layout shell. `card` is the default two-row layout; `hud` is a single-line pill with no body, action, or close button; `viewfinder` has corner brackets; `countdown` adds an auto-dismiss progress bar.
messagestringMessage content: secondary detail text below the title (rendered inline as muted text in `hud`).
durationnumber5000Auto-dismiss delay in ms. Error/loading tones and toasts with a rendered action persist when duration is omitted. The `hud` variant does not render actions or a close button, so it auto-dismisses on the default timer even for error and loading tones. An explicit positive duration schedules dismissal; a non-finite duration (Infinity) opts out of auto-dismissal entirely.
actionReactNodeAction element (e.g. a Button) rendered under the message. The `hud` variant silently omits it.
dismissLabelstring"Dismiss: " + titleAccessible name for the dismiss button. The `hud` variant does not render a close button, so this prop has no effect there.
toneLabelstringthe tone valueAccessible tone label: screen-reader tone text announced before the toast title.
idstringauto-generatedID applied to the rendered element; stable id for updating an existing toast (used by toast.promise to swap loading -> success/error).

Accessibility

Keyboard Navigation

Press Escape to dismiss every visible toast at once. Toast Escape handling is global while toasts are present and runs before lower-priority page overlays unless another handler has already consumed the key. Press the focus hotkey (F8 by default, configurable via the Toaster `hotkey` prop) to move focus into the toast region.

Notes

Imperative API

Call toast(), toast.success(), toast.error(), toast.warning(), toast.info(), or toast.loading() from any code — no provider required. Place a <Toaster /> component in your app layout to render toasts.

Tone vs Variant

`tone` is severity (success/error/warning/info/loading) and drives color and ARIA role. `variant` is the layout shell: `card` (default, full payload), `hud` (single-line pill), `viewfinder` (corner brackets), `countdown` (card + auto-dismiss progress bar).

Promise Support

toast.promise(asyncFn, { loading, success, error }) shows a loading toast that updates to success or error when the promise settles. It returns the input promise and rejects when the input rejects, so callers must handle rejection with await/try-catch or .catch().

Loading Toasts

Loading toasts show a braille spinner and persist when duration is omitted. Use toast.loading() for manual control, or toast.promise() for automatic lifecycle. An explicit positive duration schedules auto-dismissal.

Error Toasts Persist

Toasts with tone='error' persist when duration is omitted and must be closed manually. An explicit positive duration schedules auto-dismissal. The `hud` variant omits the close button and auto-dismisses even for error and loading tones; pass a non-finite duration (Infinity) to opt out.

Actions

Render the `action` slot with the bracketed ghost Button (`<Button variant="ghost" size="sm" bracket>`) so a toast invitation speaks the same [ label ] vocabulary as the rest of the library. A toast with a rendered action and no explicit duration persists until dismissed.

Keyboard

Press Escape to dismiss every visible toast at once, so the key a screen advertises for Escape is at most one extra press away even after an error burst. Toast Escape handling is global when toasts are present, so it runs before lower-priority page overlays that have not already handled the key. Press the focus hotkey (F8 by default, configurable via the Toaster `hotkey` prop) to move focus into the toast region so action and close buttons stay reachable before a timed toast disappears; the hotkey is ignored while an editable element has focus.

Pause Behavior (WCAG 2.2.1)

Auto-dismiss timers pause while the pointer hovers the toaster region, while focus is inside it (so action buttons stay reachable by keyboard), and while the document tab is hidden. Timers resume from the remaining time once interaction ends — users never lose time they could not see or read.

Source

Install via CLI: pnpm exec dgadd add ui/toast. Keyboard hooks are included as standalone copies. For the full experience, use --integration keys.

Highlighted source loads after this disclosure opens. Browse the source repository.