runway

Runway

Modal

A modal component for creating dialogs, popovers, and other overlays.



The Modal component renders its children in a modal overlay. It supports various props to customize its behavior, such as fade, blur, and closeOnOutsideClick.

You have to manage the isOpen state and the onClose function yourself.



Usage

The Modal component requires the isOpen and onClose props to control its visibility. We can use it like this:

javascript

1import Modal from "@/components/atoms/Modal";
2import { useState } from "react";
3import Button from "@/components/atoms/Button";
4
5export default function Example() {
6    const [open, setOpen] = useState(false);
7    const handleOpen = () => setOpen(true);
8    const handleClose = () => setOpen(false);
9
10    return (
11        <div>
12            <Button onClick={handleOpen}>Open Modal</Button>
13
14            <Modal
15                isOpen={open}
16                onClose={handleClose}
17            />
18                <div>
19                    Modal content goes here.
20                </div>
21            </Modal>
22        </div>
23    );
24}



Props

PropTypeDefaultDescription
childrenReactNode-The content to display inside the modal.
isOpenboolean-Whether the modal is open or closed.
onClosefunction-Function to call when the modal is closed.
fadebooleantrueWhether to fade the modal in and out.
blurbooleantrueWhether to blur the background when the modal is open.
closeOnOutsideClickbooleantrueWhether to close the modal when clicking outside of it.
showCloseButtonbooleantrueWhether to show the close button in the top right corner of the modal.
classNamestring""Additional Tailwind classes for the modal overlay (not the content).
...propsobject-Any other valid <div> attributes (e.g. role, aria-*, etc.).



Examples

Basic Modal

By default, the modal will both blur and fade the background.


Blurred Modal


Fade Modal