Modal
A dialog component with backdrop, keyboard support, and composable sub-components.
PREVIEW
Click the buttons below to trigger a modal.
INSTALLATION
bash
# Required
npm install @kennbalino/kui
# Optional — only if you want to use CVA, cn(), or lucide icons directly
npm install class-variance-authority clsx tailwind-merge lucide-reactUSAGE
tsx
"use client";
import { useState } from "react";
import { Button } from "@kennbalino/kui";
import {
Modal,
ModalHeader,
ModalTitle,
ModalDescription,
ModalContent,
ModalFooter,
} from "@kennbalino/kui";
export default function MyComponent() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Open Modal</Button>
<Modal open={open} onClose={() => setOpen(false)}>
<ModalHeader onClose={() => setOpen(false)}>
<ModalTitle>Modal Title</ModalTitle>
<ModalDescription>Optional description here.</ModalDescription>
</ModalHeader>
<ModalContent>
Your content goes here.
</ModalContent>
<ModalFooter>
<Button variant="ghost" onClick={() => setOpen(false)}>Cancel</Button>
<Button onClick={() => setOpen(false)}>Confirm</Button>
</ModalFooter>
</Modal>
</>
);
}
// Sizes
<Modal size="sm">Modal 1</Modal>
<Modal size="md">Modal 2</Modal> // default
<Modal size="lg">Modal 3</Modal>
<Modal size="xl">Modal 4</Modal>
// Disable backdrop close
<Modal open={open} onClose={onClose} closeOnBackdrop={false}>
Modal 5
</Modal>PROPS
| Prop | Type | Default | Description |
|---|---|---|---|
| open* | boolean | — | Controls whether the modal is visible. |
| onClose* | () => void | — | Callback fired when the modal is closed. |
| size | sm | md | lg | xl | full | md | Controls the max width of the modal. |
| closeOnBackdrop | boolean | true | Whether clicking the backdrop closes the modal. |
| className | string | — | Additional CSS classes to apply. |
| children* | ReactNode | — | Content rendered inside the modal. |