Skip to content
iv-ui v0.3.0

Dialog

since 0.1.0

A modal surface for focused tasks and confirmations.

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

Basic

A title, body content, and the close control.

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

	let open = $state(false);
</script>

<div class="stack">
	<Button onclick={() => (open = true)}>Rename project</Button>
	<Dialog {open} title="Rename project" onclose={() => (open = false)}>
		<p class="body">The new name appears in the switcher and in every deploy record.</p>
	</Dialog>
</div>

<style>
	.stack {
		display: flex;
		justify-content: center;
	}

	.body {
		margin: 0;
		color: var(--iv_foreground-dim);
		font-size: var(--iv_text-body);
	}
</style>
  • open is required and not bindable; set it to false from onclose to complete the close.
  • footer holds the actions; size caps the width.
  • Focus is trapped while open and restored on close.

Sizes

One dialog with a switchable sm, md, or lg width.

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

	let open = $state(false);
	let size = $state<'sm' | 'md' | 'lg'>('md');
</script>

<div class="stack">
	<div class="row">
		<Button size="sm" variant="outline" onclick={() => ((size = 'sm'), (open = true))}>Small</Button
		>
		<Button size="sm" variant="outline" onclick={() => ((size = 'md'), (open = true))}
			>Medium</Button
		>
		<Button size="sm" variant="outline" onclick={() => ((size = 'lg'), (open = true))}>Large</Button
		>
	</div>
	<Dialog {open} title="Dialog size" {size} onclose={() => (open = false)}>
		<p class="body">The width is capped at the chosen step; content wraps inside it.</p>
	</Dialog>
</div>

<style>
	.stack {
		display: flex;
		justify-content: center;
	}

	.row {
		display: flex;
		gap: var(--iv_spacing-sm);
	}

	.body {
		margin: 0;
		color: var(--iv_foreground-dim);
		font-size: var(--iv_text-body);
	}
</style>

Footer

Cancel and primary actions rendered in the footer.

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

	let open = $state(false);
	let saved = $state(false);
</script>

<div class="stack">
	<Button variant="primary" onclick={() => (open = true)}>Edit retention</Button>
	<Dialog {open} title="Retention policy" onclose={() => (open = false)}>
		<p class="body">Logs older than the selected window are removed at the next sweep.</p>
		{#snippet footer()}
			<Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
			<Button
				variant="primary"
				onclick={() => {
					open = false;
					saved = true;
				}}>Save</Button
			>
		{/snippet}
	</Dialog>
	{#if saved}<p class="readout">policy saved</p>{/if}
</div>

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

	.body {
		margin: 0;
		color: var(--iv_foreground-dim);
		font-size: var(--iv_text-body);
	}

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

Props

5 props · 1 events · 3 snippets
PropTypeDefaultDescription
open required booleanfalseWhether the dialog is visible. Set it to false from onclose to complete the close.
title string''Dialog title; also used as the accessible name.
size 'sm' | 'md' | 'lg''md'Maximum dialog width.
closeOnBackdrop booleantrueCloses when the backdrop is clicked.
closeOnEscape booleantrueCloses on Escape.

class, id, style, aria-*, and data-* are forwarded through rest props.

Events

EventHandler typeDescription
onclose() => voidCalled when the dialog requests to close; set open = false in response.

The legacy on:name form is accepted for every event.

Snippets

SnippetTypeDescription
childrenSnippetContent rendered inside the component.
iconSnippetIcon rendered before the title.
footerSnippetActions rendered below the body.
KeysAction
TabCycles focus inside the dialog.
EscapeCloses the dialog unless closeOnEscape is false.
  • The surface uses role="dialog" and aria-modal="true".
  • title is used for aria-labelledby; the body is linked through aria-describedby.
  • The backdrop click only closes when the click starts on the backdrop itself.
Class hooks
.iv-backdrop.iv-body.iv-body-no-title.iv-close-btn.iv-dialog.iv-dialog-lg.iv-dialog-sm.iv-footer.iv-header.iv-icon-slot.iv-title-area
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records