# Dialog

The one modal: a titled raised surface with a close button, over a blurred page.

## Basic

Every modal in the app is a `Dialog`: its `title` is the heading and the accessible name, the close button sits top right, Escape and a click on the backdrop close it too. The page behind is dimmed and blurred (`--q-dialog-scrim`, `--q-backdrop-blur`); with reduced transparency, or where blur is unsupported, the scrim thickens instead.

## Description and footer

`description` sits under the title and describes the dialog; `footer` holds its actions, the primary one last. The body scrolls while the header and footer stay.

## Required choices

`dismissible={false}` drops the close button and ignores Escape and the backdrop, so the footer is the only way out. Use it only while leaving would lose work or skip a required answer.

## Sizes

`sm`, `md` and `lg` are widths (`--q-dialog-sm`, `--q-dialog-md`, `--q-dialog-lg`); `xl` is the sheet, the window less `--q-dialog-gutter` on every side. `stable` holds the height (`--q-dialog-stable-height`) so tabs and steps do not reflow it. Without a size the dialog fits its content.

## Focus

On open, focus goes to the dialog itself, never to its first control, so nothing that opens on focus (a tooltip, a Help mark) opens by itself and Tab starts at the top. A field the person will type into straight away opts in with `autofocus`. On close, focus returns to the control that opened it.

`label` names the dialog more fully than its heading, where the heading alone is terse ("Versions", of which dataset).

## Modal

`Modal` is the layer under `Dialog`: the native element, the backdrop, the focus rule and the open and close motion, with no surface or header. The app uses it directly only for the search palette, whose field is its header; the dashboard's lint refuses other imports of it.

## Examples

```svelte
<script lang="ts">
  import Button from '@qualia-studios/design-ui/components/Button.svelte';
  import Dialog from '@qualia-studios/design-ui/components/Dialog.svelte';

  type Size = 'sm' | 'md' | 'lg' | 'xl';
  let basicOpen = $state(false);
  let footerOpen = $state(false);
  let choiceOpen = $state(false);
  const sizes: Size[] = ['sm', 'md', 'lg', 'xl'];
  let sized = $state<Size | null>(null);
</script>
```

### Example 1: A basic dialog

```svelte
<Button onclick={() => (basicOpen = true)}>Open dialog</Button>
<Dialog bind:open={basicOpen} size="sm" title="A modal dialog">
  <p>
    Backed by the native <code>&lt;dialog&gt;</code> element: top layer, focus
    trapping and light dismiss come from the platform.
  </p>
</Dialog>
```

### Example 2: A description and a footer

```svelte
<Button onclick={() => (footerOpen = true)}>Open dialog</Button>
<Dialog bind:open={footerOpen} size="md" title="Delete everything?">
  {#snippet description()}
    <p class="dim">This action cannot be undone.</p>
  {/snippet}
  {#snippet footer()}
    <Button class="text" onclick={() => (footerOpen = false)}>Cancel</Button
    >
    <Button class="danger" onclick={() => (footerOpen = false)}>
      Delete
    </Button>
  {/snippet}
  <p>Footers carry the confirm and cancel actions.</p>
</Dialog>
```

### Example 3: A required choice

No close button, Escape or backdrop: only the footer closes it.

```svelte
<Button onclick={() => (choiceOpen = true)}>Open dialog</Button>
<Dialog
  bind:open={choiceOpen}
  size="sm"
  title="Keep your changes?"
  dismissible={false}
>
  {#snippet footer()}
    <Button class="text" onclick={() => (choiceOpen = false)}
      >Discard</Button
    >
    <Button class="primary" onclick={() => (choiceOpen = false)}
      >Keep</Button
    >
  {/snippet}
  <p>The draft is not saved yet.</p>
</Dialog>
```

### Example 4: Four sizes

```svelte
{#each sizes as size (size)}
  <Button onclick={() => (sized = size)}>{size}</Button>
{/each}
<Dialog
  bind:open={() => sized !== null, (v) => !v && (sized = null)}
  size={sized ?? 'sm'}
  title="A {sized} dialog"
>
  <p>Its body scrolls inside it when the content runs long.</p>
</Dialog>
```

---

From the Qualia design guide: https://q-core-3b2732.gitlab.io/components/dialog. Every page as markdown: https://q-core-3b2732.gitlab.io/llms.txt
