Dialog
This component is an overlay that requires the users to interact
Basic Usage
import { Dialog } from '@krakentech/coral';
<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.
Customisation
Our dialog modal has many variations you can play with. What you see to the right is the component with all properties turned on. When you are using this component in your designs you can customise it used the right hand panel to toggle the following features off and on.
- Action buttons
- An alert
- Dismiss action
You can also remove the alert if it isn’t required for your design. All of the toggle features mean they aren’t mandatory, leaving the the simplest form the dialog can take being text only.
However there should always be a way to close the modal and allow the user to continue their journey so you must either have action buttons or the dismiss action toggled on.
Component breakdown
- Corner radius: 12px
- Outline: 2px
- Outline colour: Voltage
- Fill: Hemocyanin
- Text: H3 & Body text 1
- Text colour: Ice
- Item padding: 20px (spacing-sm-md)
- Horizontal padding: 28px
- Vertical padding: 32px