Modal
Pop up a dialog box, demanding attention like a traffic stop sign, ideal for critical interactions..
Basic
A modal is a pop-up window that demands your attention. You have to deal with it before doing anything else on the page.
Installation
Alert Dialog
Alert dialogs are meant to interrupt the user with a critical message, so use 'em only when it's absolutely necessary. The fix? Set the role to alertdialog
, and you're golden.
Notice how the modal is dismissable and the close button is hidden? That's 'cause the role is set to
alertdialog
.
Controlled
You can control the modal programmatically.
Sizes
The modal is set to lg
by default. You can adjust it to any size from the available options.
Blur
If you want to blur the background, you can use isBlurred
prop.
Sticky
You can use the Modal.Body
component to make the modal sticky.
Nested
You can also nest modals. Try open it and confirm!
Header
This setup’s super flexible. If you skip adding ModalTitle
and just drop a string as its child, it'll auto-render as the title. Like this:
Wanna customize more? Throw in props like title
and description
for a tailored header:
Custom Styles
To apply custom styles such as background colors or borders to the header, follow this guide:
Class Names
To add custom class names to your content or overlay, refer to this demonstration:
Triggered By Menu
You can also trigger the modal by clicking on a menu item.
It might be a good idea to extract the modal into a separate component for better organization.
Then you can use it like this.
With that, now we can modify the actionType
function to return the initial state.