Overlays
Modal & Drawer
Shared header and footer parts. Modal is 560px wide; drawer is 480px wide, full height, docked right.
react-aria-componentslucide-react
Modal
"use client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { DialogTrigger, Modal } from "@/components/ui/modal";
import { Textarea } from "@/components/ui/textarea";
export default function Example() {
return (
<DialogTrigger>
<Button variant="primary">Create list</Button>
<Modal
title="Create list"
description="Group prospects you want to work together."
footerNote="128 prospects selected"
footer={(close) => (
<>
<Button size="sm" onPress={close}>Cancel</Button>
<Button size="sm" variant="primary" onPress={close}>Create list</Button>
</>
)}
>
<div className="flex flex-col gap-4">
<Input label="Name" placeholder="Series B — VP Sales" autoFocus />
<Textarea label="Description" placeholder="What is this list for?" rows={3} />
</div>
</Modal>
</DialogTrigger>
);
}Drawer
"use client";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { DialogTrigger, Modal } from "@/components/ui/modal";
import { Select, SelectItem } from "@/components/ui/select";
export default function Example() {
return (
<DialogTrigger>
<Button>Open filters</Button>
<Modal
variant="drawer"
title="Filters"
description="3 active · 128 results"
footerNote={<button className="font-medium text-fg">Reset all</button>}
footer={(close) => (
<>
<Button size="sm" onPress={close}>Cancel</Button>
<Button size="sm" variant="primary" onPress={close}>Show 128 results</Button>
</>
)}
>
<div className="flex flex-col gap-5">
<Select label="Seniority" defaultSelectedKey="vp">
<SelectItem id="vp">VP</SelectItem>
<SelectItem id="director">Director</SelectItem>
<SelectItem id="head">Head of</SelectItem>
</Select>
<Checkbox defaultSelected>Verified emails only</Checkbox>
<Checkbox defaultSelected>Raised funding in the last 6 months</Checkbox>
</div>
</Modal>
</DialogTrigger>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
modal.tsxfile and paste the following code into it.src/components/ui/modal.tsx"use client"; import { X } from "lucide-react"; import type { ReactNode } from "react"; import { Button as AriaButton, Dialog, DialogTrigger, Heading, Modal as AriaModal, ModalOverlay, type ModalOverlayProps, } from "react-aria-components"; import { cx } from "@/utils/cx"; export { DialogTrigger }; export interface ModalProps extends Omit<ModalOverlayProps, "children" | "className"> { title: string; description?: string; /** Footer content, typically secondary + primary buttons. Receives `close`. */ footer?: (close: () => void) => ReactNode; /** Left side of the footer, e.g. "128 prospects selected". */ footerNote?: ReactNode; /** `modal` is 560px centered; `drawer` is 480px full-height docked right. */ variant?: "modal" | "drawer"; children?: ReactNode; } /** Shared header/footer parts for dialogs and drawers. */ export function Modal({ title, description, footer, footerNote, variant = "modal", children, ...props }: ModalProps) { const drawer = variant === "drawer"; return ( <ModalOverlay {...props} isDismissable className={cx( "fixed inset-0 z-50 flex bg-inverse/30 backdrop-blur-[1px]", drawer ? "justify-end" : "items-center justify-center p-4", )} > <AriaModal className={cx( "flex flex-col bg-surface shadow-popover outline-none", drawer ? "h-full w-full max-w-[480px]" : "max-h-[85vh] w-full max-w-[560px] rounded-lg", )} > <Dialog className="flex min-h-0 flex-1 flex-col outline-none"> {({ close }) => ( <> <header className="flex items-start gap-3 border-b border-line px-5 py-4"> <div className="min-w-0 flex-1"> <Heading slot="title" className="text-lg font-medium text-fg"> {title} </Heading> {description && <p className="mt-0.5 text-sm text-fg-muted">{description}</p>} </div> <AriaButton aria-label="Close" onPress={close} className="inline-flex size-8 items-center justify-center rounded-sm text-fg-muted shadow-button outline-none data-hovered:bg-subtle data-hovered:text-fg data-focus-visible:shadow-focus" > <X className="size-4" /> </AriaButton> </header> <div className="min-h-0 flex-1 overflow-auto px-5 py-4">{children}</div> {footer && ( <footer className="flex items-center gap-3 border-t border-line bg-subtle px-5 py-3 [border-bottom-left-radius:inherit] [border-bottom-right-radius:inherit]"> <div className="flex-1 text-sm text-fg-muted">{footerNote}</div> {footer(close)} </footer> )} </> )} </Dialog> </AriaModal> </ModalOverlay> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | — | Dialog heading. |
| description | string | — | Line under the title. |
| variant | "modal" | "drawer" | "modal" | Layout. |
| footer | (close) => ReactNode | — | Footer actions. |
| footerNote | ReactNode | — | Left side of the footer. |