Search
Modal
Modal is a component that provides a modal dialog. It is used to display information or to ask for user input. It can also display a data in a quick way. We seperate the modal into two 3 parts.
- Modal provider: This is the context provider for the modal component. It is used to manage the state of the modal and styling the modal component.
- Modal: This is the component that is used to display the modal box.
- Ready made modal: This is the component that is used to display the modal box with a ready made layout. Such as AlertModal or ConfirmModal.
This components. Store at src/components/atoms/modal and src/components/molecules/modal
Basic example
This is an example of how to use the modal provider trough the useModal. And the modal component. The modal provider is used to manage the state of the modal.
Provider
The ModalProvider is a context provider that is used to manage the state of the modal. It is used to open and close the modal. The provider is used to wrap the application in the layout.tsx file.
To use the provider you must use the useModal hook . The hook will return 4 function and 2 variable. The function are
openModal(React.ReactNode): This function is used to open the moal. It will take a component as a parameter. The component will be rendered on the screen.closeModal(): This function is used to close the modal. No parameter needed.isModalOpen: This variable is used to check if the modal is open or not. It will return a boolean value.lockModal(): This function is used to lock the banner. This will make the functioncloseModalunavailable.unlockModal(): This function is used to unlock the modal. This will make the functioncloseModalavailable.isModalLocked: This variable is used to check if the modal is locked or not. It will return a boolean value.
1// Call hook
2const {
3 openModal,
4 closeModal,
5 isModalOpen,
6 lockModal,
7 unlockModal,
8 isModalLock,
9} = useModal();
10
11// Usage
12openModal(Your Component ...);
13closeModal();
14lockModal();
15unlockModal();
16isModalOpen;
17isModalLock;
18Content and message
In the AlertModal and ConfirmModal you have to pass the content via.
- Title: This is the title of the alert and confirm.
- Message: The real part of the content. Message you want to tell users.
- icon: Icon that related to the content.
Alert
This is an example of how to use the alert modal.
Confirm
This is an example of how to use the confirm modal.
Color
You can set the color of the modal by using the color prop. You can find the allow color at Color guideline
Alert
This is an example of how to use the alert modal.
Alert
This is an example of how to use the alert modal.
Alert
This is an example of how to use the alert modal.
Action
You can set the action of the AlertModal and ConfirmModal. There are a little different beteen them but not much. You can custom the action text via confirmText and in confirmModal you can set cancelText too.
Also the action will use the simillar name as the text you can add the action via onConfirm and in confirmModal you can set onCancel too.
Please confirm
This is an example of how to use the action on the modal.
Confirm status : False
Lock and Unlock
The lock and unlock function is used to prevent the modal from being closed when the user clicks outside of it. This is useful when you want to keep the banner open until the user explicitly closes it.
If you use the lock function do not use the close function in the modal component.
Modal attribute
idstring- This is the id of the modal.
childrenReactNode (required)- The content of modal.
classNamestring- The styling of the modal.
Alert modal attribute
titleReactNode (Require)- The title of the alert modal.
messageReactNode (Require)- The message content of the alert modal.
confirmTextReactNode- The text for the confirm button in the alert modal.
onConfirmFunction- Callback function triggered when the confirm button is clicked.
idstring- Optional unique identifier for the alert modal.
colorstring- Optional color theme for the alert modal.
iconReactNode (Require)- The icon displayed in the alert modal.
Confirm modal attribute
titleReactNode (Require)- The title of the confirm modal.
messageReactNode (Require)- The message content of the confirm modal.
confirmTextReactNode- The text for the confirm button in the confirm modal.
cancelTextReactNode- The text for the cancel button in the confirm modal.
onConfirmFunction- Callback function triggered when the confirm button is clicked.
onCancelFunction- Callback function triggered when the cancel button is clicked.
idstring- Optional unique identifier for the confirm modal.
colorstring- Optional color theme for the confirm modal.
iconReactNode (Require)- The icon displayed in the confirm modal.
Copyright 2025 by Prine Components