Toast

Display a temporary message.

Basic Example

<script>
	import { Toaster, Toast, ToastTitle, ToastMessage } from 'lithesome';
</script>

<Toaster>
	{#snippet children(toasts)}
		{#each toasts as toast (toast.id)}
			<Toast>
				<ToastTitle />
				<ToastMessage />
			</Toast>
		{/each}
	{/snippet}
</Toaster>

Be sure to key your each block!

Adding a toast

To actually use the toasts, use the toaster object.

By using the add method, it will add a toast to the toaster.

<script>
	import { toaster } from 'lithesome';

	const addToast = () => {
		toaster.add('success', {
			title: 'Profile updated.',
			message: 'Your profile details have been updated.'
		});
	};
</script>

<button onclick={addToast}>Add toast</button>

Dismissing a toast early

Using the removeById allows you remove a singular toast early.

<script>
	import { toaster, Toaster, Toast, ToastTitle, ToastMessage } from 'lithesome';
</script>

<Toaster>
	{#snippet children(toasts)}
		{#each toasts as toast (toast.id)}
			<Toast>
				<ToastTitle />
				<ToastMessage />
				{#if toast.config.dismissable}
					<button onclick={() => toaster.removeById(toast.id)}>x</button>
				{/if}
			</Toast>
		{/each}
	{/snippet}
</Toaster>