# Dialog

A window over the page for a form, details or settings.

A window that holds any content (a form, details, settings) and closes on Escape, a click outside or its close button. It sits over a dimmed page. Focus is trapped inside and returns to the trigger; the page behind is inert and does not scroll. To confirm a consequential action (delete, discard, revoke), use Alert dialog, which is this window with role="alertdialog". Behaviour comes from the Zag dialog machine, through Ark UI in React, Vue and Svelte.

Kind: component · Category: Overlays · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `dialog` machine, through Ark UI

## Add

```bash
npx fndn add dialog
```

It writes the folder `dialog/` into the project's ui folder (`index.ts`, `dialog.tsx`, `Dialog.vue`, `Dialog.svelte`, `dialog.recipe.ts`), and what it is built from: [Button](/components/button.md), [Tooltip](/components/tooltip.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Dialog } from "@/components/ui/dialog";
```

```vue
import { Dialog } from "@/components/ui/dialog";
```

```svelte
import { Dialog } from "$lib/components/ui/dialog";
```

## Parts

In the DOM the root carries `data-slot="dialog"` and each part `data-slot="dialog-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `dialog` |  | Layout-neutral hook around the trigger (display: contents) |
| `trigger` | `button` | `dialog-trigger` |  | aria-haspopup=dialog, aria-expanded, data-state=open\|closed. The default trigger is a Button. Marked data-dialog="trigger". |
| `backdrop` | `div` | `dialog-backdrop` |  | Dims the page with color.scrim; rendered in a portal; data-state=open\|closed. Stacks at --fndn-z-dialog (base.css). |
| `positioner` | `div` | `dialog-positioner` |  | Centres the window, or pins it near the top (placement=top); rendered in a portal |
| `content` | `div` | `dialog-content` |  | role=dialog\|alertdialog, aria-modal; data-state=open\|closed; carries kbd-instant |
| `header` | `div` | `dialog-header` |  |  |
| `title` | `h2` | `dialog-title` |  |  |
| `close` | `button` | `dialog-close` | optional | A Button: ghost, size sm, square, shape rounded, muted, aria-label=Close, with a tooltip of the same text. Only its placement (negative margins into the header corner) is the dialog's. Marked data-dialog="close". |
| `description` | `div` | `dialog-description` | optional |  |
| `body` | `div` | `dialog-body` | optional |  |
| `footer` | `div` | `dialog-footer` | optional | Actions, as Buttons |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | Bindable (React: `defaultOpen` and `onOpenChange`; Vue: `v-model:open`; Svelte: `bind:open`). data-state=open\|closed on trigger, backdrop and content. |
| `title` | `string` |  | Required: it names the dialog. |
| `description` | `string` |  |  |
| `role` | `"dialog" \| "alertdialog"` | `"dialog"` | alertdialog for destructive confirms: a click outside does not close it and focus starts on the first action. |
| `actions` | `{ label: string; value?: string; variant?: button variant; close?: boolean; form?: string }[]` |  | Footer buttons in order, least destructive first. Each closes the dialog unless close is false. For a dialog that holds a form: an action with form="<id>" (the id of a form in the body) is rendered type="submit" form="<id>", so the browser checks the form (required, pattern) and Enter in one of its fields submits it. Its click does nothing else: the form's submit event, which the browser fires only for a valid form, calls onAction and closes the dialog unless close is false. A refused form leaves the dialog open with the browser's message. The form's own submit handler prevents the default, as any form's in an app does. An action without form is a plain button. |
| `closable` | `boolean` | `true` | Show the close button in the header. |
| `bare` | `boolean` | `false` | Bare: the dialog is only the frame (position, focus trap, motion). No fill, no shadow, no padding, no header; the title still names it for assistive technology. Its one child is the surface, as in a command palette. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Width of the window: sm 360px, md 440px, lg 880px (a large preview, such as agent-screen's viewer). |
| `placement` | `"center" \| "top"` | `"center"` | Where the window sits: center (on a phone with a coarse pointer, at the bottom near the thumb), or top: pinned below the top of the viewport (min(15vh, 120px)) and growing downward, for a window whose height changes while it is used, such as a command palette whose results follow what is typed. A top window scales from its top edge. |
| `instant` | `boolean` | `false` | Opens and closes at once from the pointer too (from the keyboard it always does): no fade or scale of the window and the backdrop. For a window summoned many times a session, such as a command palette. |
| `initialFocus` | `HTMLElement \| string \| (() => HTMLElement \| null)` |  | What takes focus when the dialog opens, in one of three forms: an element (a ref's current element); a CSS selector string, looked up inside the window first, then in the document ("#invite-email"); or a function returning the element, called when the dialog opens (the element may not exist before). Default: the first control; for alertdialog the first action. Ark's initialFocusEl. |
| `triggerLabel` | `string` |  | Renders a default Button trigger with this label. Otherwise pass your own trigger, or control `open` yourself. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `openChange` | (open: boolean) |
| `action` | (value: string) when a footer action is pressed; for an action with form, when its form is submitted |

## Slots

| Slot | Content |
| --- | --- |
| `default` | Body content |
| `trigger` | Your own trigger element (React `trigger` prop, Vue `trigger` slot, Svelte `trigger` snippet that spreads the props it receives) |
| `footer` | Custom footer instead of `actions` |

## States

`open`, `hover`, `press`, `focus-visible`

## Keyboard and accessibility

Role: dialog | alertdialog.

Keyboard:

- Enter / Space on the trigger open
- Focus moves into the window: the first focusable control, or the first action of an alertdialog
- Tab and Shift+Tab cycle inside the window; focus cannot leave it
- Escape closes and returns focus to the trigger
- Enter in a field of a form an action names submits it, as that action's button would
- A click on the dimmed page closes a dialog, not an alertdialog; either way it never moves focus out of the window

Notes:

- Labelled by its title and described by its description.
- While open, the rest of the page is inert and does not scroll.
- Opening and closing from the keyboard are instant.

## Motion

- window: opacity + scale from motion.popup-scale around its centre (its top edge when placement is top), duration.slow, easing.out-strong; closes at duration.fast
- backdrop: opacity with the window
- close button: the button's own hover and press (ghost Button)
- instant: no motion at all; the window and the backdrop appear and leave in one frame
- mounted open (defaultOpen, or open at mount): window and backdrop are drawn at once, with no entrance (data-mounted-open until it first closes); its close, and every later open, animate as above

## Tokens

`color.scrim`, `color.surface`, `color.ink`, `color.ink-2`, `shadow.overlay`, `radius.window`, `text.sm`, `text.md`, `duration.fast`, `duration.slow`, `easing.out-strong`, `motion.popup-scale`, `z.dialog`

## Dependencies

- [Button](/components/button.md)
- [Tooltip](/components/tooltip.md)

## Examples

### Invite teammates

React · `invite-teammates.tsx`

```tsx
import { Dialog, type DialogAction } from "@/components/ui/dialog";
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Select } from "@/components/ui/select";

const roles = [
  { value: "member", label: "Member" },
  { value: "admin", label: "Admin" },
  { value: "viewer", label: "Viewer" },
];

const actions: DialogAction[] = [
  { label: "Cancel", value: "cancel", variant: "ghost" },
  { label: "Send invites", value: "send", variant: "primary" },
];

/* a dialog holds any content and closes on Escape, a click outside or its close button */
export default function InviteTeammates() {
  return (
    <div className="flex w-80 items-center gap-3">
      <div className="min-w-0 flex-1">
        <div className="text-sm font-medium text-ink">Members</div>
        <div className="text-xs text-ink-2">12 people at Northwind</div>
      </div>
      <Dialog
        triggerLabel="Invite teammates"
        title="Invite teammates"
        description="They get an email with a link to join Northwind. Invites expire after 7 days."
        actions={actions}
        initialFocus="input"
      >
        <div className="flex flex-col gap-4">
          <Field label="Email addresses" helper="Separate several addresses with commas.">
            <Input type="email" multiple placeholder="priya@northwind.example, jonas@northwind.example" />
          </Field>
          <Select label="Role" items={roles} defaultValue="member" />
        </div>
      </Dialog>
    </div>
  );
}
```

Vue · `invite-teammates.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Dialog, type DialogAction } from "@/components/ui/dialog";
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Select } from "@/components/ui/select";

const roles = [
  { value: "member", label: "Member" },
  { value: "admin", label: "Admin" },
  { value: "viewer", label: "Viewer" },
];

const role = ref("member");

const actions: DialogAction[] = [
  { label: "Cancel", value: "cancel", variant: "ghost" },
  { label: "Send invites", value: "send", variant: "primary" },
];
</script>

<!-- a dialog holds any content and closes on Escape, a click outside or its close button -->
<template>
  <div class="flex w-80 items-center gap-3">
    <div class="min-w-0 flex-1">
      <div class="text-sm font-medium text-ink">Members</div>
      <div class="text-xs text-ink-2">12 people at Northwind</div>
    </div>
    <Dialog
      triggerLabel="Invite teammates"
      title="Invite teammates"
      description="They get an email with a link to join Northwind. Invites expire after 7 days."
      :actions="actions"
      initialFocus="input"
    >
      <div class="flex flex-col gap-4">
        <Field label="Email addresses" helper="Separate several addresses with commas.">
          <Input type="email" multiple placeholder="priya@northwind.example, jonas@northwind.example" />
        </Field>
        <Select v-model:value="role" label="Role" :items="roles" />
      </div>
    </Dialog>
  </div>
</template>
```

Svelte · `invite-teammates.svelte`

```svelte
<script lang="ts">
  import { Dialog, type DialogAction } from "$lib/components/ui/dialog";
  import { Field } from "$lib/components/ui/field";
  import { Input } from "$lib/components/ui/input";
  import { Select } from "$lib/components/ui/select";

  const roles = [
    { value: "member", label: "Member" },
    { value: "admin", label: "Admin" },
    { value: "viewer", label: "Viewer" },
  ];

  let role = $state("member");

  const actions: DialogAction[] = [
    { label: "Cancel", value: "cancel", variant: "ghost" },
    { label: "Send invites", value: "send", variant: "primary" },
  ];
</script>

<!-- a dialog holds any content and closes on Escape, a click outside or its close button -->
<div class="flex w-80 items-center gap-3">
  <div class="min-w-0 flex-1">
    <div class="text-sm font-medium text-ink">Members</div>
    <div class="text-xs text-ink-2">12 people at Northwind</div>
  </div>
  <Dialog
    triggerLabel="Invite teammates"
    title="Invite teammates"
    description="They get an email with a link to join Northwind. Invites expire after 7 days."
    {actions}
    initialFocus="input"
  >
    <div class="flex flex-col gap-4">
      <Field label="Email addresses" helper="Separate several addresses with commas.">
        <Input type="email" multiple placeholder="priya@northwind.example, jonas@northwind.example" />
      </Field>
      <Select bind:value={role} label="Role" items={roles} />
    </div>
  </Dialog>
</div>
```

### Deploy details

React · `deploy-details.tsx`

```tsx
import { Dialog } from "@/components/ui/dialog";
import { StatusPill } from "@/components/ui/status-pill";
import { TextRow } from "@/components/ui/text-row";

const deploy = {
  id: "dpl_7f3a9c",
  branch: "main",
  commit: "a1b2c3d",
  message: "Add retry to webhook delivery",
  duration: "1m 42s",
  region: "Frankfurt (fra1)",
};

/* read-only content, no footer: the close button, Escape or a click outside closes it */
export default function DeployDetails() {
  return (
    <div className="flex w-80 items-center gap-3">
      <div className="min-w-0 flex-1">
        <div className="flex items-center gap-2 text-sm font-medium text-ink">
          Production <StatusPill tone="green">Ready</StatusPill>
        </div>
        <div className="text-xs text-ink-2">{`${deploy.id} · ${deploy.branch} · 2 min ago`}</div>
      </div>
      <Dialog
        triggerLabel="View deploy"
        title={`Deploy ${deploy.id}`}
        description="web-app to Production, started by Maya Chen 2 min ago."
      >
        <div className="flex flex-col">
          <TextRow label="Status" value={<StatusPill tone="green">Ready</StatusPill>} />
          <TextRow label="Branch" value={deploy.branch} />
          <TextRow label="Commit" value={deploy.commit} meta={deploy.message} />
          <TextRow label="Build time" value={deploy.duration} />
          <TextRow label="Region" value={deploy.region} />
        </div>
      </Dialog>
    </div>
  );
}
```

Vue · `deploy-details.vue`

```vue
<script setup lang="ts">
import { Dialog } from "@/components/ui/dialog";
import { StatusPill } from "@/components/ui/status-pill";
import { TextRow } from "@/components/ui/text-row";

const deploy = {
  id: "dpl_7f3a9c",
  branch: "main",
  commit: "a1b2c3d",
  message: "Add retry to webhook delivery",
  duration: "1m 42s",
  region: "Frankfurt (fra1)",
};
</script>

<!-- read-only content, no footer: the close button, Escape or a click outside closes it -->
<template>
  <div class="flex w-80 items-center gap-3">
    <div class="min-w-0 flex-1">
      <div class="flex items-center gap-2 text-sm font-medium text-ink">
        Production <StatusPill tone="green">Ready</StatusPill>
      </div>
      <div class="text-xs text-ink-2">{{ `${deploy.id} · ${deploy.branch} · 2 min ago` }}</div>
    </div>
    <Dialog
      triggerLabel="View deploy"
      :title="`Deploy ${deploy.id}`"
      description="web-app to Production, started by Maya Chen 2 min ago."
    >
      <div class="flex flex-col">
        <TextRow label="Status">
          <template #value><StatusPill tone="green">Ready</StatusPill></template>
        </TextRow>
        <TextRow label="Branch" :value="deploy.branch" />
        <TextRow label="Commit" :value="deploy.commit" :meta="deploy.message" />
        <TextRow label="Build time" :value="deploy.duration" />
        <TextRow label="Region" :value="deploy.region" />
      </div>
    </Dialog>
  </div>
</template>
```

Svelte · `deploy-details.svelte`

```svelte
<script lang="ts">
  import { Dialog } from "$lib/components/ui/dialog";
  import { StatusPill } from "$lib/components/ui/status-pill";
  import { TextRow } from "$lib/components/ui/text-row";

  const deploy = {
    id: "dpl_7f3a9c",
    branch: "main",
    commit: "a1b2c3d",
    message: "Add retry to webhook delivery",
    duration: "1m 42s",
    region: "Frankfurt (fra1)",
  };
</script>

<!-- read-only content, no footer: the close button, Escape or a click outside closes it -->
<div class="flex w-80 items-center gap-3">
  <div class="min-w-0 flex-1">
    <div class="flex items-center gap-2 text-sm font-medium text-ink">
      Production <StatusPill tone="green">Ready</StatusPill>
    </div>
    <div class="text-xs text-ink-2">{`${deploy.id} · ${deploy.branch} · 2 min ago`}</div>
  </div>
  <Dialog
    triggerLabel="View deploy"
    title={`Deploy ${deploy.id}`}
    description="web-app to Production, started by Maya Chen 2 min ago."
  >
    <div class="flex flex-col">
      <TextRow label="Status">
        {#snippet value()}<StatusPill tone="green">Ready</StatusPill>{/snippet}
      </TextRow>
      <TextRow label="Branch" value={deploy.branch} />
      <TextRow label="Commit" value={deploy.commit} meta={deploy.message} />
      <TextRow label="Build time" value={deploy.duration} />
      <TextRow label="Region" value={deploy.region} />
    </div>
  </Dialog>
</div>
```

### Rename a project

React · `rename-project.tsx`

```tsx
import { useState } from "react";
import { Dialog, type DialogAction } from "@/components/ui/dialog";
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

/* Rename submits the form in the body: the browser checks the required field, Enter in it
 * renames, and the dialog closes on the form's submit */
const actions: DialogAction[] = [
  { label: "Cancel", value: "cancel", variant: "ghost" },
  { label: "Rename", value: "rename", variant: "primary", form: "rename-project-form" },
];

export default function RenameProject() {
  const [project, setProject] = useState("billing-api");
  const [name, setName] = useState(project);

  return (
    <div className="flex w-80 items-center gap-3">
      <div className="min-w-0 flex-1">
        <div className="text-sm font-medium text-ink">Project name</div>
        <div className="truncate text-xs text-ink-2" title={`northwind.dev/${project}`}>{`northwind.dev/${project}`}</div>
      </div>
      <Dialog
        size="sm"
        triggerLabel="Rename"
        title="Rename project"
        actions={actions}
        onOpenChange={(open) => { if (open) setName(project); }}
        initialFocus="input"
      >
        <form id="rename-project-form" onSubmit={(event) => { event.preventDefault(); setProject(name.trim() || project); }}>
          <Field label="Project name" required helper={`URLs become northwind.dev/${name.trim() || "…"}.`}>
            <Input name="name" value={name} onChange={(event) => setName(event.target.value)} />
          </Field>
        </form>
      </Dialog>
    </div>
  );
}
```

Vue · `rename-project.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Dialog, type DialogAction } from "@/components/ui/dialog";
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

/* Rename submits the form in the body: the browser checks the required field, Enter in it
 * renames, and the dialog closes on the form's submit */
const actions: DialogAction[] = [
  { label: "Cancel", value: "cancel", variant: "ghost" },
  { label: "Rename", value: "rename", variant: "primary", form: "rename-project-form" },
];

const project = ref("billing-api");
const name = ref(project.value);

function opened(open: boolean) {
  if (open) name.value = project.value;
}
function rename() {
  project.value = name.value.trim() || project.value;
}
</script>

<template>
  <div class="flex w-80 items-center gap-3">
    <div class="min-w-0 flex-1">
      <div class="text-sm font-medium text-ink">Project name</div>
      <div class="truncate text-xs text-ink-2" :title="`northwind.dev/${project}`">{{ `northwind.dev/${project}` }}</div>
    </div>
    <Dialog
      size="sm"
      triggerLabel="Rename"
      title="Rename project"
      :actions="actions"
      initialFocus="input"
      @open-change="opened"
    >
      <form id="rename-project-form" @submit.prevent="rename">
        <Field label="Project name" required :helper="`URLs become northwind.dev/${name.trim() || '…'}.`">
          <Input v-model:value="name" name="name" />
        </Field>
      </form>
    </Dialog>
  </div>
</template>
```

Svelte · `rename-project.svelte`

```svelte
<script lang="ts">
  import { Dialog, type DialogAction } from "$lib/components/ui/dialog";
  import { Field } from "$lib/components/ui/field";
  import { Input } from "$lib/components/ui/input";

  /* Rename submits the form in the body: the browser checks the required field, Enter in it
   * renames, and the dialog closes on the form's submit */
  const actions: DialogAction[] = [
    { label: "Cancel", value: "cancel", variant: "ghost" },
    { label: "Rename", value: "rename", variant: "primary", form: "rename-project-form" },
  ];

  let project = $state("billing-api");
  let name = $state("billing-api");

  function rename(event: SubmitEvent) {
    event.preventDefault();
    project = name.trim() || project;
  }
</script>

<div class="flex w-80 items-center gap-3">
  <div class="min-w-0 flex-1">
    <div class="text-sm font-medium text-ink">Project name</div>
    <div class="truncate text-xs text-ink-2" title={`northwind.dev/${project}`}>{`northwind.dev/${project}`}</div>
  </div>
  <Dialog
    size="sm"
    triggerLabel="Rename"
    title="Rename project"
    {actions}
    initialFocus="input"
    onopenchange={(open) => { if (open) name = project; }}
  >
    <form id="rename-project-form" onsubmit={rename}>
      <Field label="Project name" required helper={`URLs become northwind.dev/${name.trim() || "…"}.`}>
        <Input bind:value={name} name="name" />
      </Field>
    </form>
  </Dialog>
</div>
```

### Keyboard shortcuts

React · `keyboard-shortcuts.tsx`

```tsx
import { Question } from "@phosphor-icons/react";
import { Button } from "@/components/ui/button";
import { Dialog } from "@/components/ui/dialog";
import { Kbd } from "@/components/ui/kbd";
import { TextRow } from "@/components/ui/text-row";

const shortcuts = [
  { action: "Search the workspace", keys: ["⌘", "K"] },
  { action: "Create a project", keys: ["C"] },
  { action: "Go to deploys", keys: ["G", "D"] },
  { action: "Toggle the sidebar", keys: ["⌘", "B"] },
];

/* your own trigger: a ghost Button with an icon, at the foot of the help panel */
export default function KeyboardShortcuts() {
  return (
    <div className="flex w-80 items-center gap-3">
      <div className="min-w-0 flex-1">
        <div className="text-sm font-medium text-ink">Work faster</div>
        <div className="text-xs text-ink-2">Every action in Northwind has a key.</div>
      </div>
      <Dialog
        size="sm"
        title="Keyboard shortcuts"
        trigger={<Button variant="ghost" size="sm" icon={<Question data-slot="icon" weight="bold" />}>Shortcuts</Button>}
      >
        <div className="flex flex-col">
          {shortcuts.map((s) => (
            <TextRow key={s.action} label={s.action} value={<Kbd keys={s.keys} />} />
          ))}
        </div>
      </Dialog>
    </div>
  );
}
```

Vue · `keyboard-shortcuts.vue`

```vue
<script setup lang="ts">
import { PhQuestion } from "@phosphor-icons/vue";
import { Button } from "@/components/ui/button";
import { Dialog } from "@/components/ui/dialog";
import { Kbd } from "@/components/ui/kbd";
import { TextRow } from "@/components/ui/text-row";

const shortcuts = [
  { action: "Search the workspace", keys: ["⌘", "K"] },
  { action: "Create a project", keys: ["C"] },
  { action: "Go to deploys", keys: ["G", "D"] },
  { action: "Toggle the sidebar", keys: ["⌘", "B"] },
];
</script>

<!-- your own trigger: a ghost Button with an icon, at the foot of the help panel -->
<template>
  <div class="flex w-80 items-center gap-3">
    <div class="min-w-0 flex-1">
      <div class="text-sm font-medium text-ink">Work faster</div>
      <div class="text-xs text-ink-2">Every action in Northwind has a key.</div>
    </div>
    <Dialog size="sm" title="Keyboard shortcuts">
      <template #trigger>
        <Button variant="ghost" size="sm">
          <template #icon><PhQuestion data-slot="icon" weight="bold" /></template>
          Shortcuts
        </Button>
      </template>
      <div class="flex flex-col">
        <TextRow v-for="s in shortcuts" :key="s.action" :label="s.action">
          <template #value><Kbd :keys="s.keys" /></template>
        </TextRow>
      </div>
    </Dialog>
  </div>
</template>
```

Svelte · `keyboard-shortcuts.svelte`

```svelte
<script lang="ts">
  import Question from "phosphor-svelte/lib/QuestionIcon";
  import type { HTMLButtonAttributes } from "svelte/elements";
  import { Button } from "$lib/components/ui/button";
  import { Dialog } from "$lib/components/ui/dialog";
  import { Kbd } from "$lib/components/ui/kbd";
  import { TextRow } from "$lib/components/ui/text-row";

  const shortcuts = [
    { action: "Search the workspace", keys: ["⌘", "K"] },
    { action: "Create a project", keys: ["C"] },
    { action: "Go to deploys", keys: ["G", "D"] },
    { action: "Toggle the sidebar", keys: ["⌘", "B"] },
  ];
</script>

<!-- your own trigger: a ghost Button with an icon, at the foot of the help panel; it takes the
     dialog's trigger props -->
{#snippet trigger(props: () => HTMLButtonAttributes)}
  <Button {...props()} variant="ghost" size="sm">
    {#snippet icon()}<Question data-slot="icon" weight="bold" />{/snippet}
    Shortcuts
  </Button>
{/snippet}
<div class="flex w-80 items-center gap-3">
  <div class="min-w-0 flex-1">
    <div class="text-sm font-medium text-ink">Work faster</div>
    <div class="text-xs text-ink-2">Every action in Northwind has a key.</div>
  </div>
  <Dialog size="sm" title="Keyboard shortcuts" {trigger}>
    <div class="flex flex-col">
      {#each shortcuts as s (s.action)}
        <TextRow label={s.action}>
          {#snippet value()}<Kbd keys={s.keys} />{/snippet}
        </TextRow>
      {/each}
    </div>
  </Dialog>
</div>
```

## Recipe

`dialog.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* dialog — a centred window over a dimmed page: title, description, body, actions.
 * Behaviour comes from the Zag dialog machine: focus trap, Escape, focus return, scroll lock,
 * inert page. Not anchored to a trigger, so it scales from its own centre (from its top edge when
 * placed at the top).
 * The root is only a hook for the trigger; backdrop and window live in a portal. Stacking (above
 * popups, below tooltips) comes from base.css (--fndn-z-dialog). The trigger, the close button and
 * the actions are Buttons; only their placement is the dialog's (passed as className). The trigger
 * and the close button are marked data-dialog="trigger|close".
 * A dialog that is already open when it mounts is drawn at once: the adapter marks its backdrop and
 * window data-mounted-open until it first closes, and the entrance (@starting-style) skips them.
 * Opening it later, and every close, animate as usual. */

/* on a phone ([@media(pointer:coarse)_and_(max-width:480px)], written out in full in each class so
 * Tailwind finds it) the window sits near the thumb and the actions share the row */

export const dialog = tv({
  slots: {
    base: "contents",
    /* a trigger in a toolbar keeps its size */
    trigger: "shrink-0",
    backdrop: [
      "kbd-instant",
      "fixed inset-0 bg-scrim",
      "motion-opacity-slow-out motion-also-[display_var(--fndn-duration-slow)_allow-discrete]",
      "starting:data-[state=open]:not-data-mounted-open:opacity-0",
      "data-[state=closed]:opacity-0",
      "data-[state=closed]:motion-opacity-fast-out data-[state=closed]:motion-also-[display_var(--fndn-duration-fast)_allow-discrete]",
    ],
    /* the engine sets pointer-events: none on <body> while modal; the dimmed area still takes the
     * press so it can be told apart from the page (and keep focus inside, see the adapter) */
    positioner: [
      "fixed inset-0 flex justify-center p-4 pb-[calc(16px+env(safe-area-inset-bottom,0px))]",
      "overflow-y-auto overscroll-contain pointer-events-auto",
    ],
    content: [
      "kbd-instant",
      "relative flex flex-col w-full max-w-[440px] rounded-window bg-surface text-ink shadow-overlay outline-none",
      "[transform:scale(1)]",
      "motion-opacity-slow-out motion-transform-slow-out motion-also-[display_var(--fndn-duration-slow)_allow-discrete]",
      "starting:data-[state=open]:not-data-mounted-open:opacity-0 starting:data-[state=open]:not-data-mounted-open:scale-popup",
      "data-[state=closed]:opacity-0 data-[state=closed]:scale-popup",
      /* it leaves faster than it came */
      "data-[state=closed]:motion-opacity-fast-out data-[state=closed]:motion-transform-fast-out",
      "data-[state=closed]:motion-also-[display_var(--fndn-duration-fast)_allow-discrete]",
    ],
    header: "flex items-start justify-between gap-3 px-4 pt-4 pb-0",
    title: "min-w-0 m-0 text-md font-semibold leading-[1.4] tracking-[-0.01em] text-ink wrap-anywhere",
    /* the close button sits on the title's first line and reaches into the corner */
    close: "shrink-0 -my-1 ms-0 -me-1.5",
    description: "px-4 pt-1 pb-0 text-sm leading-normal text-ink-2 wrap-anywhere",
    body: "px-4 pt-3 pb-0 text-sm leading-normal text-ink wrap-anywhere",
    footer: [
      "flex flex-wrap items-center justify-end gap-2 p-4",
      "[@media(pointer:coarse)_and_(max-width:480px)]:[&>[data-slot=button]]:flex-auto",
    ],
  },
  variants: {
    /* width: sm 360px, md 440px, lg 880px for a large preview */
    /* placement: center (a decision, near the thumb on a phone); top: pinned below the top of the
     * viewport and growing downward, so a window whose height follows what is typed (a command
     * palette's results) never moves its field under the caret. It scales from its top edge. */
    placement: {
      center: {
        positioner: "items-center [@media(pointer:coarse)_and_(max-width:480px)]:items-end",
        content: "origin-center",
      },
      top: {
        positioner: "items-start pt-[min(15vh,120px)]",
        content: "origin-top",
      },
    },
    /* instant: opens and closes at once from the pointer too, as from the keyboard: for a window
     * summoned many times a session (a command palette). No entrance, no exit. */
    instant: {
      true: {
        backdrop: "transition-none!",
        content: "transition-none!",
      },
    },
    size: {
      sm: { content: "max-w-[360px]" },
      md: {},
      lg: { content: "max-w-[880px]" },
    },
    /* bare: only the frame (position, focus trap, motion). Its one child is the surface (a command
     * palette: the Search panel), so there is never a box in a box. No fill, no shadow, no
     * padding; the header is kept for assistive technology (the title names the dialog) and not
     * shown; the adapter renders no close button. */
    bare: {
      true: {
        content: "bg-transparent shadow-none rounded-none",
        header: "sr-only p-0",
        body: "p-0",
      },
    },
  },
  defaultVariants: { size: "md", placement: "center" },
});

export type DialogRecipeProps = VariantProps<typeof dialog>;
```
