A simple, flexible, and modern toast notification library for Svelte 5. Easily display beautiful notifications in your SvelteKit or Svelte 5 app with minimal setup.
| Success | Info | Warning | Error | Confirm |
|---|---|---|---|---|
pnpm i @mi1y/toast-mi1y
# or
npm i @mi1y/toast-mi1y
Add the toast component to your main layout (e.g. +layout.svelte):
<script lang="ts">
import { InitToast } from '@mi1y/toast-mi1y';
</script>
<InitToast />
<slot />
Import the toast store and use it anywhere in your app:
import { toast } from '@mi1y/toast-mi1y';
toast.success("This is a sample success toast!");
toast.info("This is a sample info toast!");
toast.warning("This is a sample warning toast!");
toast.error("This is a sample error toast!");
// Dynamic values (e.g. with i18n)
toast.success($LL.success);
// Confirm toast example
let confirmResult: boolean | null = null;
async function showConfirm() {
const result = await toast.confirm("Are you sure?");
confirmResult = result;
}
Example Svelte usage:
<script lang="ts">
import { toast } from '@mi1y/toast-mi1y';
function showSuccess() {
toast.success("This is a sample success toast!");
}
function showInfo() {
toast.info("This is a sample info toast!");
}
function showWarning() {
toast.warning("This is a sample warning toast!");
}
function showError() {
toast.error("This is a sample error toast!");
}
let confirmResult: boolean | null = null;
async function showConfirm() {
const result = await toast.confirm("Are you sure?");
confirmResult = result;
}
</script>
<div>
<button on:click={showSuccess}>Show success toast</button>
<button on:click={showInfo}>Show info toast</button>
<button on:click={showWarning}>Show warning toast</button>
<button on:click={showError}>Show error toast</button>
<button on:click={showConfirm}>Show confirm toast</button>
{#if confirmResult !== null}
<p>Confirm result: {confirmResult ? 'Confirmed' : 'Cancelled'}</p>
{/if}
</div>