Toast
BasicFeedback
<co-toast>Toast confirms a finished action at the bottom of the screen for about 2.8 seconds, in the "... Successfully" voice.
import { Toast } from 'health-components';
Examples
Tones
With Undo
With Provider
Usage
{toast && <Toast tone="success" message="Draft Saved Successfully" />} // hide after 2800 ms
In an app, wrap the root in ToastProvider and use the hook: toasts queue in a portal, hide after 2800 ms (5000 ms with an action; hover or focus pauses), and errors stay until dismissed.
<ToastProvider><App /></ToastProvider>
const toast = useToast();
toast.success("Draft Saved Successfully");
toast.show({ message: "Notification Deleted Successfully", tone: "success", action: "Undo", onAction: restore });
toast.error("Could not save. This browser is blocking storage; nothing was changed.");
When to use
- Background confirmation that needs no action.
When not to use
- Errors the user must fix: field error or Alert.
- Big completions (claim submitted): SuccessDialog.
Variants and states
| Variant | What it is |
|---|---|
| neutral | Default. |
| success | Check icon. |
| error | Alert icon, role alert, stays until dismissed. |
| action | One text action, such as Undo. |
| inline | Static, for previews and docs. |
Accessibility
- role status with aria-live polite; errors role alert.
- Do not auto-hide a toast that holds an action in under 5 seconds.
Do and don't
- Do: Title Case object and verb plus Successfully: "Appointment Type Added Successfully".
- Don't: "Success!"
- Don't: Toasts for errors that block the task.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | — | Message in the "... Successfully" voice ("Draft Saved Successfully"). Falls back to `children`. |
tone | ToastTone | 'neutral' | 'neutral' | 'success' | 'error' |
action | string | none | One text action, such as "Undo" |
onAction | () => void | none | Action handler |
onDismiss | () => void | none | Shows a Dismiss (x) button that calls this |
inline | boolean | false | Static, rendered in place (previews, docs, and inside ToastProvider); otherwise fixed at the bottom through a portal |
children | ReactNode | — | Message content when `message` is not set |
Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, plus className and event handlers on the root element.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-toast>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-toast message="…" tone="…" [defaultValue]="defaultValue" (co-action)="onAction($event.detail)">…</co-toast>
| Kind | Name | Description |
|---|---|---|
| attribute | message | Message in the "... Successfully" voice ("Draft Saved Successfully"). Falls back to `children`. |
| attribute | tone | 'neutral' | 'success' | 'error'; default 'neutral' |
| attribute | action | One text action, such as "Undo"; default none |
| attribute | inline | Static, rendered in place (previews, docs, and inside ToastProvider); otherwise fixed at the bottom through a portal; default false |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| event | co-action | Action handler; default none (React: onAction) |
| event | co-dismiss | Shows a Dismiss (x) button that calls this; default none (React: onDismiss) |
| slot | (default) | Message content when `message` is not set |