Open History to see the last commit
1import * as React from 'react'
2import * as DialogPrimitive from '@radix-ui/react-dialog'
3import { XIcon } from 'lucide-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 hideCloseButton,
51 ...props
52}: React.ComponentProps<typeof DialogPrimitive.Content> & {
53 hideCloseButton?: boolean
54}) {
55 return (
56 <DialogPortal data-slot="dialog-portal">
57 <DialogOverlay />
58 <DialogPrimitive.Content
59 data-slot="dialog-content"
60 className={cn(
61 '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 p-6 shadow-lg duration-200 sm:max-w-lg bg-opacity-70 backdrop-blur-md border-3 border-white/20',
62 className,
63 )}
64 {...props}
65 >
66 {children}
67 {!hideCloseButton && (
68 <DialogPrimitive.Close 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">
69 <XIcon />
70 <span className="sr-only">Close</span>
71 </DialogPrimitive.Close>
72 )}
73 </DialogPrimitive.Content>
74 </DialogPortal>
75 )
76}
77
78function DialogHeader({ className, ...props }: React.ComponentProps<'div'>) {
79 return (
80 <div
81 data-slot="dialog-header"
82 className={cn('flex flex-col gap-2 text-center sm:text-left', className)}
83 {...props}
84 />
85 )
86}
87
88function DialogFooter({ className, ...props }: React.ComponentProps<'div'>) {
89 return (
90 <div
91 data-slot="dialog-footer"
92 className={cn(
93 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end',
94 className,
95 )}
96 {...props}
97 />
98 )
99}
100
101function DialogTitle({
102 className,
103 ...props
104}: React.ComponentProps<typeof DialogPrimitive.Title>) {
105 return (
106 <DialogPrimitive.Title
107 data-slot="dialog-title"
108 className={cn('text-lg leading-none font-semibold', className)}
109 {...props}
110 />
111 )
112}
113
114function DialogDescription({
115 className,
116 ...props
117}: React.ComponentProps<typeof DialogPrimitive.Description>) {
118 return (
119 <DialogPrimitive.Description
120 data-slot="dialog-description"
121 className={cn('text-muted-foreground text-sm', className)}
122 {...props}
123 />
124 )
125}
126
127export {
128 Dialog,
129 DialogClose,
130 DialogContent,
131 DialogDescription,
132 DialogFooter,
133 DialogHeader,
134 DialogOverlay,
135 DialogPortal,
136 DialogTitle,
137 DialogTrigger,
138}