Toast
A notification system for displaying temporary messages with support for different severity levels, custom actions, and configurable positioning.
Import
Usage
ToastProvider is a global feature provider. Wrap your application root once, placed strictly below <AsheeUIProvider>, then call toast functions from anywhere in your app.
Examples
Warning messages
Info messages
With title
With custom icon
Custom styling
Style the toast container with the className prop on ToastProvider, and compose rich toasts with title, custom icon, and action elements.
With action button
With custom timeout
Non-dismissible
Placement variants
Size variants
Variant
Radius
Max toasts
Clearing all toasts
Removing specific toast
ToastProvider Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | None | App content (required) |
size | "sm" | "md" | "lg" | "md"* | Toast size scale |
placement | "top-right" | "top-left" | "bottom-right" | "bottom-left" | "top-center" | "bottom-center" | "top-right"* | Position on screen |
variant | "solid" | "ghost" | "bordered" | "faded" | "underlined" | "solid"* | Visual style |
radius | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "full" | "md"* | Corner rounding |
defaultTimeout | number | 3500* | Default duration in ms |
maxToasts | number | 5* | Maximum visible toasts |
animated | boolean | true* | Enable animations |
portal | boolean | true* | Whether to render toasts in a portal |
portalTarget | HTMLElement | null | null* | Custom portal target element |
className | string | None | Extra classes for container |
* Falls back through Global Configuration if not set. See below.
useToast API
| Method | Parameters | Description |
|---|---|---|
toast(options) | string | ToastShowOptions | Show a toast |
success(message, options?) | string, optional options | Show success toast |
error(message, options?) | string, optional options | Show error toast |
warning(message, options?) | string, optional options | Show warning toast |
info(message, options?) | string, optional options | Show info toast |
removeToast(id) | string | Remove a specific toast |
clearToasts() | None | Remove all toasts |
ToastShowOptions
| Prop | Type | Default | Description |
|---|---|---|---|
message | ReactNode | Required | Toast content |
title | ReactNode | None | Optional title |
type | "success" | "error" | "warning" | "info" | "info" | Severity type |
timeout | number | 3500* | Duration in ms |
icon | ReactNode | None | Custom icon |
action | ReactNode | None | Action element |
dismissible | boolean | true | Show close button |
id | string | Auto-generated | Custom ID |
placement | ToastPlacement | Inherited from provider | Override placement |
size | Size | Inherited from provider | Override size |
variant | Variant | Inherited from provider | Override variant |
radius | Radius | Inherited from provider | Override radius |
animated | boolean | Inherited from provider | Override animation |
Portal Behavior
The Toast container is rendered in a React portal by default. This means toasts are attached to document.body rather than staying in the component's DOM hierarchy.
Why use a portal?
- Escapes CSS containment: Toasts appear above other content even when the ToastProvider is inside containers with
overflow: hiddenorcontain: layout - Avoids stacking context issues: Toasts maintain proper z-index regardless of parent stacking contexts
- Works with any parent: Toasts function correctly regardless of where the ToastProvider is placed in the component tree
- Prevents clipping: Toasts are never clipped by parent containers
When to disable the portal
You may want to disable the portal (by setting portal={false}) when:
- You need toasts to stay within a specific container for testing purposes
- You are rendering inside a shadow DOM or iframe where
document.bodyis not appropriate - You have specific layout requirements that depend on toasts remaining in the DOM hierarchy
You can also provide a custom portalTarget to render toasts into a specific container instead of document.body.
Global Configuration
Toast reads defaults from four places, in this order of precedence:
- Instance prop: set directly on
<ToastProvider /> - Component config:
components.toastin yourashee.config - Theme default:
defaultVariant/defaultRadiusin yourashee.config - Built-in fallback: component's internal default values
Component config
Built-in fallbacks
Accessibility
- Toast container has
aria-label="Notifications" - Toasts are keyboard focusable with proper focus management
- Dismiss buttons include
aria-label="Dismiss notification" - Toasts pause on hover for accessibility
- Respects reduced motion preferences
- Screen readers announce toast messages
Notes
- Context Required: The
ToastProvidermust wrap your app root (placed below<AsheeUIProvider>) for toast functions to work. - Type Mapping: Toast types (
success,error,warning,info) automatically map to appropriate colors and icons. - Pausable Timeout: Toasts pause their timeout when hovered, giving users more time to interact.
- Animation: Toasts animate in and out based on the
placementprop. Disable withanimated={false}. - Max Toasts: When the maximum number of toasts is reached, older toasts are automatically removed.
- Dismissible: By default, toasts include a dismiss button. Set
dismissible={false}to disable. - Portal: Toasts are portaled to
document.bodyby default. This can be disabled via theportalprop or component config. - Per-Toast Customization: Each toast can override size, placement, variant, radius, and animation settings via
ToastShowOptions. - Solid Variant: When using the
"solid"variant, the icon color automatically matches the toast's accent color.