Dialog
Base UI dialog in the house chrome: card panel, hairline border, quiet rise.
src/components/ui/dialog.tsx
"use client";
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
function Dialog(props: DialogPrimitive.Root.Props) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
}
function DialogTrigger(props: DialogPrimitive.Trigger.Props) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
}
function DialogPortal(props: DialogPrimitive.Portal.Props) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
}
function DialogClose(props: DialogPrimitive.Close.Props) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
}
function DialogOverlay({
className,
...props
}: DialogPrimitive.Backdrop.Props) {
return (
<DialogPrimitive.Backdrop
className={cn(
"fade-in-0 fixed inset-0 z-50 animate-in bg-black/60 duration-200 motion-reduce:animate-none",
className
)}
data-slot="dialog-overlay"
{...props}
/>
);
}
function DialogContent({
children,
className,
...props
}: DialogPrimitive.Popup.Props) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Popup
className={cn(
"fade-in-0 slide-in-from-bottom-2 fixed top-1/2 left-1/2 z-50 grid w-full max-w-md translate-x-[-50%] translate-y-[-50%] animate-in gap-4 rounded-lg border border-border/60 bg-card p-6 duration-300 motion-reduce:animate-none",
className
)}
data-slot="dialog-content"
{...props}
>
{children}
</DialogPrimitive.Popup>
</DialogPortal>
);
}
function DialogHeader({ className, ...props }: ComponentProps<"div">) {
return (
<div
className={cn("flex flex-col gap-1.5", className)}
data-slot="dialog-header"
{...props}
/>
);
}
function DialogFooter({ className, ...props }: ComponentProps<"div">) {
return (
<div
className={cn("flex justify-end gap-2", className)}
data-slot="dialog-footer"
{...props}
/>
);
}
function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
return (
<DialogPrimitive.Title
className={cn(
"text-balance font-semibold text-foreground text-lg tracking-tight",
className
)}
data-slot="dialog-title"
{...props}
/>
);
}
function DialogDescription({
className,
...props
}: DialogPrimitive.Description.Props) {
return (
<DialogPrimitive.Description
className={cn("text-pretty text-muted-foreground text-sm", className)}
data-slot="dialog-description"
{...props}
/>
);
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
};
- Interaction
- modal
DependenciesBundle weight · light
- ui-primitives
- @base-ui/react