Toast
Shows a brief notification after an action.
toast-demo.tsx
Installation
The CLI adds the files, packages, theme variables, and Tailwind plugin that this component uses. Before you run it, set up your project.
npm
yarn
pnpm
bun
Composition
ToastViewportRender it once in the root layout. Stacks up to three toasts.
showToast Queues a toast and returns its key. Call it from an event handler.
Variants
toast-status-demo.tsx
Action
A toast with an action stays open until the user closes it.
toast-action-demo.tsx
Stack
Hover or focus the stack to expand it. Swipe a toast to close it.
toast-stack-demo.tsx
Timeout
A toast closes after 5 seconds. Set timeout to 0 to keep it open.
toast-timeout-demo.tsx
API reference
vip/ui adds or changes the props below. For all other props, see React Aria Toast (opens in a new tab).
ToastViewport
- children: ({ toast }) => ReactElement
- Renders each toast. Build it from Toast, ToastIcon, ToastContent, ToastTitle, ToastDescription, ToastAction, and ToastClose.
showToast message
showToast(message, options) shows a toast and returns its key. To close that toast, call toastQueue.close(key).
- title: stringRequired
- The main text of the toast.
- description: string
- Text below the title.
- variant: "info" | "success" | "warning" | "error" = "info"
- Sets the icon and its colors.
- action: { label: string; onAction: () => void }
- Adds a button after the text. A press calls onAction and closes the toast.
showToast options
- timeout: number = 5000
- Milliseconds before the toast closes. Values under 5000 become 5000. Set 0 to keep the toast open until the user closes it. A toast with an action defaults to 0. Hover and focus pause the timer.