Toast

A succinct message that is displayed temporarily, providing feedback about an operation.

Installation

$ npx shadcn@latest add "/r/toast.json"

Usage

To use the toast component, wrap your application in a ToastProvider and include a ToastViewport within a ToastPortal. Then, use the useToast hook to trigger notifications.

Variants

Toasts come with several variants to convey different statuses. The component automatically renders an appropriate icon for each variant.

Examples

With Action

You can add an interactive action to the toast using the ToastAction component.

Props

ToastRoot

PropTypeDefaultDescription
variant`"default""success""error"
childrenReact.ReactNode-The content of the toast.
classNamestring-Additional CSS classes for the toast root.

ToastProvider

PropTypeDefaultDescription
childrenReact.ReactNode-The application components that can trigger toasts.

ToastViewport

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the toast viewport.

ToastTitle

PropTypeDefaultDescription
childrenReact.ReactNode-The title text for the toast.
classNamestring-Additional CSS classes for the title.

ToastDescription

PropTypeDefaultDescription
childrenReact.ReactNode-The description text for the toast.
classNamestring-Additional CSS classes for the description.

ToastClose

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the close button.

ToastAction

PropTypeDefaultDescription
childrenReact.ReactNode-The content of the action button.
onClick() => void-Function called when the action button is clicked.
classNamestring-Additional CSS classes for the action button.