Modals
Modals allow you to display content on top of the current page. They are useful for displaying alerts, forms, or any other content that requires user interaction.
Use them sparingly though, as they can be disruptive to the flow of the user experience.
Components
Modals come in two flavours: the completely plain Modal and the TemplateModal, which provides some sensible defaults.
In most cases, you’ll want to use the TemplateModal.
TemplateModal
Example usage:
const [visible, setVisible] = useState(false);
return (
<>
<TemplateModal isOpen={visible} onDismiss={() => setVisible(false)} title="Example modal">
<p>Hello, world!</p>
</TemplateModal>
<Button onClick={() => setVisible(true)}>Open modal</Button>
</>
);Props:
isOpen: Whether the modal is visible or notonDismiss: A function to call when the modal is dismissedtitle: The title of the modalchildren: The content of the modalclassName: A custom class name to apply to the modalshowsDismissButton: Whether to show the dismiss button or not (defaults totrue)cancel: Cancel button text - don’t use together withshowsDismissButtonconfirm: Confirm button textconfirmationAction: A function to call when the confirm button is clicked
Modal
Simple wrapper around <Dialog> from @reach/dialog.
Props:
isOpen: Whether the modal is visible or notonDismiss: A function to call when the modal is dismissed
Also inherits all other props from @reach/dialog.
Modal.ExitButton
Close button for the modal. A small sub-component that can be used to close the modal.
Example usage:
<Modal.ExitButton onClick={dismissModal} />Props:
onClick: A function to call when the button is clickedclassName: A custom class name to apply to the button (optional)