Modal
A Modal Dialog is used to represent information that demands attention and/or action from the users, preventing them from interacting with the rest of the page. It follows the WAI-ARIA Dialog (Modal) Pattern.
Behavior
Modal is a compound component with the following composites:
Name | Description |
---|---|
ModalHeader | Modal header. Renders header element |
ModalContent | Content of the modal. Renders a section element |
ModalFooter | Modal footer. Renders a footer element |
ModalButton | Renders a admin-ui/Button |
function ModalDialog() {
const modal = useModalState()
return (
<Box>
<ModalDisclosure state={modal}>
<Button>Publish</Button>
</ModalDisclosure>
<Modal aria-label="Publish modal" state={modal} size="small">
<ModalHeader title="Publish content" />
<ModalContent>
<Text>
Are you sure you want to publish this content? This action cannot be
undone.
</Text>
</ModalContent>
<ModalFooter>
<Button variant="secondary">Cancel</Button>
<Button>Confirm</Button>
</ModalFooter>
</Modal>
</Box>
)
}
Examples
Sizes
The modal comes in three different sizes: small
, regular
, and large
.
Small
function SmallModal() {
const modal = useModalState()
return (
<Box>
<ModalDisclosure state={modal}>
<Button>Small</Button>
</ModalDisclosure>
<Modal aria-label="Small" state={modal} size="small">
<ModalHeader title="Small" />
<ModalContent>
<Text>Small Modal</Text>
</ModalContent>
<ModalFooter>
<Button>Confirm</Button>
</ModalFooter>
</Modal>
</Box>
)
}
Regular (default)
function RegularModal() {
const modal = useModalState()
return (
<Box>
<ModalDisclosure state={modal}>
<Button>Regular</Button>
</ModalDisclosure>
<Modal aria-label="Regular" state={modal}>
<ModalHeader title="Regular" />
<ModalContent>
<Text>Regular Modal</Text>
</ModalContent>
<ModalFooter>
<Button>Confirm</Button>
</ModalFooter>
</Modal>
</Box>
)
}
Large
function LargeModal() {
const modal = useModalState()
return (
<Box>
<ModalDisclosure state={modal}>
<Button>Large</Button>
</ModalDisclosure>
<Modal aria-label="Large" state={modal} size="large">
<ModalHeader title="Large" />
<ModalContent>
<Text>Large Modal</Text>
</ModalContent>
<ModalFooter>
<Button>Confirm</Button>
</ModalFooter>
</Modal>
</Box>
)
}