Feedback
Toast
A global notification system. Mount Toaster once, then call toast.success(), toast.error() and friends from anywhere.
<!-- +layout.svelte: mount once -->
<script>
import { Toaster } from "@codeatlasdev/ui";
</script>
<Toaster />
<!-- anywhere -->
<script>
import { toast } from "@codeatlasdev/ui";
</script>
<button onclick={() => toast.success("Changes saved.")}>Save</button>
toast is a global store, so the calls need no component context. The Toaster is a polite live region (role="region", aria-live="polite") and each toast is a role="status". Toasts stack in the bottom right corner. The demo below mounts its own Toaster because every demo is an independent island.
Variants and duration
Five variants, plus persistent (duration 0) and custom durations. The default auto-dismiss is 4 seconds.
Variants
Duration
Code
API
| Prop | Type | Default | Description |
|---|---|---|---|
toast.show(message, opts?) | (message: string, opts?: { variant?: ToastVariant; duration?: number }) => string | – | Shows a toast and returns its id. Variant defaults to 'default'. |
toast.success(message, duration?) | (message: string, duration?: number) => string | – | Success toast. |
toast.error(message, duration?) | (message: string, duration?: number) => string | – | Error toast. |
toast.warning(message, duration?) | (message: string, duration?: number) => string | – | Warning toast. |
toast.info(message, duration?) | (message: string, duration?: number) => string | – | Info toast. |
toast.remove(id) | (id: string) => void | – | Dismisses a toast by id. |
toast.items | ToastItem[] | – | Reactive list of the visible toasts. |
duration | number | 4000 | Auto-dismiss delay in ms. 0 keeps the toast until dismissed. |
ToastVariant | 'default' | 'success' | 'error' | 'warning' | 'info' | – | Accepted variants. |