UI

Toast

Non-blocking status cards, stacked viewport notifications, and countdown undo toasts.

import { Toast, Toaster, createToaster } from '@uthereal/ui/toast'

Toast playground

Release 4.2 publishedLive for 1,284 customers.
Loading interactive preview…

Overview

@uthereal/ui/toast unifies three notification patterns on one visual contract:

ModeAPIUse for
Declarative<Toast />One in-place status card controlled by React state or an agent composition.
Stacked viewport<Toaster /> + createToaster()Application-wide notifications pushed from event handlers that tuck behind the newest card.
Undo<Toast undo /> or toaster.undo()Reversible removals with a draining countdown ring, batch merging (mergeKey), and Cmd/Ctrl+Z.

Use a toast for transient results that require no blocking decision. Use a dialog for blocking decisions or irreversible destructive confirmations.

Tones

ToneVisual cueDefault lifetimeWhen to use
neutralInfo glyph (--ui-muted)4500 ms (<Toast>) / 5000 ms (stack)General status updates and undo batches.
infoInfo glyph (--ui-accent)4500 ms / 5000 msBackground updates and team activity.
successDrawn check (<Toast>) or circled check (--ui-success)4500 ms / 5000 msCompleted actions ("Release 4.2 published").
warningAlert triangle (--ui-warning)1.6x base in stack (8000 ms)Limits or degraded states that keep working.
dangerCircled X (--ui-danger)1.6x base in stack (8000 ms)Failed actions (toaster.error()).
loading800 ms spinner (--ui-muted)Indefinite until updatedIn-progress work replaced via toaster.update() or toaster.promise().

Usage

Declarative <Toast />

Render <Toast /> directly in React or in an agent composition. Control visibility with open and onOpenChange, or leave it uncontrolled with defaultOpen. Set duration={0} to keep the card visible until dismissed.

'use client'
import { useState } from 'react'
import { Toast } from '@uthereal/ui/toast'

export function ReleaseConfirmation() {
  const [open, setOpen] = useState(true)
  return (
    <Toast
      open={open}
      onOpenChange={setOpen}
      tone="success"
      title="Release 4.2 published"
      description="Live for 1,284 customers."
      actionLabel="View"
      action="view_release"
      onAction={(action) => console.log(action)}
    />
  )
}

Stacked <Toaster /> + createToaster()

Create one toaster outside render, mount <Toaster toaster={toaster} /> once, and push toasts from event handlers. Pass contained on <Toaster /> to pin the stack inside the nearest positioned container instead of the viewport.

'use client'
import { Toaster, createToaster } from '@uthereal/ui/toast'

export const toaster = createToaster({
  position: 'bottom-end',
  visibleToasts: 3,
  limit: 12,
})

export function App() {
  return (
    <>
      <InvoiceForm
        onSent={() =>
          toaster.success({
            title: 'Invoice sent',
            description: 'Northwind will receive it by email.',
          })
        }
      />
      <Toaster
        toaster={toaster}
        onAction={(action, toastId) => console.log(action, toastId)}
      />
    </>
  )
}

Undo mode (toaster.undo and <Toast undo />)

Undo mode replaces the status icon with a draining countdown ring (6000 ms by default) and shows an Undo button with a ⌘Z / Ctrl Z cap on fine pointers. Host callbacks own all data effects:

  • onUndo runs when the user clicks Undo, clicks Retry, or presses Cmd/Ctrl+Z. Returning a promise transitions the toast through counting → restoring (disabled button + spinner) → restored (drawn check for 2000 ms) or error (Retry button).
  • onCommit runs when the countdown drains or Escape commits the active undo window.
  • Repeat toaster.undo(...) calls sharing a mergeKey merge into the active counting toast: count rolls up digit-by-digit, the countdown ring refills, and the card plays a subtle scale nudge.
'use client'
import { toaster } from './toaster'

export function archiveThread(id: string) {
  hideThread(id)
  toaster.undo(
    {
      mergeKey: 'archive-threads',
      title: 'conversations archived',
      undoLabel: 'Undo',
    },
    {
      onUndo: () => restoreArchivedThreads(),
      onCommit: () => commitArchivedThreads(),
    },
  )
}

Examples

Tones and actions

Single declarative <Toast /> cards across info, warning, danger, and loading states with optional descriptions and action buttons (success is shown in the playground above).

Invite sent to Maya ChenShe can join once she accepts the email link.
Storage at 92% capacityArchive older exports to stay within your plan.
Webhook delivery failedEndpoint returned HTTP 502 after 3 retries.
Exporting audit logPreparing 14,200 events as CSV.

Undo countdown and batch counts

Declarative <Toast undo /> cards with the live draining countdown ring, rolled batch count, and Cmd/Ctrl+Z shortcut cap.

Conversation archived
4conversations archived

Live stacked viewport

Trigger tones, promise updates, live undo batching (toaster.undo with mergeKey), morphing actions, placements, and overlap behavior in a live <Toaster />.

