Dialog

The panel of a modal. Layer opens it; Dialog is what you see.

Usage

Put a Dialog inside a Layer, with a Header on top, a Dialog.Body and a Dialog.Footer. Every part is optional.

tsx
const { close, id, isActive, open } = useGraftDialog<void>();

<Layer open={isActive} onClose={close} aria-labelledby={id}>
  <Dialog className="max-w-lg">
    <Header className="border-b-margo border-border">
      <Header.Title id={id}>Delete invoice</Header.Title>
      <Header.Trailing>
        <Button aria-label="close" onClick={close}>
          <Button.Icon><MdClose /></Button.Icon>
        </Button>
      </Header.Trailing>
    </Header>
    <Dialog.Body>This cannot be undone.</Dialog.Body>
    <Dialog.Footer>
      <Button onClick={close}>
        <Button.Label>cancel</Button.Label>
      </Button>
    </Dialog.Footer>
  </Dialog>
</Layer>

Long content

The body scrolls; the header and the footer stay in place.

tsx
const { close, id, isActive, open } = useGraftDialog<void>();

<Layer open={isActive} onClose={close} aria-labelledby={id}>
  <Dialog className="max-w-lg">
    <Header className="border-b-margo border-border">
      <Header.Title id={id}>Delete invoice</Header.Title>
      <Header.Trailing>
        <Button aria-label="close" onClick={close}>
          <Button.Icon><MdClose /></Button.Icon>
        </Button>
      </Header.Trailing>
    </Header>
    <Dialog.Body>This cannot be undone.</Dialog.Body>
    <Dialog.Footer>
      <Button onClick={close}>
        <Button.Label>cancel</Button.Label>
      </Button>
    </Dialog.Footer>
  </Dialog>
</Layer>

Reference

Dialog, Dialog.Body and Dialog.Footer take the same props. Opening, closing and Escape come from Layer.

proptypedefault
as?ElementType"div"the element or component to render
className?string—added after the component's own class: what you set wins
…restprops of as—typed against the chosen element