Open History to see the last commit
1import * as DialogPrimitive from "@radix-ui/react-dialog";
2import { XIcon } from "lucide-react";
3import type * as React from "react";
4
5import { cn } from "@/lib/utils";
6
7function Dialog({
8 ...props
9}: React.ComponentProps<typeof DialogPrimitive.Root>) {
10 return <DialogPrimitive.Root data-slot="dialog" {...props} />;
11}
12
13function DialogTrigger({
14 ...props
15}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
16 return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
17}
18
19function DialogPortal({
20 ...props
21}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
22 return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
23}
24
25function DialogClose({
26 ...props
27}: React.ComponentProps<typeof DialogPrimitive.Close>) {
28 return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
29}
30
31function DialogOverlay({
32 className,
33 ...props
34}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
35 return (
36 <DialogPrimitive.Overlay
37 data-slot="dialog-overlay"
38 className={cn(
39 "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
40 className,
41 )}
42 {...props}
43 />
44 );
45}
46
47function DialogContent({
48 className,
49 children,
50 showCloseButton = true,
51 ...props
52}: React.ComponentProps<typeof DialogPrimitive.Content> & {
53 showCloseButton?: boolean;
54}) {
55 return (
56 <DialogPortal data-slot="dialog-portal">
57 <DialogOverlay />
58 <DialogPrimitive.Content
59 onPointerDown={(e) => {
60 // NOTE: Without this, the edited draggable element is grabbed
61 e.stopPropagation();
62 }}
63 data-slot="dialog-content"
64 className={cn(
65 "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
66 className,
67 )}
68 {...props}
69 >
70 {children}
71 {showCloseButton && (
72 <DialogPrimitive.Close
73 data-slot="dialog-close"
74 className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
75 >
76 <XIcon />
77 <span className="sr-only">Close</span>
78 </DialogPrimitive.Close>
79 )}
80 </DialogPrimitive.Content>
81 </DialogPortal>
82 );
83}
84
85function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
86 return (
87 <div
88 data-slot="dialog-header"
89 className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
90 {...props}
91 />
92 );
93}
94
95function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
96 return (
97 <div
98 data-slot="dialog-footer"
99 className={cn(
100 "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
101 className,
102 )}
103 {...props}
104 />
105 );
106}
107
108function DialogTitle({
109 className,
110 ...props
111}: React.ComponentProps<typeof DialogPrimitive.Title>) {
112 return (
113 <DialogPrimitive.Title
114 data-slot="dialog-title"
115 className={cn("text-lg leading-none font-semibold", className)}
116 {...props}
117 />
118 );
119}
120
121function DialogDescription({
122 className,
123 ...props
124}: React.ComponentProps<typeof DialogPrimitive.Description>) {
125 return (
126 <DialogPrimitive.Description
127 data-slot="dialog-description"
128 className={cn("text-muted-foreground text-sm", className)}
129 {...props}
130 />
131 );
132}
133
134export {
135 Dialog,
136 DialogClose,
137 DialogContent,
138 DialogDescription,
139 DialogFooter,
140 DialogHeader,
141 DialogOverlay,
142 DialogPortal,
143 DialogTitle,
144 DialogTrigger,
145};