Feedback
Toast
A global notification system. Mount Toaster once, then call toast.success(), toast.error() and friends from anywhere.
Mount Toaster once in the root layout:
<!-- +layout.svelte -->
<script>
import { Toaster } from "@codeatlasdev/ui";
let { children } = $props();
</script>
{@render children()}
<Toaster />
Then call toast from 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" with a dismiss button. Toasts stack in the bottom right corner, up to 380px wide, in a fixed container layered with --ca-z-snackbar (they are not in the browser top layer, unlike dialogs and popovers). toast.show accepts variant and duration in its options; the shortcut methods take the duration as a second argument. 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. |