Cómo funciona
A self-contained toast system: ToastProvider renders the region and useToast() returns toast(). Each toast is a floating surface card (18px corners, hairline ring and soft shadow, no border) with its status icon in a tinted rounded square, an optional soft pill action and a quiet round close button. Each toast is absolutely positioned and its transform is computed in JS from measured heights. Collapsed layers shrink 5%, step back 10px and fade 18%. When a layer behind is taller than the front one, clip-path trims the overflow instead of changing height. Timers pause on hover, focus, drag and in background tabs.
Úsalo para
- Light feedback for an action: order placed, saved, copied.
- Messages that must not interrupt the current task, such as a new message or a status change.
- Results with a quick action, such as “Deleted · Undo” or “Order placed · View”.
Busca otra opción cuando
- Information the user must confirm or choose from: use a dialog.
- Validation errors tied to an input: show them next to the field.
- Long content people need to revisit: toasts vanish in seconds, use a message center.
- A page that already uses another notification system: do not mix two.
Uso
import { ToastProvider, useToast } from './ToastProvider.jsx'
export function App() {
return (
<ToastProvider position="bottom-right" duration={4000}>
<OrderButton />
</ToastProvider>
)
}
function OrderButton() {
const toast = useToast()
return (
<button
onClick={() =>
toast.success('Order placed', {
description: 'Trail running shoes · Size 42',
action: { label: 'View', onClick: () => navigate('/orders') },
})
}
>
Order
</button>
)
}
// Inside one panel: give the parent position: relative, then use <ToastProvider contained>Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
ToastProvider.position | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'bottom-right' | Where toasts appear. On the left edge they are swiped left to dismiss, otherwise right. |
ToastProvider.duration | number | 4000 | Default time on screen, in ms. |
ToastProvider.visibleToasts | number | 3 | Maximum layers in the stack; older ones are hidden, also when expanded. |
ToastProvider.contained | boolean | false | Positions toasts inside the nearest positioned ancestor (it needs position: relative). Otherwise they are fixed and portaled to body. |
ToastProvider.offset | number | 16 | Distance from the container edge, in px. |
ToastProvider.gap | number | 12 | Space between toasts when expanded, in px. |
ToastProvider.label | string | 'Notifications' | Accessible name of the notification region. |
ToastProvider.labels | object | — | Replaces built-in text (close). Shallow-merged over the English defaults. |
useToast() | () => ToastFn | — | Returns toast(message, options) with success, error, info and dismiss. Must be used inside ToastProvider. |
toast(message, options) | (message: ReactNode, options?: ToastOptions) => string | — | Shows a toast and returns its id. toast.success, error and info take the same arguments with a fixed type. |
toast.dismiss(id?) | (id?: string) => void | — | Closes one toast, or all of them when no id is given. |
options.description | ReactNode | — | Second line of text. |
options.type | 'default' | 'success' | 'error' | 'info' | 'default' | Sets the icon. Errors are announced assertively. |
options.duration | number | — | Time on screen for this toast, in ms. Infinity never dismisses automatically. |
options.action | { label: ReactNode; onClick: () => void } | — | Action button on the right; the toast closes after a click. |
options.id | string | — | Custom id. Calling again with the same id updates the toast in place and restarts its timer. |
Accesibilidad
- The region is a labelled landmark, with two always-present live regions: polite for normal toasts, assertive for errors.
- Each toast is focusable; focus expands the stack and pauses timers. Esc or Delete closes the toast and moves focus to a neighbour.
- The close button has an accessible name and focus ring, is always visible and has a 44px hit area.
- Toasts hidden behind the front one or exiting are inert and skipped by Tab.
- With reduced motion, toasts fade without sliding or moving.
Movimiento
Enter and re-stacking 360ms ease-out (a new toast rises from the edge while growing from 94%); exit 200ms ease-in (40% toward the edge while fading); swipe snap-back 240ms ease-out. The action pill presses to 0.96.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
ToastProvider.jsxtoast-stack.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.
Reglas de diseño que sigue
Plantillas que lo incluyen
- Plantilla Next.js de dashboard
- Plantilla Next.js de tienda online
- Plantilla Next.js de reservas
- Plantilla Next.js de landing page
- Plantilla Next.js de chat con IA
- Plantilla Next.js de blog
- Plantilla Next.js de página de evento
- Plantilla Next.js de portafolio
- Plantilla Next.js de documentación
- Plantilla Next.js SaaS

