@hacline/ui/dialogDialog
A modal dialog built on @ui-sdk/react/dialog with multiple sizes and full-screen mode, placements, backdrop variants, sticky header/footer scrolling, responsive bottom sheets, and dismiss protection.
Imports
import {
Dialog,
DialogBackdrop,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/hacline/components/dialog";Basic Usage
Compose DialogTrigger and DialogClose with render={<Button />} to get focus trapping, backdrop click dismissal, Escape key dismissal, and automatic focus restoration out of the box.
import { Button } from "@/components/ui/hacline/components/button";
import {
Dialog,
DialogBackdrop,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/hacline/components/dialog";
export function DialogBasic() {
return (
<Dialog>
<DialogTrigger render={<Button />}>Open dialog</DialogTrigger>
<DialogBackdrop />
<DialogContent>
<DialogHeader>
<DialogTitle>Edit project details</DialogTitle>
<DialogDescription>
Updated settings sync immediately to the current workspace.
</DialogDescription>
</DialogHeader>
<DialogBody>Workspace ID: hacline-ui-workspace</DialogBody>
<DialogFooter>
<DialogClose render={<Button variant="outline" />}>
Cancel
</DialogClose>
<DialogClose render={<Button variant="primary" />}>
Save changes
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);
}Sizes
Switch dialog width presets via the size prop on DialogContent, supporting sm, md (default), lg, xl, and full for full-screen mode.
<Dialog>
<DialogTrigger render={<Button variant="outline" />}>
Full-screen dialog
</DialogTrigger>
<DialogBackdrop />
<DialogContent size="full">
<DialogHeader>
<DialogTitle>Full-screen dialog</DialogTitle>
<DialogDescription>
Ideal for complex forms, document previews, or large table editing.
</DialogDescription>
</DialogHeader>
<DialogBody>
The body area fills the remaining height and scrolls independently.
</DialogBody>
</DialogContent>
</Dialog>Placement Variants
Adjust where the dialog sits within the viewport using placement, supporting center (default), top (near the top, suitable for search bars or dynamic-height content), and bottom (bottom-aligned card).
<Dialog>
<DialogTrigger render={<Button variant="outline" />}>
Top dialog
</DialogTrigger>
<DialogBackdrop />
<DialogContent placement="top" size="sm">
<DialogHeader>
<DialogTitle>Top placement</DialogTitle>
<DialogDescription>
Prevents the dialog from jumping vertically when content height changes.
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>Backdrop Variants
Switch the background overlay style via the variant prop on DialogBackdrop: dim (default translucent dark), blur (frosted glass blur), or transparent (invisible backdrop).
<Dialog>
<DialogTrigger render={<Button variant="outline" />}>
Blur backdrop
</DialogTrigger>
<DialogBackdrop variant="blur" />
<DialogContent size="sm">
<DialogHeader>
<DialogTitle>Blur backdrop</DialogTitle>
<DialogDescription>
Enhances visual focus on the foreground dialog layer.
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>Scrollable Body with Sticky Header & Footer
Wrap long text or tall forms in DialogBody so DialogHeader and DialogFooter remain pinned while only the body area scrolls. Pair with initialFocus="content" to place initial keyboard focus directly at the top of the dialog content.
<Dialog>
<DialogTrigger render={<Button variant="outline" />}>
Read Terms of Service
</DialogTrigger>
<DialogBackdrop variant="blur" />
<DialogContent className="max-h-96" initialFocus="content">
<DialogHeader>
<DialogTitle>Terms of Service</DialogTitle>
<DialogDescription>
Please read completely before continuing.
</DialogDescription>
</DialogHeader>
<DialogBody className="space-y-3">{/* Long content */}</DialogBody>
<DialogFooter>
<DialogClose render={<Button variant="outline" />}>Decline</DialogClose>
<DialogClose render={<Button variant="primary" />}>
Agree & Continue
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>Bottom Sheet & Dismiss Protection
- Set
presentation="sheet"to render the dialog as a bottom sheet (or"auto"to automatically switch to a sheet on small touch devices while staying a dialog on large screens). - For high-risk confirmations, set
dismissible={false}to prevent accidental dismissal via backdrop clicks, Escape, or swipe gestures (useonDismissAttemptto listen for blocked dismiss attempts).
<Dialog presentation="sheet">
<DialogTrigger render={<Button variant="outline" />}>
Bottom sheet
</DialogTrigger>
<DialogBackdrop variant="blur" />
<DialogContent>
<DialogHeader>
<DialogTitle>Quick actions</DialogTitle>
</DialogHeader>
</DialogContent>
</Dialog>
<Dialog dismissible={false}>
<DialogTrigger render={<Button variant="danger" />}>
Confirm before closing
</DialogTrigger>
<DialogBackdrop variant="blur" />
<DialogContent size="sm">
<DialogHeader>
<DialogTitle>Delete project?</DialogTitle>
</DialogHeader>
</DialogContent>
</Dialog>Controlled Mode
Control dialog visibility externally with open and onOpenChange. When needed, call details.cancel() inside the callback to intercept dismissal.
"use client";
import { Button } from "@/components/ui/hacline/components/button";
import {
Dialog,
DialogBackdrop,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/hacline/components/dialog";
import { useState } from "react";
export function DialogControlled() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Open controlled dialog</Button>
<Dialog onOpenChange={setOpen} open={open}>
<DialogBackdrop />
<DialogContent size="sm">
<DialogHeader>
<DialogTitle>Controlled mode</DialogTitle>
<DialogDescription>
Open and close state is controlled externally.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose render={<Button variant="outline" />}>
Close
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}Props
Dialog
Prop
Type
DialogBackdrop
Prop
Type
DialogContent
Prop
Type
Data Attributes
| Attribute | Description |
|---|---|
data-slot="dialog-backdrop" / "dialog-content" | Element identifiers for backdrop and content |
data-open / data-closed | Dialog open or closed state |
data-presentation="dialog" | "sheet" | Actual active presentation mode |
data-starting-style / data-ending-style | Entering first-frame and exiting transition markers |