Skip to main content

Modal

The Modal component displays a modal dialog box over the content, providing a way to present information or receive input from the user. It includes options to customize its behavior and appearance.

Props

PropTypeDefaultDescription
isOpenbooleanRequiredDetermines whether the modal is open or closed.
onClose() => voidRequiredCallback function to handle closing the modal.
childrenReactNodeRequiredContent to be displayed inside the modal.
preventCancelOnOverlaybooleanfalsePrevents closing the modal when clicking outside the dialog content.
showFooterbooleanfalseDetermines whether to show the footer with buttons in the modal.
onOk() => void-Optional callback function to handle the "Ok" button click event. Only applicable if showFooter is true.
sizeModalSizeModalSize.MediumSpecifies the size of the modal. Available options are ModalSize.Medium, ModalSize.Small, ModalSize.Large, and ModalSize.XLarge.

Example Usage

import React, { useState } from 'react';
import { ModalSize, Modal, ModalHeader, ModalBody } from '@ginger-society/ginger-ui';

const ExampleModal = () => {
const [isOpen, setIsOpen] = useState(false);

const handleOpenModal = () => {
setIsOpen(true);
};

const handleCloseModal = () => {
setIsOpen(false);
};

return (
<>
<button onClick={handleOpenModal}>Open Modal</button>
<Modal isOpen={isOpen} onClose={handleCloseModal} size={ModalSize.Large} preventCancelOnOverlay>
<ModalHeader>Hello world</ModalHeader>
<ModalBody>
<p>
A Lorem ipsum dolor sit amet consectetur adipisicing elit. Nisi cum
sint eius voluptas itaque obcaecati, totam ratione earum ullam
eligendi officiis ipsum possimus sit quas accusantium voluptatibus
natus voluptatum aperiam?
</p>
</ModalBody>
</Modal>
</>
);
};

export default ExampleModal;

Demo

In the above example, isOpen controls the modal's visibility, onClose handles modal close events, size determines the modal's size.