Skip to content

Modal

Overlay modal dialog component. Renders via createPortal to document.body.

Also known as: dialog, popup, overlay, lightbox, modal dialog

View in Storybook

When to use

  • Overlaying content that requires attention (forms, confirmations, details). For side panels, use Drawer.
  • For simple yes/no confirmations, use Confirmation.

Import

tsx
import { Modal } from '@vacano/ui'

Usage

tsx
const [open, setOpen] = useState(false)

<Button onClick={() => setOpen(true)}>Open Modal</Button>

<Modal open={open}>
  <h2>Modal Title</h2>
  <p>Modal content goes here.</p>
  <Button onClick={() => setOpen(false)}>Close</Button>
</Modal>

Custom Width

tsx
<Modal open={open} width="600px">
  <p>Wide modal content</p>
</Modal>

<Modal open={open} width="80%">
  <p>Percentage width modal</p>
</Modal>

Animated

tsx
<Modal open={open} animated>
  <p>This modal has fade-in animation</p>
</Modal>

Without Animation

tsx
<Modal open={open} animated={false}>
  <p>This modal appears instantly</p>
</Modal>

Props

PropTypeDefaultDescription
openbooleanrequiredControls whether the modal is visible
childrenReactNode-Modal content
widthstring'500px'Custom width of the modal content container
animatedbooleanfalseEnable fade-in animation for overlay and content
classNamestring-CSS class name applied to the content container
classnamesModalClassNames-Custom class names for sub-elements
refRef<HTMLDivElement>-Ref forwarded to the content container
data-test-idstring-Test identifier attribute

The component also accepts all standard HTMLDivElement attributes (except className which is overridden by the component prop).

ModalClassNames

KeyDescription
overlayBackground overlay that covers the viewport
contentModal content container

Released under the MIT License.