| title | Toast |
|---|---|
| description | Displays temporary notification messages using Base UI Toast primitives. |
| source | packages/raystack/components/toast |
import { preview, basicDemo, typesDemo, descriptionDemo, actionDemo, promiseDemo, positionDemo, updateDemo } from "./demo.ts";
Import and set up the toast system:
import { Toast, toastManager } from '@raystack/apsara'
// Wrap your app with Toast.Provider (once, at root)
<Toast.Provider position="bottom-right">
<App />
</Toast.Provider>
// Trigger toasts from anywhere
toastManager.add({ title: 'Hello!', type: 'success' })Renders the toast viewport and manages the toast lifecycle. Place once at the root of your app.
Creates a new toast and returns its unique ID. The toastManager can be imported and used anywhere — including outside React components (e.g., API interceptors, utility functions).
| Method | Signature | Description |
|---|---|---|
add |
(options) => string |
Create a toast, returns its ID |
close |
(id: string) => void |
Close a specific toast by ID |
update |
(id: string, options) => void |
Update an existing toast's properties |
promise |
(promise, { loading, success, error }) => Promise |
Create a toast that tracks a promise lifecycle |
Use the type prop to change the visual styling of the toast.
Use actionProps to render an action button inside the toast.
Track an async operation with automatic loading, success, and error states.
Control where toasts appear on screen with the position prop on Toast.Provider.
Create a toast, then update or close it programmatically using the returned ID.
- Uses
aria-liveregions for screen reader announcements priority: 'high'usesrole="alert"(assertive) for urgent notificationspriority: 'low'(default) usesrole="status"(polite) for non-urgent notifications- Close button has
aria-label="Close toast" - Supports keyboard navigation and Escape to dismiss
- Swipe-to-dismiss gesture support
- Respects motion preferences: toast enter/exit motion is enabled only when
prefers-reduced-motion: no-preference