Create a toast.

Imperative queue methods

Every helper validates its input against toastSchema and returns the toast ID.

MethodBehavior
create(input)Shows a toast (tone: 'info' by default). Reusing an active id updates that toast in place.
success, info, warning, errorShows a toast in that tone (error maps to danger).
loading(input)Shows a spinner toast with infinite lifetime until updated or dismissed.
undo(input, { onUndo, onCommit? })Shows an undo countdown toast. Matching mergeKey while counting merges into the active toast, increments count, and refills the ring.
update(id, patch)Morphs icon, title, description, height, and action width in place and restarts the timer. Omitted fields keep their values; pass description: undefined or action: undefined to clear one. No-op if dismissed.
promise(promise, { loading, success, error })Shows a loading toast, then morphs to success or danger when settled. Returns { id, unwrap }.
dismiss(id?)Dismisses one toast, or every toast when called without an ID.

Stacking, gestures, and timing

  • Stack geometry: Older toasts tuck behind the front card with 14 px peeks and 0.05 scale steps on --ui-highlight. Hovering, keyboard-focusing, or tapping (on touch) fans the stack out with gap (12 px) spacing.
  • Pause behavior: Timers and undo countdown rings pause on hover (pauseOnHover), keyboard focus, pointer drag, and hidden browser tabs (visibilitychange), then resume from the exact remaining time.
  • RTL-aware swipe: Swiping toward the inline-end edge (right in LTR, left in RTL) follows 1:1; pulling toward inline-start rubber-bands. Releasing past 80 px or 480 px/s (<Toast>) or projected past 40% width (<Toaster>) throws the card off with its release velocity.
  • Responsive layout: Viewport-fixed stacks sit offset (24 px) from the edges and center 16 px from the edge below 480 px. Contained stacks sit 16 px inside their ancestor. Below 21 rem (336 px) card width, actions wrap under the copy; below 360 px, the shortcut cap hides.

API reference

Declarative <Toast />

ArgumentType / defaultDescription
titleRequiredstring—Required message: what happened, in sentence case.
descriptionstring—Supporting detail under the title.
toneneutral | info | success | warning | danger | loadingDefault: "neutral"Status: neutral or info for results, success with a drawn check, warning and danger longer-lived, loading a spinner until updated.
defaultOpenbooleanDefault: trueInitial open state. Later argument edits do not reset an existing instance; use open and onOpenChange to control it.
durationintegerDefault: 4500Time on screen, ms; 0 stays until dismissed. 4500 by default, or the 6000 undo window in undo mode.
actionLabelstring—Action button text: a verb, e.g. "View".
actionstring—Action name sent to onAction; the toast closes after it.
undobooleanDefault: falseUndo mode: a draining countdown ring, an Undo button and the Cmd/Ctrl+Z shortcut replace the plain lifetime; undo emits onUndo and the drained window emits onCommit.
countinteger—Batch count rolled into the message, e.g. "3 items archived".
undoShortcutbooleanDefault: trueCmd+Z on Apple devices and Ctrl+Z elsewhere trigger the undo, unless focus is in a text field.
undoLabelstringDefault: "Undo"Undo button text in undo mode.
dismissiblebooleanDefault: trueShow a dismiss button.
dismissLabelstringDefault: "Dismiss notification"Accessible name of the dismiss button; {title} fills the toast title.
labelstringDefault: "Notification"Accessible name of the status.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeToastTheme—Color mode, accent, and tokens, including width. See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"Rise and swap animation preset. System reduced-motion preferences take precedence.
motionOptionsToastMotionOptions—Overrides for the stack spring and the press scale.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

<Toaster />

ArgumentType / defaultDescription
labelstringDefault: "Notifications"Accessible name of the notification region; " (Alt+T)" is appended while the hotkey is on.
dismissLabelstringDefault: "Dismiss notification"Name of each dismiss button; {title} is replaced by the toast title, e.g. "Dismiss Invoice sent".
statusLabelsToastStatusLabels—Status read before each toast by screen readers: info, success, warning, danger ("Error") and loading ("In progress"). Neutral toasts have none.
containedbooleanDefault: falsePin the stack inside the nearest positioned ancestor instead of the viewport.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeToastTheme—Color mode, accent, and tokens, including the stack width. See Theming.
motionnone | subtle | expressiveDefault: "subtle"Stack animation preset. System reduced-motion preferences take precedence.
motionOptionsToastMotionOptions—transition for entering and following the stack (Arc smooth spring), expand for fanning out and tucking back (Arc morph spring), and pressScale for the buttons.
dirltr | rtl—Reading direction; start and end placements follow it. Omit it to use the document direction.

createToaster options

