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>Footer
Buttons sit on the right. Use justify-between to split them.
tsx
<Dialog.Footer className="justify-between">
<Button onClick={remove}>
<Button.Label>delete</Button.Label>
</Button>
<Button active onClick={close}>
<Button.Label>done</Button.Label>
</Button>
</Dialog.Footer>Reference
Dialog, Dialog.Body and Dialog.Footer take the same props. Opening, closing and Escape come from Layer.
| prop | type | default | |
|---|---|---|---|
as? | ElementType | "div" | the element or component to render |
className? | string | — | added after the component's own class: what you set wins |
…rest | props of as | — | typed against the chosen element |