Toast notifications for short confirmations and alerts. Routine toasts are announced politely
and dismiss after 6 seconds; warning and danger toasts are announced immediately, and danger
toasts stay until the user dismisses them. The timer pauses while the pointer or keyboard focus
is on a toast.
toast.add({
tone: 'danger',
title: 'Sensor offline',
message: 'CW-AIR-014 has not reported for 2 hours.'
// danger toasts stay until dismissed; pass duration to override
});
Duration & dismissal
Stacking
At most 4 toasts are shown. When the stack is full, the oldest routine toast is removed first,
so danger and warning toasts are never pushed out by routine ones. This button adds one danger
toast and five info toasts.
API
Usage and API reference
The toast system is a small context-based API rather than a single component. Create the context once, mount a container once, and then call `toast.add(...)` anywhere below that tree.
How to think about it
Create the context high in the treeCall `createCwToastContext()` in a layout or root component so all child routes can access the toast API.
Render one containerMount `CwToastContainer` once, usually near the root layout, so notifications have a consistent stack location.
Trigger toasts from feature codeUse `useCwToast()` in child components and call `toast.add(...)` after save, error, or background events.
System API
API
Type
Details
createCwToastContext(maxItems?)
(maxItems?: number) => CwToastApi
Creates and stores the toast context. Call this once near the app root.
useCwToast()
() => CwToastApi
Reads the toast API from context inside child components.
<CwToastContainer />
component
Renders the visible toast stack for the current context.