Toast @astryx-svelte/core v0.5.2 · Toast
Usage
Toast shows a brief, non-blocking notification to confirm an action or present temporary information. Use it for scenarios where the user needs feedback but not a decision, such as saving, deleting, or changing a status. For production use, prefer theuseToast() hook; it handles positioning, stacking, auto-dismiss, and deduplication via ToastViewport. Toasts stay within viewport and safe-area gutters, wrap long message content, and enter, exit, or swipe-dismiss toward their configured top or bottom edge. The vertical swipe uses the same spatial model as placement motion: top Toasts leave upward and bottom Toasts leave downward. Swipe waits for dominant edge-directed intent before cancelling native touch movement and reports the existing manual dismissal reason. Pen is supported as direct-contact input; mouse drag is excluded to avoid conflicting with desktop text selection, where the visible close control remains available. Set isAutoHide: false explicitly when an action or message must remain available. The Toast component renders the visual toast element inline and is useful for previews, documentation, and static showcases where the viewport lifecycle is not needed. tsimport { Toast } from '@astryx-svelte/core';
Best practices
| Guidance | Practices |
|---|---|
| Do | Keep messages short: only a few words that tell the user what happened, like "Changes saved" or "Message sent". |
| Do | Add a short undo action in the endContent slot for reversible operations. Set isAutoHide to false when the action must remain available. |
| Do | Use uniqueID to deduplicate toasts that fire from repeated actions, like clicking a save button multiple times. |
| Do | Use error type for failures that need attention but not immediate action; it persists until dismissed so the user won't miss it. |
| Don't | Don't use a toast for critical errors that block the user. Use Banner for persistent, in-context messaging that requires acknowledgment. |
| Don't | Don't put long or multi-line content in a toast; it disappears after 5 seconds and the user may not finish reading. |
| Don't | Don't show form validation errors as toasts. Use inline field validation so the user can see exactly which field needs fixing. |
Examples
Common configurations, variations, and states.Toast — Action
Persistent toasts with a trailing button or link so the user can act on the notification, like undoing a delete or viewing a report.
Toast — Deduplication
Prevent duplicate toasts with uniqueID. Use ignore to keep the first toast, or overwrite to replace it with updated content like a progress percentage.
Toast — Dismiss
Show a persistent toast and dismiss it programmatically using the function returned by useToast. Use for long-running operations that need manual cleanup.
Toast — Stacking
Multiple toasts stacking vertically with smooth enter and exit animations. Click repeatedly to see how toasts queue and dismiss.
Toast — Types
Info and error toast variants side by side. Info toasts auto-dismiss after 5 seconds, error toasts persist until the user dismisses them.