Toasts (the container) and ToastItem (individual toast).
Toasts
TheToasts component is a container that renders all active toast notifications. It should be placed once in your application layout.
Usage
Props
TheToasts component accepts no props. It automatically retrieves toast items and configuration from the ToastProvider context.
Behavior
- Automatically positions toasts based on the
positionconfig fromToastProvider - Renders toasts with proper ARIA attributes for accessibility (
aria-live="polite") - Applies responsive styling with a maximum width of
sm(24rem) - Stacks multiple toasts with vertical spacing
Position mapping
The component maps position config values to CSS classes:| Position | CSS Classes |
|---|---|
top-right | top-4 right-4 items-end |
top-left | top-4 left-4 items-start |
top-center | top-4 left-1/2 -translate-x-1/2 items-center |
bottom-right | bottom-4 right-4 items-end |
bottom-left | bottom-4 left-4 items-start |
bottom-center | bottom-4 left-1/2 -translate-x-1/2 items-center |
ToastItem
TheToastItem component renders an individual toast notification with animations, icons, and a dismiss button.
You typically don’t need to use
ToastItem directly. The Toasts component automatically renders it for each active toast.Props
The toast item data to render.
Unique identifier for the toast (auto-generated).
The main message content to display.
The severity level of the toast. Determines the icon and color scheme.Options:
success | error | info | warningOptional title displayed above the message in bold.
Optional override for the auto-dismiss duration. Uses config default if
null.The global toast configuration from the provider.
The position where toasts are displayed. Used to determine animation direction.
Callback function invoked when the toast should be removed from state.
Features
Animations
- Enter animation: Fades in and slides from the edge over 300ms
- Exit animation: Fades out and slides back to the edge over 200ms
- Animation direction automatically adjusts based on position:
- Right positions: slides from/to right
- Left positions: slides from/to left
- Top positions: slides from/to top
- Bottom positions: slides from/to bottom
Icons
Each toast level displays a distinct icon with matching colors:| Level | Icon | Background | Text Color |
|---|---|---|---|
success | Checkmark circle | bg-green-100 | text-green-500 |
error | X circle | bg-rose-100 | text-rose-500 |
warning | Warning triangle | bg-yellow-100 | text-yellow-500 |
info | Info circle | bg-blue-100 | text-blue-500 |
Auto-dismiss
- Toasts automatically dismiss after the configured duration
- Duration can be overridden per-toast via the
durationproperty - Set duration to
0to disable auto-dismiss for specific toasts - Timer is cleared if the toast is manually dismissed
Dismiss button
- Every toast includes a close button in the top-right corner
- Clicking triggers the exit animation and removes the toast
- Accessible with proper ARIA labels and focus states
TypeScript types
Custom usage example
If you need to render aToastItem directly (advanced use case):
Styling
Both components use Tailwind CSS classes for styling. The default theme provides:- White background with subtle shadow
- Rounded corners (
rounded-lg) - Responsive padding
- Smooth transitions and animations
- Accessible color contrast ratios
- Hover and focus states for interactive elements
- Override Tailwind classes in your global CSS
- Fork the component and modify the class names
- Use Tailwind’s JIT mode to extend the default theme