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.
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 | |
placement | Placement | |
max | number | |
overlap | boolean | |
duration | number | |
gap | number | |
offsets | string | Record<"top" | "bottom" | "left" | "right", string> | |
hotkey | string[] | |
removeDelay | number | |
pauseOnPageIdle | boolean | |
Toast
Property | Type | Description |
---|---|---|
toast * | Options<any> | |
index * | number | |
parent * | ToastGroupService | |
max | number | |
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 | |
placement | Placement | |
overlap | boolean | |
duration | number | |
gap | number | |
offsets | string | Record<"top" | "bottom" | "left" | "right", string> | |
hotkey | string[] | |
removeDelay | number | |
pauseOnPageIdle | boolean | |
Alternatives
If you’re looking for power user features or more control over templates, consider using Svelte-French-Toast.