UI Components
Modal
Accessible dialog overlay with backdrop, ESC close, body scroll lock, and composable sub-components
Quick Preview
Installation
// Copy the Modal component fromsrc/components/ui/Modal.tsx
Usage
'use client'import { useState } from 'react'import { Modal, ModalHeader, ModalBody, ModalFooter } from '@/components/ui/Modal'import { Button } from '@/components/ui/Button'export default function Example() {const [open, setOpen] = useState(false)return (<><Button onClick={() => setOpen(true)}>Open Modal</Button><Modal isOpen={open} onClose={() => setOpen(false)}><ModalHeader><h2 className="text-lg font-semibold">Title</h2></ModalHeader><ModalBody><p className="text-gray-600 text-sm">Modal content goes here.</p></ModalBody><ModalFooter><Button variant="ghost" onClick={() => setOpen(false)}>Cancel</Button><Button onClick={() => setOpen(false)}>Confirm</Button></ModalFooter></Modal></>)}
Examples
Confirm / Destructive Dialog
Size Variants
Prompt Preview
Copy a prompt that recreates this UI
Paste this into your AI coding assistant to generate code that closely matches the reference, including color, size, shape, typography, spacing, and polish.
Copy-ready AI prompt
Starts from the current visual reference and project constraints.
Tweak only product-specific copy or data after the first generation pass.
Props
Sub-components ModalHeader, ModalBody, and ModalFooter accept children and className.
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen* | boolean | - | Controls dialog visibility |
onClose* | () => void | - | Called when the modal should close |
size | "sm" | "md" | "lg" | "xl" | "full" | "md" | Dialog width preset |
closeOnBackdrop | boolean | true | Close when clicking the backdrop |
closeOnEsc | boolean | true | Close on Escape key press |
className | string | - | Additional CSS classes for the dialog panel |
Features
- โPortal rendering into document.body
- โESC key to close
- โBackdrop click to close
- โBody scroll lock when open
- โAuto-focuses close button on open
- โModalHeader / ModalBody / ModalFooter sub-components
- โaria-modal + role="dialog"
- โFive size presets
- โClient Component