Search

⌘K
Something

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.

ExampleCode
Click the button to test our 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 function closeModal unavailable.
  • unlockModal(): This function is used to unlock the modal. This will make the function closeModal available.
  • 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;
18

Content 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.
ExampleCode
Alert Modal


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

ExampleCode

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.

ExampleCode

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.

ExampleCode

Modal attribute

id
string
This is the id of the modal.
children
ReactNode (required)
The content of modal.
className
string
The styling of the modal.

Alert modal attribute

title
ReactNode (Require)
The title of the alert modal.
message
ReactNode (Require)
The message content of the alert modal.
confirmText
ReactNode
The text for the confirm button in the alert modal.
onConfirm
Function
Callback function triggered when the confirm button is clicked.
id
string
Optional unique identifier for the alert modal.
color
string
Optional color theme for the alert modal.
icon
ReactNode (Require)
The icon displayed in the alert modal.

Confirm modal attribute

title
ReactNode (Require)
The title of the confirm modal.
message
ReactNode (Require)
The message content of the confirm modal.
confirmText
ReactNode
The text for the confirm button in the confirm modal.
cancelText
ReactNode
The text for the cancel button in the confirm modal.
onConfirm
Function
Callback function triggered when the confirm button is clicked.
onCancel
Function
Callback function triggered when the cancel button is clicked.
id
string
Optional unique identifier for the confirm modal.
color
string
Optional color theme for the confirm modal.
icon
ReactNode (Require)
The icon displayed in the confirm modal.

Copyright 2025 by Prine Components