The first example showcases the complete setup process for a reusable toast component, while the following are abridged to handle everything in a single file. Please keep this in mind when following these examples.
Trigger Methods
Use the generic create()
method to trigger toasts of type: info|success|warning|error
.
toaster.create({ type: 'info', message: 'This is a toast', description: 'This is a toast description.'});
Additonally, four shorthand methods are available for specific toast types.
info()
success()
warning()
error()
Placement
Provide a placement
option for createToaster()
. Accepts the following:
top-start
top-end
bottom-start
bottom-end
Closable
Set closable
to false
to disable the close button toasts.
Promise
Use promise()
to create a toast configured based on the state of a promise. The toast will automatically update based on the state of the promise.
Styling for React 18
For React 18 add these styles to your global stylesheet. For React 19+, these styles are set automatically.
[data-scope='toast'][data-part='root'] { translate: var(--x) var(--y); scale: var(--scale); z-index: var(--z-index); height: var(--height); opacity: var(--opacity); will-change: translate, opacity, scale;}
[data-scope='toast'][data-part='root'] { transition: translate 400ms, scale 400ms, opacity 400ms; transition-timing-function: cubic-bezier(0.21, 1.02, 0.73, 1);}
[data-scope='toast'][data-part='root'][data-state='closed'] { transition: translate 400ms, scale 400ms, opacity 200ms; transition-timing-function: cubic-bezier(0.06, 0.71, 0.55, 1);}
API Reference
Toaster
Property | Type | Description |
---|---|---|
toaster * | ToastStore<any> | |
base | string | |
width | string | |
padding | string | |
rounded | string | |
classes | string | |
messageBase | string | |
messageClasses | string | |
titleBase | string | |
titleClasses | string | |
descriptionBase | string | |
descriptionClasses | string | |
btnDismissBase | string | |
btnDismissClasses | string | |
stateInfo | string | |
stateSuccess | string | |
stateWarning | string | |
stateError | string | |
Toast
Property | Type | Description |
---|---|---|
toast * | Options<any> | |
parent * | ToastGroupService | |
base | string | |
width | string | |
padding | string | |
rounded | string | |
classes | string | |
messageBase | string | |
messageClasses | string | |
titleBase | string | |
titleClasses | string | |
descriptionBase | string | |
descriptionClasses | string | |
btnDismissBase | string | |
btnDismissClasses | string | |
stateInfo | string | |
stateSuccess | string | |
stateWarning | string | |
stateError | string | |
Alternatives
If you’re looking for power user features or more control over templates, consider using React-Hot-Toast.