Dialog
A modal dialog component for displaying content.
Follow the installation and quick start below to use Dialog in your project, or read the complete setup guide.
On this page
Installation
1. Initialize once
Run from an existing React project with Node.js 18 or later. Skip this step if the project already has u-lib.json. Initialization copies the shared stylesheet and adds its import to your application entry.
npx @scriptwithahmad/u-lib@0.2.2 init2. Add Dialog and example components
This command includes the UI components used by this page's usage examples. The CLI copies editable source into your components directory and installs each component's dependencies. Existing source files are preserved.
npx @scriptwithahmad/u-lib@0.2.2 add dialog button3. Install example dependencies
These packages are imported directly by the examples. Some may already have been installed by the CLI.
npm install lucide-reactChoose the tab for your package manager. Yarn commands require modern Yarn; Yarn Classic users can use npx. Use --dry-run to preview changes. See the installation guide for custom paths, JavaScript output and package-import alternatives.
Quick start
Copy this example into src/Example.tsx (or Example.tsx at the project root when you do not use src). Imports assume the default CLI paths. From a nested file such as src/app/page.tsx, adjust ./components to ../components. Keep the client directive in Next.js when using state or event handlers.
"use client";
import { Button } from "./components/ui/button";
import { ArrowRight, MessageSquare } from "lucide-react";
import {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
DialogClose,
} from "./components/ui/dialog";
const DialogUi = () => {
return (
<div className="flex flex-wrap items-center justify-center gap-3">
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Open default dialog</Button>
</DialogTrigger>
<DialogContent animated intensity={0.65} duration={220}>
<DialogHeader>
<DialogTitle>Confirmation</DialogTitle>
<DialogDescription>
Are you sure you want to perform this action? This action cannot be
undone.
</DialogDescription>
</DialogHeader>
<p>This is a customizable content area for the dialog.</p>
<DialogFooter className="gap-2 sm:space-x-0">
<DialogClose asChild><Button variant="outline">Cancel</Button></DialogClose>
<DialogClose asChild><Button>Confirm</Button></DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
<Dialog>
<DialogTrigger asChild>
<Button>Open card dialog</Button>
</DialogTrigger>
<DialogContent variant="card" animated intensity={0.65} duration={220}>
<DialogHeader className="space-y-4 text-left">
<div className="flex h-10 w-10 items-center justify-center rounded-xl border bg-muted/30 text-primary" aria-hidden="true">
<MessageSquare className="h-5 w-5" />
</div>
<DialogTitle className="pr-3 text-2xl leading-tight sm:text-[30px]">A little clarity goes a long way.</DialogTitle>
<DialogDescription className="leading-6">
This is a component preview. Try navigating with Tab, confirm the
demo, or press Escape to return to the gallery.
</DialogDescription>
</DialogHeader>
<DialogFooter className="gap-2 sm:space-x-0">
<DialogClose asChild><Button variant="outline">Cancel</Button></DialogClose>
<DialogClose asChild><Button>Confirm demo <ArrowRight className="ml-2 h-4 w-4" aria-hidden="true" /></Button></DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
};
export default DialogUi;Keep DialogTitle and DialogDescription inside DialogContent so the dialog has an accessible name and description. Use asChild when the trigger is already a button.
Keep the shared stylesheet imported once. Replace sample image URLs and data with your own. Examples may use layout utilities beyond the precompiled component styles; compile added Tailwind classes in your app or replace them with your own CSS. Customize local source or className, and preserve accessible names and keyboard behavior.
Usage examples
Try each example, then switch to Code to copy its complete implementation. These catalog snippets use the website's @/components/ui alias; replace it with your local generated path as shown in Quick start.
Basic Usage
A complete dialog example. Copy this into a client component.
Loading example…
Props & configuration
Everything you need to fine-tune this component.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "card" | default | DialogContent surface style. Card uses the shared rounded frame and a softer blurred overlay. |
open | boolean | — | Controlled dialog visibility. |
onOpenChange | (open: boolean) => void | — | Called when the dialog opens or closes. |
defaultOpen | boolean | false | Initial visibility in uncontrolled mode. |
