Components
Loading preview...
Accessible dialog overlay for focused user interactions, with sizes, placement, dismiss control, and controlled state.
npx shadcn@latest add https://21st.dev/r/hero_ui/heroui-modal"use client"
import { CheckCircle } from "lucide-react"
import { Button, Modal, useOverlayState } from "@/components/ui/heroui-modal"
export default function Demo() {
const state = useOverlayState()
return (
<div className="flex max-w-md flex-col gap-3">
<h3 className="text-lg font-semibold text-foreground">With useOverlayState()</h3>
<p className="text-sm leading-relaxed text-pretty text-muted">
Use the <code className="text-foreground">useOverlayState</code> hook for a cleaner API with
convenient methods like <code>open()</code>, <code>close()</code>, and <code>toggle()</code>.
</p>
<div className="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm">
<div className="flex w-full items-center justify-between">
<p className="text-xs text-muted">
Status:{" "}
<span className="font-mono font-medium text-foreground">
{state.isOpen ? "open" : "closed"}
</span>
</p>
</div>
<div className="flex gap-2">
<Button size="sm" variant="secondary" onPress={state.open}>
Open Modal
</Button>
<Button size="sm" variant="tertiary" onPress={state.toggle}>
Toggle
</Button>
</div>
</div>
<Modal.Backdrop isOpen={state.isOpen} onOpenChange={state.setOpen}>
<Modal.Container>
<Modal.Dialog className="sm:max-w-[360px]">
<Modal.CloseTrigger />
<Modal.Header>
<Modal.Icon className="bg-success-soft text-success-soft-foreground">
<CheckCircle className="size-5" />
</Modal.Icon>
<Modal.Heading>Controlled with useOverlayState()</Modal.Heading>
</Modal.Header>
<Modal.Body>
<p>
The <code>useOverlayState</code> hook provides dedicated methods for common
operations. No need to manually create callbacks—just use <code>state.open()</code>,{" "}
<code>state.close()</code>, or <code>state.toggle()</code>.
</p>
</Modal.Body>
<Modal.Footer>
<Button slot="close" variant="secondary">
Cancel
</Button>
<Button slot="close">Confirm</Button>
</Modal.Footer>
</Modal.Dialog>
</Modal.Container>
</Modal.Backdrop>
</div>
)
}