Modals manager
Centralized modals manager with option to handle state of multi-step modals
Source
LLM docs
Docs
Package
License
Installation
Setup ModalsProvider
Wrap your app with ModalsProvider component:
Confirm modal
The @mantine/modals package includes a special modal that can be used for confirmations.
The component includes confirm and cancel buttons and supports children to display additional
information about the action. Use the openConfirmModal function to open a confirm modal:
openConfirmModal function accepts one argument with the following properties:
modalId– modal id, defaults to a random id, can be used to close the modal programmaticallychildren– additional modal content displayed before actionsonCancel– called when the cancel button is clickedonConfirm– called when the confirm button is clickedcloseOnConfirm– should the modal be closed when the confirm button is clicked, defaults totruecloseOnCancel– should the modal be closed when the cancel button is clicked, defaults totruecancelProps– cancel button propsconfirmProps– confirm button propsgroupProps– buttons Group propslabels– cancel and confirm button labels, can be defined on ModalsProvider
Using these properties, you can customize the confirm modal to match current context requirements:
To set up shared labels for confirm modals, set labels on ModalsProvider:
Context modals
You can define any number of modals in the ModalsProvider context:
And then open one of these modals with the modals.openContextModal function.
The modals.openContextModal function accepts 2 arguments: modal key (should match one defined on ModalsProvider) and modal props:
Typesafe context modals
By default, innerProps and modal are not typesafe. You can add type safety with a TypeScript module declaration.
Type-safe context modals will force you to use the correct types for openContextModal:
Content modals
With the modals.open function, you can open a modal with any content:
Multiple opened modals
You can open multiple layers of modals. Every opened modal is added as the first element in the modals queue.
To close all opened modals, call the modals.closeAll() function:
Modal props
You can pass props down to the Modal component by adding them to the
argument of every modals.x function. Example of setting the radius, size, and withCloseButton
props:
Dynamic content and the modals manager
The modals manager allows you to dynamically update the content and properties of both standard and context modals after they are opened.
To update regular modals, use the modals.updateModal function:
Context modals can also be updated dynamically using modals.updateContextModal: