This library is still in development and is available only for internal usage at VTEX.
Skip to main content

Modal

Version: 0.132.0

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:

NameDescription
ModalHeaderModal header. Renders header element
ModalContentContent of the modal. Renders a section element
ModalFooterModal footer. Renders a footer element
ModalButtonRenders 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>
)
}