Dialog

A modal window over a dimmed page, and the Alert Dialog that asks before something can't be undone. Built on ui-sdk: the page behind is inert, focus stays inside and starts on the first control, Escape closes, and focus returns to the trigger.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

size
closeButton

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse Dialog for a short task that holds the page until it is done, like editing a contact's details. Use AlertDialog to ask before something can't be undone, like archiving a contact.
DoWrite an AlertDialogTitle as a question, like Archive contact?, say what happens in AlertDialogDescription, and name the confirming button with the action, like Archive.
DoPut data-agent-confirm on the confirming button in the footer, not on the trigger, so Firm Pilot can't archive, send or delete without the lawyer.
DoLet closing return focus on its own: it goes back to the trigger, or to what had focus before the dialog opened. Pass finalFocus only when that control is gone, like the row a delete removed.
Don'tTurn off closeButton on DialogHeader. A dialog always needs a visible way out besides Escape; only AlertDialog leaves it out, because its choice is in the footer.
Don'tUse a dialog for a long form or a record read beside the page, like a whole contact. Use Drawer, the CRM's side panel.

Props

Dialog takes ui-sdk's options (open, defaultOpen, onOpenChange, modal, closeOnOutsidePress, presentation, controller); AlertDialog the same minus modal and outside press. DialogContent takes initialFocus, finalFocus and keepMounted. DialogClose and AlertDialogClose take render and value.

DialogContent

PropTypeDefaultDescription
childrenReactNode—What it shows inside.
size"sm" | "md" | "lg" | "xl""sm"sm 448 · md 512 · lg 672 · xl 900, shrinking to the screen.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

DialogHeader

PropTypeDefaultDescription
closeButtonbooleantrueShows the close button on the right. Leave it on: a dialog should always have a visible way out besides Escape.

DialogBody

No props of its own.

DialogFooter

No props of its own.

DialogTitle

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

DialogDescription

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

AlertDialog

No props of its own.

AlertDialogContent

PropTypeDefaultDescription
childrenReactNode—What it shows inside.
size"sm" | "md" | "lg" | "xl""sm"sm 448 · md 512 · lg 672 · xl 900, shrinking to the screen.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import {
  Button,
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@leap-crm/design-system";

<Dialog>
  <DialogTrigger render={<Button intent="outline">Edit note</Button>} />
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Edit note</DialogTitle>
      <DialogDescription>Changes are saved to the opportunity.</DialogDescription>
    </DialogHeader>
    <DialogFooter>
      <DialogClose render={<Button intent="outline">Cancel</Button>} />
      <DialogClose render={<Button>Save</Button>} />
    </DialogFooter>
  </DialogContent>
</Dialog>

Alert dialog

Asks before archiving. No close button and a press outside doesn't close it: the choice is in the footer. Each action's value reaches onOpenChange as details.returnValue.

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { Archive, Pencil } from "lucide-react";

import { useId, useState } from "react";

import { AlertDialog, AlertDialogBody, AlertDialogClose, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Button, Checkbox, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@leap-crm/design-system";

const sizes = ["sm", "md", "lg", "xl"] as const;

function ArchiveContact() {
  const [result, setResult] = useState("");
  const alsoOpportunities = useId();
  return (
    <div className="flex items-center gap-3">
      <AlertDialog
        onOpenChange={(open, details) => {
          if (!open) setResult(details.returnValue ?? "dismissed");
        }}
      >
        <AlertDialogTrigger
          render={
            <Button intent="destructive" icon={<Archive />}>
              Archive contact
            </Button>
          }
        />
        <AlertDialogContent>
          <AlertDialogHeader>
            <AlertDialogTitle>Archive contact?</AlertDialogTitle>
            <AlertDialogDescription>
              Jane Citizen will be hidden from search. Her matters stay in LEAP.
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogBody>
            <div className="flex items-center gap-2">
              <Checkbox id={alsoOpportunities} defaultChecked />
              <label
                htmlFor={alsoOpportunities}
                className="text-neutral-text-secondary text-base"
              >
                Also archive 2 open opportunities
              </label>
            </div>
          </AlertDialogBody>
          <AlertDialogFooter>
            <AlertDialogClose
              value="cancel"
              render={<Button intent="outline">Cancel</Button>}
            />
            <AlertDialogClose
              value="archive"
              render={
                <Button intent="destructive" icon={<Archive />}>
                  Archive
                </Button>
              }
            />
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
      {result && (
        <span className="text-body text-neutral-text-muted">
          Closed with: {result}
        </span>
      )}
    </div>
  );
}

function EditDialog({ size }: { size: (typeof sizes)[number] }) {
  return (
    <Dialog>
      <DialogTrigger
        render={
          <Button intent="outline" icon={<Pencil />} className="uppercase">
            {size}
          </Button>
        }
      />
      <DialogContent size={size}>
        <DialogHeader>
          <DialogTitle>Edit details</DialogTitle>
          <DialogDescription>
            Changes save to the contact and sync to LEAP.
          </DialogDescription>
        </DialogHeader>
        <DialogBody>
          <p className="text-body text-neutral-text-secondary">
            The {size} dialog is {{ sm: 448, md: 512, lg: 672, xl: 900 }[size]}{" "}
            px wide, and shrinks to the screen with 16 px either side.
          </p>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button intent="outline">Cancel</Button>} />
          <DialogClose render={<Button>Save</Button>} />
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
EnterSpaceOpen the dialog from its trigger.
TabMoves through the dialog in order, wrapping from the last element to the first.
Shift + TabFrom the first element, wraps to the last.
EscapeCloses it and returns focus to the trigger.