ArgumentType / defaultDescription
positiontop-start | top-center | top-end | bottom-start | bottom-center | bottom-endDefault: "bottom-end"Viewport edge and alignment of the stack (Arc naming). start and end follow the reading direction.
visibleToastsintegerDefault: 3Toasts shown at once, 1 to 10 (Arc: 3). Later ones wait behind the stack and return as the front ones close.
placementtop-start | top | top-center | top-end | bottom-start | bottom | bottom-center | bottom-end—Legacy spelling of position; top and bottom read as centered.
maxVisibleinteger—Legacy spelling of visibleToasts.
limitintegerDefault: 12Toasts kept in the queue, 1 to 50. The oldest beyond it are dropped.
durationintegerDefault: 5000Base time on screen in milliseconds, 1000 to 60000. Warnings and errors stay 1.6 times longer. Hovering, focusing or tapping the stack, dragging a toast, or hiding the page pauses it.
undoDurationintegerDefault: 6000Undo window in milliseconds, 1000 to 30000 (Arc: 6000). It refills whenever another removal joins the batch.
overlapbooleanDefault: trueTuck older toasts behind the newest; hovering or focusing the stack fans it out. false lists them all.
pauseOnHoverbooleanDefault: trueHold the countdowns while the pointer rests on the stack.
gapintegerDefault: 12Space between toasts in the expanded stack, px.
offsetintegerDefault: 24Distance from the viewport edges, px. Below 480px wide the stack centers 16px from its edge.
hotkeybooleanDefault: trueAlt+T moves focus into the stack and fans it out.

React integration

PropComponentPurpose
refToast, ToasterForwarded to the root HTMLDivElement (Toast) or <section> (Toaster).
open / onOpenChange(open)ToastControlled visibility and dismissal callback.
onAction(action) / onAction(action, toastId)Toast, ToasterHost action callback. In <Toaster>, calling toaster.update(toastId, ...) morphs the toast instead of dismissing it.
onUndo / onCommitToastHost undo and commit callbacks for <Toast undo />; return a promise to show restoring / restored / error.
toasterToasterRequired queue instance from createToaster().
portalContainerToasterPortal target when contained is false; defaults to the enclosing layer, provider, or document.body.
renderIcon(name, { size, slot })Toast, ToasterCustom icon renderer for slot: 'icon' or slot: 'dismiss'. Keep icons decorative.
preset / tokensToast, ToasterApplication defaults and --ui-* CSS custom property overrides.
className / styleToast, ToasterAppended to the root element or stack region.

Keyboard & accessibility

Key / gestureInteraction
Alt + TFocus the <Toaster /> stack and fan it out (hotkey: true).
Cmd + Z / Ctrl + ZTrigger active undo toast (undoShortcut: true). Ignored while focus is inside input, textarea, select, or contenteditable.
Tab / Shift+TabMove through toasts, action/undo buttons, and dismiss buttons.
Enter / SpaceActivate the focused action, undo, or dismiss button.
EscapeCommit a focused counting undo toast, or dismiss any other focused toast.
Swipe inline-endThrow and dismiss the toast (right in LTR, left in RTL).
  • <Toast /> renders with role="status", aria-live="polite", and aria-atomic="true".
  • <Toaster /> mounts a dedicated role="status" live region before any toast appears, announcing status labels, merged batch counts, and undo lifecycle transitions (Restoring, Restored, Error).
  • Toasts waiting behind visibleToasts are inert. Closing a focused toast hands focus to the next toast or restores focus to the element active before entering the stack.
  • Under forced-colors: active, cards preserve CanvasText borders, buttons preserve ButtonText borders, and the countdown ring uses CanvasText track with Highlight fill.

Motion and theming

<Toast /> rises 16 px from scale 0.96 on the morph spring (0.42s, bounce 0.16), draws its success check over 240 ms, and springs height changes with the smooth spring (0.4s, bounce 0). <Toaster /> rises new toasts from their own height beyond the edge on the smooth spring, fans out on the morph spring, and folds removed action buttons horizontally. Copy updates crossfade with a 0.3em vertical shift and subtle blur.

Under prefers-reduced-motion: reduce, travel, scale, blur, and the loading spinner are disabled in favor of 160 ms opacity fades while the countdown ring still drains smoothly. Setting motion="none" makes every transition immediate (0 ms).

Theme tokenCSS variableDefaultRole
width--ui-toast-width360pxPreferred card and stack width, clamped to the viewport.
surfaceRaised--ui-surface-raisedthemeFront and expanded card background.
highlight--ui-highlightthemeTucked card background and control hover fill.
popupRadius--ui-popup-radiusthemeCard corner radius (26px in studio).
shadow / shadowRaised--ui-shadow / --ui-shadow-raisedthemeFloating front shadow and resting tucked shadow.
border / borderStrong--ui-border / --ui-border-strongthemeCard edge and hovered action border.
success / warning / danger / accent--ui-success, --ui-warning, --ui-danger, --ui-accentthemeStatus icons and countdown ring stroke.
shortcutSize--ui-shortcut-size12pxInline ⌘Z / Ctrl Z shortcut hint size.

theme also accepts mode, accent, and core typography and color tokens. An application-wide UtherealProvider supplies shared defaults.

On this page