Toast
Notifications sent from anywhere with useToast, one or several at once, collapsed, pinned, with actions or following a promise, that pause their timer while hovered or focused.
Import
import { Toast } from '@vitral/vue';Severities
Four seconds each; hover one to keep it.
Sticky and grouped
Without a `life` a toast waits to be closed. A `group` sends it to another `<Toast>`, here one at the bottom.
Several at once
`add` takes a list as well as one message. `max` caps the cards on screen: with `overflow` at `'queue'`, the default, the rest wait and each one's life starts only when it shows; with `'replace'`, the oldest card that is not pinned closes to make room. `newest-on-top` turns the order round.
Collapsed into one
Messages that share a `collapseKey` share a card: the newest text, its life started again, and a count of how many came. Press the button a few times.
Pinned, with actions
A `pinned` message leads the stack, never times out and never waits behind `max`. `actions` puts buttons on the card; each closes it unless it says `keepOpen`, and the `action` event reports the press. `progress` draws the life left, holding while the card is read.
Following a promise
`promise` shows one card while the work runs, with a spinner and no close button, and turns it into the success or the error when it settles. `update` changes any card in place by its id.
A pile
`stacked` draws the cards as a pile, the newest in front; pointed at or focused, it spreads and every countdown waits. On a phone a card can be swiped sideways to close it, which `swipe-to-close` turns off, and the countdowns hold while the page is in the background, which `pause-on-page-hidden` turns off.
API
Read from packages/vue/src/components/Toast/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| position | ToastPosition | Defaults to `'top-right'`. |
| group | string | Shows only the messages sent with the same `group`. |
| max | number | At most this many cards at once; pinned ones always show. What happens to the rest is `overflow`'s. |
| overflow | 'queue' | 'replace' | Past `max`: `'queue'` (the default) makes a new toast wait until a card leaves; `'replace'` closes the oldest card that is not pinned to make room. |
| newestOnTop | boolean | Put the latest at the head of the stack rather than at its end. |
| stacked | boolean | Draw the stack as a pile: the newest in front, a few behind it, the rest hidden, all spread out while it is pointed at or holds focus. The countdowns wait while it is spread. |
| showProgress | boolean | A bar on each timed card that shows the life left; a message's `progress` overrides it. |
| pauseOnPageHidden | boolean | Hold every countdown while the page is in the background. On by default. |
| swipeToClose | boolean | Let a finger or a pen swipe a card sideways to close it. On by default. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| close | event: ToastEvent | Closed by its close button. |
| life-end | event: ToastEvent | Closed because its `life` ran out. |
| action | event: ToastEvent & { action: ToastAction } | One of a message's `actions` was pressed. |
Slots
| Name | Slot props | Description |
|---|---|---|
| message | (props: { message: ToastMessage }) | Replaces the icon and text of each message; the close button stays. |
| container | (props: { message: ToastMessage; closeCallback: () => void }) | Replaces the whole card's inside, close button included. |
| closeicon | — | — |