Documentation
Components
Modal

Modal

Props

PropTypeDefaultRequired
variant"primary" | "secondary" | "tertiary" | "default" | "warning""default"yesstyle of the modal
openbooleanfalseyesthe state to open the modal
setOpenSetStateAction<boolean>noneyesthe state action to open the modal
modalTitlestring""notitle of the modal
modalActionsArray[ ]nobuttons at the bottom of the modal
modalImageReactNode<></>noimage inside the modal
modalDraggablebooleanfalsenodraggable modal
modalCloseButtonbooleantruenoshows/hides the close button
outsideClickClosebooleanfalsenocloses the modal when clicking outside
dangerbooleanfalsenodisplays danger animation
classNamestring""noset additional classNames

Importing Modal

import { Modal } from "cerberusui"

Open/Close Modal

Use the useState hook in your component and pass it to the Modal component

const [open, setOpen] = useState(false);
 
return (
    <>
        <Button onClick={() => setOpen(true)} variant="primary">Open Modal</Button>
        <Modal open={open} setOpen={setOpen} variant="default">
            <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
        </Modal>
    </>
)

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

ℹ️

Important For readability reasons the open and setOpen props aren't included in the other code examples

Variants

<Modal modalTitle="Default Modal" variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Default Modal

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Options

Title

<Modal 
    modalTitle="Default Modal with Title"
    variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Default Modal with Title

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Image

The modalImage prop displayes the passed image on the left side of the image.

When the viewport gets to small the images display is set to display: none;.

<Modal 
    modalTitle="Default Modal with Icon"
    modalImage={
        <img src="https://example.com/your-image.png" />
    } 
    variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Default Modal with Icon

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Actions

Inside the modalActions Array you can define buttons which will be displayed at the bottom right corner of the modal.

For each action you can define an action which has the type Function, an actionTitle which has the type string and an actionVariant which uses the variants from the Button Component.

<Modal 
    modalTitle="Default Modal with Actions"
    modalActions={[{
        action: () => alert("modal alert"),
        actionTitle: "Alert",
        actionVariant: "warning"
    }, {
        action: () => setOpen(false),
        actionTitle: "Close",
        actionVariant: "secondary"
    }]}
    variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Default Modal with Actions

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Without Close Button

When this option is set to false the default close button doesn't show up.

Make sure to implement an alternative closing button like shown in #Actions or enable outsideClickClose.

<Modal 
    modalTitle="Default Modal without Close Button"
    modalCloseButton={false}
    variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Default Modal without Close Button

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Close on Outside Click

<Modal 
    modalTitle="This Modal closes when clicked outside"
    outsideClickClose={true}
    modalCloseButton={false} // this is optional
    variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

This Modal closes when clicked outside

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Danger

<Modal 
    modalTitle="Danger Modal"
    danger={true}
    variant="warning">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Danger Modal

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Combined

<Modal 
    modalTitle="Combined Modal"
    modalActions={[{
        action: () => alert("modal alert"),
        actionTitle: "Alert",
        actionVariant: "warning"
    }, {
        action: () => setOpen(false),
        actionTitle: "Close",
        actionVariant: "secondary"
    }]}
    modalImage={
        <img src="https://example.com/your-image.png" />
    } 
    danger={true}
    outsideClickClose={true}
    modalCloseButton={false}
    variant="warning">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Combined Modal

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.

Draggable

The modal uses the package react-draggable (opens in a new tab) to move the modal around.

<Modal
    modalTitle="Default Modal Draggable"
    modalDraggable={true}
    variant="default">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.</p>
</Modal>

Default Modal Draggable

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda, reprehenderit.