Dialog
This component is an overlay that requires the users to interact
Basic Usage
import { Dialog } from '@krakentech/coral/atoms';
<Button onClick={() => setOpen(true)}>Open dialog</Button>
<Dialog
ariaLabelledBy="dialog-title"
open={open}
onClose={() => setOpen(false)}
>
<Stack flexDirection="column" gap="smMd">
<Typography textStyle="h3" id="dialog-title">
Dialog title
</Typography>
<Typography>
Dialog content Cupidatat duis officia laborum pariatur
officia pariatur cupidatat proident id qui anim. Tempor
dolore in non mollit incididunt quis eu. Dolor nulla
cupidatat ea nisi commodo ut fugiat velit commodo est.
Amet officia tempor magna eu reprehenderit dolore est
laboris in ipsum ipsum nisi enim.
</Typography>
<Stack gap="smMd">
<Button
variant="outlined"
onClick={() => setOpen(false)}
>
Close
</Button>
<Button onClick={() => setOpen(false)}>Action</Button>
</Stack>
</Stack>
</Dialog>Properties
disableEscapeKeyDown
const [open, setOpen] = useState(false);
<Button onClick={setOpen(true)}>Open dialog</Button>
<Dialog
ariaLabelledBy="title"
onClose={() => setOpen(false)}
open={open}
disableEscapeKeyDown
>
<Typography id="title">Dialog title ...</Typography>
</Dialog>dialogWidth
const [open, setOpen] = useState(false);
<Button onClick={setOpen(true)}>Open dialog</Button>
<Dialog
ariaLabelledBy="title"
onClose={() => setOpen(false)}
open={open}
dialogWidth="md"
>
<Typography id="title">Dialog title ...</Typography>
</Dialog>Event Handlers
<Dialog
ariaLabelledBy="title"
onClose={() => {}}
>
...
</Dialog>Responsiveness
const [open, setOpen] = useState(false);
<Button onClick={setOpen(true)}>Open dialog</Button>
<Dialog
ariaLabelledBy="title"
onClose={() => setOpen(false)}
open={open}
dialogWidth={{ base: "xs", lg: "md" }}
>
<Typography id="title">Dialog title ...</Typography>
</Dialog>Full API
Design
Good to know
Only use a dialog modal when absolutely necessary.
A modal interrupts a users journey in order to grab their attention. It sits on top of a main window, disabling the main window until interacted with, while still keeping it partly visible.
Last updated on