An opinionated toast component for Svelte. Gooey SVG morphing, spring physics, and a minimal API — beautiful by default.
A Svelte port of hiaaryan/sileo.
description for rich toast content.top-left, top-center, top-right, bottom-left, bottom-center, bottom-right.npm install svelte-sileo
# or
pnpm add svelte-sileo
# or
yarn add svelte-sileo
Add <Toaster /> to your layout. Then call sileo from anywhere.
<script lang="ts">
import { Toaster, sileo } from 'svelte-sileo';
</script>
<Toaster />
<button onclick={() => sileo.success({ title: 'Changes saved' })}>
Toast
</button>
sileo.success(opts)sileo.success({ title: 'Changes saved' });
sileo.error(opts)sileo.error({
title: 'Something went wrong',
description: 'Please try again later.'
});
sileo.warning(opts)sileo.warning({ title: 'Storage almost full' });
sileo.info(opts)sileo.info({ title: 'New update available' });
sileo.action(opts)Renders a toast with an inline action button.
sileo.action({
title: 'File uploaded',
description: 'Share it with your team?',
button: {
title: 'Share',
onClick: () => {}
}
});
sileo.promise(promise, opts)Starts in a loading state and transitions to success or error automatically.
sileo.promise(
new Promise((resolve) => setTimeout(resolve, 2000)),
{
loading: { title: 'Saving record...' },
success: { title: 'Record saved' },
error: { title: 'Failed to save' }
}
);
You can also pass a function to success or error to use the resolved value or error:
sileo.promise(fetchUser(), {
loading: { title: 'Loading user...' },
success: (data) => ({ title: `Welcome, ${data.name}!` }),
error: (err) => ({ title: `Error: ${err.message}` })
});
When the promise resolves you can show an action state instead of success:
sileo.promise(uploadFile(), {
loading: { title: 'Uploading...' },
success: { title: 'Done' },
action: { title: 'File ready', button: { title: 'Download', onClick: () => {} } },
error: { title: 'Upload failed' }
});
sileo.show(opts)Generic toast with no default state icon.
sileo.show({ title: 'Hello world' });
sileo.dismiss(id)Dismiss a specific toast by id.
const id = sileo.success({ title: 'Saved' });
sileo.dismiss(id);
sileo.clear(position?)Dismiss all toasts, optionally scoped to a position.
sileo.clear();
sileo.clear('top-right');
Every method accepts a SileoOptions object:
| Option | Type | Description |
|---|---|---|
title |
string |
Main toast text. |
description |
string | Component |
Expandable body. Accepts plain text or a Svelte component. |
button |
{ title: string, onClick: () => void } |
Inline action button. |
icon |
Component | null |
Replaces the default state icon. |
duration |
number | null |
Auto-dismiss delay in ms. null = persistent. Default 6000. |
position |
SileoPosition |
Overrides the <Toaster> position for this toast. |
fill |
string |
Background fill color of the pill. Default #FFFFFF. |
roundness |
number |
Border radius of the pill. Default 16. |
autopilot |
boolean | { expand?: number, collapse?: number } |
Auto-expand/collapse timing. |
styles |
SileoStyles |
Per-element class overrides (title, description, badge, button). |
| Prop | Type | Default | Description |
|---|---|---|---|
position |
SileoPosition |
top-right |
Where toasts appear. |
offset |
number | string | object |
— | Edge offset. Accepts a value or { top, right, bottom, left }. |
options |
Partial<SileoOptions> |
— | Default options applied to every toast. |
Pass any Svelte component as description for rich content:
<!-- InvoiceToast.svelte -->
<div class="flex flex-col gap-2">
<span class="text-xs opacity-50">Invoice #INV-2024-001</span>
<span class="font-medium">$1,200.00 · 3 items</span>
</div>
import InvoiceToast from './InvoiceToast.svelte';
sileo.success({
title: 'Invoice sent',
description: InvoiceToast,
button: { title: 'View', onClick: () => {} }
});
import RocketIcon from './RocketIcon.svelte';
sileo.success({
title: 'Deployed',
icon: RocketIcon
});
<!-- Available: top-left · top-center · top-right · bottom-left · bottom-center · bottom-right -->
<Toaster position="bottom-center" />