Components
Toast
Transient corner notification raised from anywhere in the code through a shared toastManager.
import { Toast, toastManager } from "@openperf/deft";
<Toast.Provider>{children}</Toast.Provider>;
toastManager.add({ title: "Project created", description: "Checkout" });Mount Toast.Provider once with the root providers, inside the Lingui I18nProvider that the close button label needs. It renders the toast list itself. toastManager is a plain module export, not a hook, so it also works outside React.
When to use
| Need | Component |
|---|---|
| Confirm that an action finished or failed, without blocking | Toast |
| Message that stays next to the content it is about | Callout |
| A decision the user has to make | Dialog or Confirm dialog |
Types
type picks the icon:
type | Icon |
|---|---|
| not set | Success check |
"danger" | Alert circle |
"warning" | Alert triangle |
"loading" | Spinner |
| anything else | No icon |
toastManager.add({
id: "project-save-error",
title: "Could not save the project",
description: "The name is already taken.",
type: "danger",
});Adding a toast with an id that is already on screen updates that toast and restarts its timer. Give repeated messages, such as error toasts, a stable id so they do not stack up copies.
Lifetime and stacking
A toast closes after 5 seconds unless timeout is set. A loading toast stays until it is updated or closed.
Toasts sit in the bottom right corner, 360px wide at most. At most three are visible: older ones collapse behind the newest, and the stack expands on hover or focus. A swipe right or down dismisses a toast, and F6 moves focus to the toasts and pauses their timers.
Action
actionProps adds one button after the text:
toastManager.add({
title: "Issue created",
actionProps: { children: "Open", onClick: openIssue },
});API
Toast also re-exports the Base UI parts of a single toast (Toast.Root, Toast.Title, Toast.Close and the rest), Toast.useToastManager and Toast.createToastManager unchanged. The provider already renders the parts.
Toast.Provider
toastManager cannot be passed: the provider always uses the shared one.
Prop
Type
toastManager
| Method | Description |
|---|---|
add(options) | Shows a toast and returns its id. |
update(id, options) | Changes a toast that is on screen. |
close(id) | Closes one toast, or all of them when called without an id. |
promise(promise, options) | Shows a loading toast and updates it when the promise settles. |
promise marks the settled states with the types success and error. Neither has an icon, so the toast loses the spinner and shows only text.
Options of add:
Prop
Type