Mount <Toaster /> once near the app root, then call toast() anywhere.
Setup
<script lang="ts">
import { Toaster, toast, Button } from '.';
</script>
<Toaster /> Basic usage
Interactive toast triggers belong in example fences (client-side). Live page demos below call the same API from the docs script.
<script lang="ts">
import { Button, toast } from '.';
</script>
<Button onclick={() => toast('Hello toast!')}>Default</Button>
<Button color="green" onclick={() => toast.success('Saved successfully')}>Success</Button>
<Button color="red" onclick={() => toast.error('Something went wrong')}>Error</Button>
<Button color="blue" onclick={() => toast.loading('Uploading…')}>Loading</Button> Promise toast
<script lang="ts">
import { Button, toast } from '.';
function save() {
const p = new Promise((resolve) => setTimeout(resolve, 1500));
toast.promise(p, {
loading: 'Saving…',
success: 'Saved!',
error: 'Failed to save'
});
}
</script>
<Button onclick={save}>Save with promise</Button> With sound
<script lang="ts">
import { Toaster } from '.';
</script>
<Toaster fireWithSound soundPreset="chime" /> Sound presets: chime, ding, bell, soft, pop, pulse, airy.
Composition notes
- Render a single
<Toaster />at the app shell (docs pages mount one for demos). - Prefer
toast.success/toast.error/toast.loadinghelpers; usetoast.promisefor async work. updateToastConfigadjusts shared defaults (duration, sound) after mount.- Options follow svelte-french-toast
ToastOptions(duration,position,icon,style,id, …).
Props
ToasterProps
| Prop | Type | Default | Description |
|---|---|---|---|
position | ToastPosition | top-center | Viewport placement |
duration | number | 4000 | Default ms before dismiss |
toastOptions | DefaultToastOptions | {} | Defaults passed to french-toast |
reverseOrder | boolean | false | Newest first vs last |
gutter | number | 8 | Gap between toasts |
containerStyle | string | — | Inline style on container |
containerClassName | string | — | Class on container |
fireWithSound | boolean | false | Play Web Audio on show |
soundPreset | chime | ding | bell | soft | pop | pulse | airy | chime | Sound when enabled |
className | string | '' | Legacy no-op class |
theme | ToastTheme | {} | Reserved theme bag |
richColors | boolean | false | Rich color styling flag |
customIcons | boolean | true | Use custom icons |
closeButton | boolean | true | Show close control |
pauseOnHover | boolean | true | Pause timer on hover |
visibleToasts | number | 3 | Max visible stack |
expand | boolean | false | Expand stacked toasts |
gap | number | 8 | Stack gap |
offset | number | string | '32px' | Distance from edge |
toast API
| Export | Signature | Description |
|---|---|---|
toast | (message, options?) => id | Show a default toast |
toast.success | (message, options?) => id | Success variant |
toast.error | (message, options?) => id | Error variant |
toast.loading | (message, options?) => id | Loading variant |
toast.promise | (promise, msgs, opts?) | Loading → success/error |
toast.custom | french-toast custom | Fully custom toast |
toast.dismiss | (id?) | Dismiss one or all |
toast.remove | (id?) | Remove without animation |
updateToastConfig | (config) | Update shared duration / sound |
originalToast | french-toast instance | Escape hatch |
Events
Toast is imperative — there are no component event props. Lifecycle is controlled via toast.dismiss / toast.remove and french-toast options (onClick, onClose where supported by the underlying library).