Toast
Alignment target:@astryxdesign/core v0.7.1 · Toast
Usage #
Place ToastViewport once near the root of your app, then call useToast from any component.
On a touch screen, a swipe toward the toast's edge dismisses it: down when it sits at the bottom, up when it sits at the top. A horizontal drag is left to the page. A swipe that starts on a button or link does not dismiss. A mouse drag does not dismiss either.
<script setup lang="ts">
import { ToastViewport, useToast } from '@astryx-vue/core/Toast'
const toast = useToast()
toast({ body: 'Saved successfully', type: 'success' })
</script>
<template>
<div>
<button @click="toast({ body: 'Saved' })">
Save
</button>
<ToastViewport />
</div>
</template>Anatomy
| Element | Description |
|---|---|
| Body | The primary message text describing what happened or what the user should know. |
| End content | A trailing action like an Undo button or a link, placed after the body text. |
| Dismiss button | A close button that lets the user manually dismiss the toast before auto-hide. |
Best practices #
| Guidance | Practice |
|---|---|
| Recommended | Put ToastViewport at the top level so toasts overlay every page. |
| Recommended | Use type="error" for failures and rely on role="alert". |
| Recommended | Keep toast copy short — one line describing the outcome is enough. |
| Don't | Flood the screen with many toasts at once. |
| Don't | Use toasts for actions that need user confirmation. |
Examples #
Toast — Action
A persistent toast can end with a button or a link, for undoing a delete or opening a report.
Toast — Deduplication
uniqueID collapses repeats. ignore keeps the first toast; overwrite replaces it, for a progress percentage.
Toast — Dismiss
useToast returns a function that dismisses that toast. Use it when a long-running operation should close the notice itself.
Toast — Stacking
Toasts stack vertically and animate in and out. Clicking again queues another one.
Toast — Types
Info and error side by side. Info goes away on its own; error stays until it is dismissed.