Files
shared/packages/web-ui/src/lib/components/Dialog.svelte
T

54 lines
1.1 KiB
Svelte
Raw Normal View History

2026-08-04 15:17:15 +02:00
<script lang="ts">
import type { Snippet } from 'svelte';
let {
children,
description = '',
footer,
open = $bindable(false),
title
}: {
children?: Snippet;
description?: string;
footer?: Snippet;
open?: boolean;
title: string;
} = $props();
function close(): void {
open = false;
}
</script>
{#if open}
<div
aria-label={title}
class="sc-dialog-backdrop"
role="presentation"
onclick={(event) => {
if (event.target === event.currentTarget) close();
}}
>
<section aria-modal="true" class="sc-dialog" role="dialog">
<div class="sc-dialog-header">
<div>
<h2 class="sc-dialog-title">{title}</h2>
{#if description}
<p class="sc-dialog-description">{description}</p>
{/if}
</div>
<button aria-label="Close" class="sc-dialog-close" type="button" onclick={close}>×</button>
</div>
<div class="sc-dialog-body">
{@render children?.()}
</div>
{#if footer}
<div class="sc-dialog-footer">
{@render footer()}
</div>
{/if}
</section>
</div>
{/if}