# Dialog

A panel over the page for a short task or a piece of detail, which dims what is behind it.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/dialog shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A native `<dialog class="dex-dialog">`, opened with `showModal()`. `dex.css` dims the page behind it. A title, a line under it when it helps, the content, then the actions on the right with the main one last:

```html
<button class="dex-button dex-button--outline" onclick="document.getElementById('notice').showModal()">Edit notice period</button>

<dialog class="dex-dialog" id="notice" aria-labelledby="notice-title" aria-describedby="notice-text">
  <form method="dialog">
    <h2 class="dex-h3" id="notice-title">Notice period</h2>
    <p class="dex-small dex-muted" id="notice-text" style="margin-top: 0.5rem">Teams see this before they ask to meet you.</p>
    <label class="dex-form-row" style="margin-top: 1.25rem">
      <span class="dex-field-label">Weeks</span>
      <input class="dex-field" inputmode="numeric" value="4" />
    </label>
    <div style="display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem">
      <button class="dex-button dex-button--outline" value="cancel" formnovalidate>Cancel</button>
      <button class="dex-button" value="save">Save</button>
    </div>
  </form>
</dialog>

<script>
  // Close on a press outside it, as the app's dialogs do.
  const notice = document.getElementById('notice')
  notice.addEventListener('click', (event) => {
    if (event.target === notice) notice.close()
  })
</script>
```

- **With a form**: the form wraps the title, fields and buttons, so Enter in a field saves. A form that saves to a server closes the dialog itself once the save has worked.
- **Close button**: an icon-only `dex-button dex-button--ghost dex-button--sm` with `aria-label="Close"` and a Lucide `x`, placed in the top right corner with layout CSS of your own (`position: absolute; top: 0.75rem; right: 0.75rem`, and `position: relative` on the dialog). Leave it out when the buttons already say how to leave.
- **Without `<dialog>`** (a static mock or a screenshot): a `dex-dialog` inside a `dex-scrim`, as design.md shows.
- **Page dialog** (a whole screen of content, such as settings, laid over the current one): `dex.css` has no class for it. Use a `<dialog>` with layout CSS of your own, nearly the full screen (`width: calc(100vw - 2rem); height: calc(100dvh - 2rem)`), `background: var(--dex-background)`, `border-radius: var(--dex-radius-lg)`, no shadow, and a body that scrolls. It has a title and a close button.

## Rules

- Every dialog has a title, named with `aria-labelledby`. Add one line under it (`aria-describedby`) when that helps.
- A dialog closes on Escape, on a press outside it and from its close button. If closing would lose something, ask first with an alert dialog (https://brand.meetdex.ai/components/alert-dialog.md).
- In the footer the main action is last. On a phone the buttons stack, full width, with the main action on top.
- Name buttons for what they do ("Save", "Send to Synthesia"), never "OK" or "Submit".
