Skip to content
iv-ui v0.3.0

AlertDialog

since 0.1.0

A blocking confirmation that returns a decision through an action.

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

Confirm

A title, a message, and a cancel/confirm pair.

published 0 times

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

	let published = $state(0);

	function confirm() {
		showAlertDialog({
			title: 'Publish release?',
			message: 'The build will be promoted to production and the current version will be archived.',
			actions: [
				{ label: 'Cancel', variant: 'ghost' },
				{
					label: 'Publish',
					variant: 'primary',
					onClick: () => (published += 1)
				}
			]
		});
	}
</script>

<div class="stack">
	<Button variant="primary" onclick={confirm}>Publish release</Button>
	<p class="readout">published {published} times</p>
	<AlertDialog />
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}

	.readout {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
  • Mount <AlertDialog /> once in the root layout, then open it with showAlertDialog({ ... }).
  • actions defaults to a single OK button; give each action a variant that matches its weight.
  • Set closeOnClick: false to keep the dialog open, then close it yourself when the work finishes.

Destructive

A danger action with the delete verb in the label.

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

	let deleted = $state(false);

	function remove() {
		showAlertDialog({
			title: 'Delete project?',
			message: 'Orbital and its deployments will be removed. This cannot be undone.',
			actions: [
				{ label: 'Cancel', variant: 'ghost' },
				{
					label: 'Delete project',
					variant: 'danger',
					onClick: () => (deleted = true)
				}
			]
		});
	}
</script>

<div class="stack">
	<Button variant="danger" onclick={remove}>Delete project</Button>
	{#if deleted}<p class="readout">project deleted</p>{/if}
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}

	.readout {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_error);
	}
</style>

Custom actions

Several actions, each with its own variant and handler.

last choice: none

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

	let last = $state('none');

	function choose() {
		showAlertDialog({
			title: 'Unsaved changes',
			message: 'Leave the editor and lose the draft, or keep working?',
			closeOnBackdrop: false,
			actions: [
				{
					label: 'Keep editing',
					variant: 'ghost',
					onClick: () => (last = 'keep editing')
				},
				{
					label: 'Discard',
					variant: 'danger',
					onClick: () => (last = 'discarded')
				},
				{
					label: 'Save draft',
					variant: 'primary',
					onClick: () => (last = 'saved')
				}
			]
		});
	}
</script>

<div class="stack">
	<Button variant="outline" onclick={choose}>Close editor</Button>
	<p class="readout">last choice: {last}</p>
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}

	.readout {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
import { AlertDialog } from '@elluzion/iv-ui';

Props

0 props · 0 events · 0 snippets

This component has no props.

Functions

NameTypeDescription
showAlertDialog(config)AlertDialogStateOpens the dialog with the given title, message, and actions.
alertDialogStateWritable<AlertDialogState | null>Store holding the current dialog, or null when closed.

Config

Passed to showAlertDialog.

NameTypeDescription
titlestringDialog title and accessible name.
messagestringBody text describing the decision.
actionsAlertDialogAction[]Buttons rendered in order; defaults to one OK action.
closeOnBackdropbooleanCloses when the backdrop is clicked. Defaults to true.
closeOnEscapebooleanCloses on Escape. Defaults to true.
onclose() => voidCalled after the dialog closes for any reason.

Action

NameTypeDescription
labelstringButton text.
variant'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'Button emphasis.
size'sm' | 'md' | 'lg'Button size.
disabledbooleanDisables the action.
closeOnClickbooleanCloses the dialog after the handler runs. Defaults to true.
onClick() => voidRuns before the dialog closes.
KeysAction
TabMoves focus between the actions.
EscapeCloses the dialog unless closeOnEscape is false.
  • The surface uses role="alertdialog" and aria-modal="true".
  • Focus is trapped while open and restored when the dialog closes.
  • The title names the dialog; the message is linked through aria-describedby.
Class hooks
.iv-alertdialog.iv-alertdialog-actions.iv-alertdialog-message.iv-alertdialog-title.iv-backdrop
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records