Toast
Stacked and anchored notifications with actions, semantic status icons and swipe-to-dismiss behavior.
Installation
npx shadcn@latest add "@aiellie/toast"shadcn needs the @aiellie registry in components.json first. npx aiellie add toast adds it on its first run, then installs the same way.
Toast says something happened without stopping anyone: a save, a copy, an export that finished or failed. It is Base UI's toast with this registry's glass on it. Toasts stack in the corner of the screen, or anchor to the button that caused them for a quick confirmation, and each one wears an icon for its type.
Getting started
Add the provider and a toaster
Once, near the root of the app. A manager made outside React lets anything add a toast, not only components.
app/providers.tsx"use client" import { ToastProvider, Toaster, createToastManager, } from "@/components/ui/toast" export const toasts = createToastManager() export function Providers({ children }: { children: React.ReactNode }) { return ( <ToastProvider toastManager={toasts}> {children} <Toaster /> </ToastProvider> ) }Add a toast
typepicks the icon:success,info,warning,errororloading.actionPropsadds a button, like Undo.toasts.add({ title: "Chat deleted", description: "It's gone from your history.", type: "success", actionProps: { children: "Undo", onClick: restore }, })
Anatomy
<div data-slot="toast-viewport"> {/* Toaster: the bottom corner, stacking */}
<div data-slot="toast" data-type="success"> {/* glass, a shadow */}
<div data-slot="toast-content">
<span data-slot="toast-icon" />
<div data-slot="toast-title" />
<div data-slot="toast-description" />
<button data-slot="toast-action" /> {/* only with actionProps */}
</div>
<button data-slot="toast-close" />
</div>
</div>
{/* AnchoredToaster: each toast beside its anchor */}
<div data-slot="toast-positioner">
<div data-slot="toast"><span data-slot="toast-arrow" />…</div>
</div>Stacked toasts fan out behind the newest, open up on hover, and can be swiped away. They slide in from below and out the same way; a toast pushed out by the limit fades instead. An error toast's title is in destructive. A loading toast spins until its promise settles, then becomes the success or error toast in place.
Anchored toasts are one line, a description and an icon, with an arrow toward the anchor. Both toasters take variant="solid" to drop the blur.
Examples
Follow a promise
promise shows the loading toast and swaps it for the outcome.
Anchored to its button
With an AnchoredToaster, pass positionerProps with the element to point at.
API reference
Toaster and AnchoredToaster
Both take Base UI's Toast.Viewport props and render the toasts in a portal.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "glass" | "solid" | "glass" | With or without the blur behind each toast. |
showArrow | boolean | true | AnchoredToaster only: points the toast at its anchor. |
className | string | Merged onto the viewport. |
toasts.add
The manager is Base UI's. These are the options this registry's toasts read.
| Option | Type | Description |
|---|---|---|
title / description | ReactNode | What it says. |
type | "success" | "info" | "warning" | "error" | "loading" | Its icon, and for error the title's color. |
timeout | number | How long it stays, in ms. 0 keeps it until it is closed. |
priority | "low" | "high" | high is announced at once to screen readers. |
actionProps | ButtonProps | Adds a button, like Undo. |
positionerProps | { anchor, side, align } | Where an anchored toast points. |
Parts
| Export | Notes |
|---|---|
ToastProvider | Holds the toasts. Pass toastManager to add them from outside React. |
createToastManager / useToastManager | Make a manager, or reach the provider's from a component. |
Toast, ToastContent, ToastTitle, ToastDescription, ToastAction, ToastClose, ToastIcon | The pieces the toasters are built from, for a toaster of your own. |
ToastPortal, ToastViewport, ToastPositioner, ToastArrow | Where toasts render, and how an anchored one is placed. |