Overlays
Dialog
Interrupts the page for a focused task, as a centered modal or a sheet from the side.
Installation
npx sinaui add dialogCopy src/lib/ui/Dialog.svelte, Icon.svelte and tokens.css. The close button's icon comes from @hugeicons/core-free-icons.
Examples
Modal
Centered, with a title, description and footer actions. Clicking the backdrop or pressing Escape closes it.
<script lang="ts">
import Button from '#lib/ui/Button.svelte';
import Dialog from '#lib/ui/Dialog.svelte';
import Input from '#lib/ui/Input.svelte';
let open = $state(false);
</script>
<Button variant="secondary" onclick={() => (open = true)}>Edit scholar</Button>
<Dialog
bind:open
title="Edit scholar"
description="Changes appear in the House of Wisdom catalog right away."
>
<Input
label="Name"
name="name"
value="Maryam al-Ijliya"
autocomplete="off"
hint="Astrolabe maker, Aleppo, 10th century."
/>
{#snippet footer()}
<Button variant="secondary" onclick={() => (open = false)}>Cancel</Button>
<Button onclick={() => (open = false)}>Save changes</Button>
{/snippet}
</Dialog>Side sheet
side="start" slides in from the reading-start edge, and from the right in right-to-left pages; side="end" from the other. The docs' mobile navigation uses it. Set --ui-sheet-width (20rem by default) to make it wider, and --ui-sheet-inset (3rem, the room left beside it on narrow screens) to 0 for a detail panel that fills a phone.
<script lang="ts">
import Button from '#lib/ui/Button.svelte';
import Dialog from '#lib/ui/Dialog.svelte';
let open = $state(false);
</script>
<Button variant="secondary" onclick={() => (open = true)}>Open reading rooms</Button>
<Dialog bind:open side="start" title="Reading rooms" description="Where the manuscripts are kept.">
<ul>
<li>Bayt al-Hikma, Baghdad</li>
<li>Library of Córdoba</li>
<li>Al-Qarawiyyin, Fez</li>
</ul>
</Dialog>With a status icon
The icon snippet sits before the title, for a sheet that shows a record's state at a glance. It's decorative: the title still names the dialog.
<script lang="ts">
import { BookOpen01Icon } from '@hugeicons/core-free-icons';
import Button from '#lib/ui/Button.svelte';
import Dialog from '#lib/ui/Dialog.svelte';
import Icon from '#lib/ui/Icon.svelte';
let { open = $bindable(false) }: { open?: boolean } = $props();
</script>
<Button variant="secondary" onclick={() => (open = true)}>Open the loan</Button>
<Dialog
bind:open
side="end"
title="Loan returned"
description="The Canon of Medicine, back on its shelf."
>
{#snippet icon()}
<span class="status"><Icon icon={BookOpen01Icon} size={18} /></span>
{/snippet}
<p>Returned to the House of Wisdom two days early.</p>
</Dialog>
<style>
.status {
display: grid;
place-items: center;
inline-size: 2.25rem;
block-size: 2.25rem;
border-radius: var(--ui-radius-pill);
background: var(--ui-hover);
color: var(--ui-fg);
}
p {
margin: 0;
}
</style>Props
| Prop | Type | Default |
|---|---|---|
open | boolean, bindable | false |
title | string (required) | |
description | string | |
icon | Snippet, before the title | |
side | 'center' | 'start' | 'end' | 'center' |
closeLabel | string | 'Close' |
footer | Snippet |
Accessibility
- Built on
<dialog>withshowModal(): focus stays inside, the page behind is inert, and focus returns to the trigger on close. - Labeled by its
titleand described by itsdescription. - Dragging a text selection out onto the backdrop doesn't close it.
- Add
autofocusto the field that should receive focus when it opens. TranslatecloseLabelfor non-English interfaces.
| Key | Action |
|---|---|
| Tab / Shift Tab | Moves between controls inside the dialog. |
| Escape | Closes the dialog and returns focus. |