Components/Overlay

Modal

Modals are dialogs that open over the page and hold the reader’s attention until they are dealt with. They suit a task that has to be finished, or abandoned, before anything else can continue. Everything behind one waits, which makes a modal a demand on the reader rather than an offer.

import { Modal } from '@growth-protocol-ai/alpha';

On this page

width
state
Modal.tsxtsx
1import { Modal } from '@growth-protocol-ai/alpha';
2
3<>
4 <Button onClick={() => onOpenChange?.(true)}>Export data</Button>
5 <Modal
6 width="compact"
7 title="Export your data"
11 open={false}
12 onOpenChange={setOpen}
13 >
14 <ModalBody>
15 <p>
16 An export bundles everything your account owns into a single archive.
17 You will get an email when it is ready.
18 </p>
19 </ModalBody>
20 <ModalFooter>
21 <Button variant="secondary" onClick={() => onOpenChange?.(false)}>
22 Cancel
23 </Button>
24 <Button onClick={() => onOpenChange?.(false)}>Start export</Button>
25 </ModalFooter>
26 </Modal>
27</>

When to use

Reach for a modal when the next step has to happen before anything else does and the page behind it should wait. It suits a short task that finishes in one screen — a confirmation, a rename, a single form — where taking the page away is proportionate to what is being asked.

When not to use

Do not put content in a modal that is long enough to deserve its own address, because a reader cannot bookmark or share one. Never open a modal over a modal: a two-step flow is one dialog with a back step. A message the reader only has to see does not need to take the page away at all.

width3 values

Three widths, and the choice is what the content needs rather than how important the modal is. At compact and wide the height is never set: the dialog is as tall as its content until it runs out of viewport, and then the body scrolls. Large is the exception and takes the full viewport in both directions.

compact
wide
large
widthWhen to use
compactThe default. A confirmation, a rename, a handful of fields — anything that reads as one question.
wideRoom for two columns or a short table without cramping either.
largeA working surface: a picker, a preview, an editor. At this width, ask first whether it should be a page.