Toast is an imperative singleton that presents a short, non-blocking message at the top of the display and dismisses it on its own. Reach for it to confirm something that already happened — “Settings saved”, “Photo deleted” — never to ask a question, offer an action, or report a failure the user has to recover from.App already renders the single ToastContainer that paints it, so there is no toast component for an application to render — you just call Toast.show.Toast.show from an event handler. There is nothing to mount and no state to hold.import { Button, Page, Toast } from '@wearables-ui-toolkit/mrbd';
export function SettingsScreen() {
return (
<Page>
<Button
title="Save"
onActivate={() => {
Toast.show('Settings saved');
}}
/>
</Page>
);
}
import { Toast, type ToastIdentifier } from '@wearables-ui-toolkit/mrbd';
const token: ToastIdentifier = Toast.show('Uploading photo', '3 remaining', uploadIcon);
// The upload was cancelled before the toast finished.
Toast.cancel(token);
App mounts the presenter for you, so an application root needs no toast markup:import { App } from '@wearables-ui-toolkit/mrbd';
export function Root() {
return (
<App>
<SettingsScreen />
</App>
);
}
useToast when a component needs to know what is currently on screen — for example to skip an announcement it would otherwise duplicate:import { useToast } from '@wearables-ui-toolkit/mrbd';
function SaveStatus() {
const toast = useToast();
const isAnnouncingSave = toast?.message === 'Settings saved';
return isAnnouncingSave ? null : <SavedBadge />;
}
| Method | Signature | Description |
|---|---|---|
Toast.show | show(message: string, metadata?: string, icon?: IconSource, style?: ToastStyle): ToastIdentifier | Enqueues a toast and returns the identifier used to cancel it. Presents immediately when nothing else is on screen. style defaults to ToastStyle.STANDARD. |
Toast.cancel | cancel(token: ToastIdentifier): void | Removes the toast from the queue. If it is the one currently on screen, its exit fade starts right away. |
Toast.cancelAll | cancelAll(): void | Empties the pending queue. A toast already on screen finishes its normal display and fade. |
icon accepts any IconSource: an inline vector, an asset descriptor, or a URL string.| Hook | Returns | Description |
|---|---|---|
useToast | the toast being presented, or null | Subscribes to the presenter and re-renders when the presented toast changes. The value carries message, metadata, icon, style, and token. |
null for the whole visible lifetime of a toast, including its exit fade, and drops back to null in the gap before the next one. Use it only to observe the queue — rendering the toast itself is the container’s job.ToastContainer is the component that paints the presented toast, and App renders it for you. It is exported so its props type is nameable and so tests and previews can render one in isolation; applications should not mount their own.ToastContainerProps. Both props are escape hatches for nudging the container inside a preview harness; the container still owns its layout, gradient, and the chip inside it.| Prop | Type | Default | Description |
|---|---|---|---|
className | string | '' | Extra class on the container element. |
style | CSSProperties | {} | Extra inline styles on the container element. Position and stacking level are set by the container afterwards and cannot be replaced here. |
ToastStyle| Member | Description |
|---|---|
STANDARD | The only style. Draws the message on an elevated Chip. |
ToastIdentifiernumber handed back by Toast.show and accepted by Toast.cancel. Treat it as an opaque token.Chip, which owns its own intrinsic sizing and material.--uit-color-background-window to --uit-color-background-flat behind it so the message stays legible over whatever is underneath.App, above route content, and falls back to the document body when there is no App root. See Floating portals.App is mounted still runs its display timer and expires unseen, so do not enqueue one during module evaluation and expect it to wait for the application root.show, cancel, and cancelAll do nothing and show returns 0.role="status", aria-live="polite", aria-atomic="true"), so the message and metadata are announced when it appears. You supply the wording; the container supplies the role.metadata.message and metadata; the utility never translates them.ToastContainer; App already renders one.Modal surface, or a progress indicator.cancel to do anything with a token whose toast has already finished; identifiers come from a monotonic counter, so a stale one simply matches nothing.