Skip to content
iv-ui v0.3.0

Toast

since 0.1.0

A single transient notification driven by the toast store.

import { Toast } from '@elluzion/iv-ui';

Types

Info, success, and error; the last one is announced assertively.

Source· svelte Show Hide
<script lang="ts">
	import { Button, showToast, Toast } from '@elluzion/iv-ui';
</script>

<div class="row">
	<Button variant="outline" onclick={() => showToast('Build queued for main.', 'info')}>
		Info
	</Button>
	<Button variant="outline" onclick={() => showToast('Deployed to production.', 'success')}>
		Success
	</Button>
	<Button variant="outline" onclick={() => showToast('Deploy failed: exit code 1.', 'error')}>
		Error
	</Button>
	<Toast />
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: var(--iv_spacing-sm);
	}
</style>
  • Mount <Toast /> once in the root layout.
  • Call showToast(message, type, durationMs); only one toast is visible at a time.
  • hideToast() clears it immediately; an id guard stops an old timer from closing a newer toast.

Duration

The third argument sets the visible time in milliseconds.

Source· svelte Show Hide
<script lang="ts">
	import { Button, showToast } from '@elluzion/iv-ui';
</script>

<div class="row">
	<Button variant="outline" onclick={() => showToast('Quick confirmation', 'success', 2000)}>
		2 seconds
	</Button>
	<Button variant="outline" onclick={() => showToast('Longer confirmation', 'info', 10000)}>
		10 seconds
	</Button>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: var(--iv_spacing-sm);
	}
</style>

Dismiss

hideToast() closes the current toast from your own control.

Source· svelte Show Hide
<script lang="ts">
	import { Button, hideToast, showToast } from '@elluzion/iv-ui';
</script>

<div class="row">
	<Button variant="outline" onclick={() => showToast('Waiting for your response…', 'info', 30000)}>
		Show
	</Button>
	<Button variant="ghost" onclick={() => hideToast()}>Dismiss</Button>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: var(--iv_spacing-sm);
	}
</style>
import { Toast } from '@elluzion/iv-ui';

Props

0 props · 0 events · 0 snippets

This component has no props.

Functions

NameTypeDescription
showToast(message, type?, durationMs?)(message: string, type?: ToastType, durationMs?: number) => voidShows a toast, replacing the current one. The default duration is 5000 ms.
hideToast(id?)(id?: number) => voidHides the toast. With an id, only hides it when that toast is still active.
toastStateWritable<ToastState | null>Store holding the active toast, or null when hidden.

Options

NameTypeDescription
type'info' | 'success' | 'error'Controls the icon and accent. Defaults to info.
durationMsnumberVisible time in milliseconds; clamped to at least 800 ms.
  • The layer uses role="status" with aria-live="polite" for info and success.
  • Errors use role="alert" with aria-live="assertive".
  • The dismiss control has an accessible name.
  • Only one toast exists at a time, so messages do not stack up.
Class hooks
.iv-close.iv-content.iv-toast.iv-toast-error.iv-toast-info.iv-toast-layer.iv-toast-success
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records