@toast-kit/svelte
v0.1.0
Published
Typed toast helper for Svelte 5 — a thin, dedupe-aware.
Downloads
32
Readme
@toast-kit/svelte
Install
npm install @toast-kit/svelte svelte-sonnersvelte ^5.0.0 is a peer dependency and must already be in your project.
Usage
Mount Toaster once, typically in your root layout, exactly as you would with svelte-sonner:
<!-- +layout.svelte -->
<script lang="ts">
import { Toaster } from '@toast-kit/svelte';
</script>
<Toaster />
{@render children?.()}Then call toast from anywhere:
import { toast } from '@toast-kit/svelte';
toast('Saved!');
toast.success('Profile updated');
toast.error('Something went wrong', { description: 'Please try again.' });
// Any svelte-sonner ExternalToast field works unchanged:
toast.warning('Connection unstable', { duration: Infinity, closeButton: true });
// Pass-through, undeduped:
toast.loading('Uploading…');
toast.promise(uploadFile(), { loading: 'Uploading…', success: 'Done!', error: 'Failed' });
toast.dismiss();Duplicate grouping
Calling the same toast.* kind with the same message text updates the existing toast instead of
opening a new one:
toast.warning('Sync conflict detected'); // "Sync conflict detected"
toast.warning('Sync conflict detected'); // same toast, now "Sync conflict detected × 2"Grouping is keyed by (kind, message) and is scoped to the browser only — calling toast() during
SSR (e.g. accidentally, from a server load function) never touches the grouping state, so nothing
can leak across requests.
Opt out per call:
toast.error('Manual id', { id: 'my-fixed-id' }); // caller owns identity: no grouping
toast.info('Always show separately', { dedupe: false });Control how a repeat's duration behaves:
toast.warning('Rate limited', {
duration: 4000,
dedupeDurationStrategy: 'extend', // 'reset' (default) | 'extend' | 'accumulate'
dedupeExtendBy: 2000 // defaults to `duration`
});'reset'— the toast gets the fulldurationagain on each repeat (svelte-sonner's native update-by-id behavior).'extend'— addsdedupeExtendByonce, regardless of how many repeats follow.'accumulate'— addsdedupeExtendByagain for every repeat, so a message hit 5 times stays up longer than one hit twice.
duration: Infinity (persistent toasts) is never adjusted, under any strategy.
|
SSR
Grouping is a client-only concern (see above); every other export is exactly what svelte-sonner
already provides, which supports SSR.
License
MIT
