Toast - Skeleton

Skeleton

  1. components
  2. toast
  3. svelte

Toast

Build a toast notification system.

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 *
base
string
Provide base classes for the root element.
width
string
Provide width classes for the root element.
padding
string
Provide padding classes for the root element.
rounded
string
Provide border radius classes for the root element.
classes
string
Provide arbitrary classes for the toast cards.
messageBase
string
Provide base classes for the message.
messageClasses
string
Provide classes for the message.
titleBase
string
Provide base classes for the title.
titleClasses
string
Provide classes for the title.
descriptionBase
string
Provide base classes for the description.
descriptionClasses
string
Provide classes for the description.
btnDismissBase
string
Provide base classes for the dismiss button.
btnDismissClasses
string
Provide arbitrary classes for the dismiss button.
stateInfo
string
Provide base classes for info toasts.
stateSuccess
string
Provide base classes for success toasts.
stateWarning
string
Provide base classes for warning toasts.
stateError
string
Provide base classes for error toasts.
placement
Placement
The placement of the toast
Default: "bottom"
max
number
The maximum number of toasts
Default: 24
overlap
boolean
Whether to overlap the toasts
duration
number
The duration of the toast. By default, it is determined by the type of the toast.
gap
number
The gap between the toasts
Default: 16
offsets
string | Record<"top" | "bottom" | "left" | "right", string>
The offset from the safe environment edge of the viewport
Default: "1rem"
hotkey
The hotkey that will move focus to the toast group
Default: '["altKey", "KeyT"]'
removeDelay
number
The duration for the toast to kept alive before it is removed. Useful for exit transitions.
Default: 200
pauseOnPageIdle
boolean
Whether to pause toast when the user leaves the browser tab
Default: false

Toast

Property Type Description
toast *
index *
number
parent *
max
number
The maximum number of toasts
Default: 24
base
string
Provide base classes for the root element.
width
string
Provide width classes for the root element.
padding
string
Provide padding classes for the root element.
rounded
string
Provide border radius classes for the root element.
classes
string
Provide arbitrary classes for the toast cards.
messageBase
string
Provide base classes for the message.
messageClasses
string
Provide classes for the message.
titleBase
string
Provide base classes for the title.
titleClasses
string
Provide classes for the title.
descriptionBase
string
Provide base classes for the description.
descriptionClasses
string
Provide classes for the description.
btnDismissBase
string
Provide base classes for the dismiss button.
btnDismissClasses
string
Provide arbitrary classes for the dismiss button.
stateInfo
string
Provide base classes for info toasts.
stateSuccess
string
Provide base classes for success toasts.
stateWarning
string
Provide base classes for warning toasts.
stateError
string
Provide base classes for error toasts.
placement
Placement
The placement of the toast
Default: "bottom"
overlap
boolean
Whether to overlap the toasts
duration
number
The duration of the toast. By default, it is determined by the type of the toast.
gap
number
The gap between the toasts
Default: 16
offsets
string | Record<"top" | "bottom" | "left" | "right", string>
The offset from the safe environment edge of the viewport
Default: "1rem"
hotkey
The hotkey that will move focus to the toast group
Default: '["altKey", "KeyT"]'
removeDelay
number
The duration for the toast to kept alive before it is removed. Useful for exit transitions.
Default: 200
pauseOnPageIdle
boolean
Whether to pause toast when the user leaves the browser tab
Default: false

Alternatives

If you’re looking for power user features or more control over templates, consider using Svelte-French-Toast.