-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathdialog.tsx
More file actions
172 lines (159 loc) · 4.44 KB
/
Copy pathdialog.tsx
File metadata and controls
172 lines (159 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "../../lib/utils"
import { X } from "lucide-react"
const dialogVariants = cva(
"fixed inset-0 z-50 flex items-center justify-center",
{
variants: {
variant: {
default: "",
fullscreen: "p-0",
},
},
defaultVariants: {
variant: "default",
},
}
)
const overlayVariants = cva(
"fixed inset-0 bg-black/50 backdrop-blur-sm transition-opacity",
{
variants: {
variant: {
default: "",
fullscreen: "bg-black/80",
},
},
defaultVariants: {
variant: "default",
},
}
)
const contentVariants = cva(
"relative bg-white rounded-lg shadow-lg max-h-[90vh] overflow-hidden",
{
variants: {
variant: {
default: "w-full max-w-md mx-4",
fullscreen: "w-full h-full max-w-none mx-0 rounded-none",
large: "w-full max-w-2xl mx-4",
xlarge: "w-full max-w-4xl mx-4",
},
size: {
default: "",
sm: "max-w-sm",
lg: "max-w-lg",
xl: "max-w-xl",
"2xl": "max-w-2xl",
"3xl": "max-w-3xl",
"4xl": "max-w-4xl",
"5xl": "max-w-5xl",
"6xl": "max-w-6xl",
"7xl": "max-w-7xl",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
export interface DialogProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof dialogVariants> {
open?: boolean
onOpenChange?: (open: boolean) => void
}
const Dialog = React.forwardRef<HTMLDivElement, DialogProps>(
({ className, variant, open, onOpenChange, children, ...props }, ref) => {
if (!open) return null
return (
<div
ref={ref}
className={cn(dialogVariants({ variant, className }))}
{...props}
>
<div
className={cn(overlayVariants({ variant }))}
onClick={() => onOpenChange?.(false)}
/>
{children}
</div>
)
}
)
Dialog.displayName = "Dialog"
export interface DialogContentProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof contentVariants> {
onClose?: () => void
showCloseButton?: boolean
}
const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps>(
({ className, variant, size, onClose, showCloseButton = true, children, ...props }, ref) => (
<div
ref={ref}
className={cn(contentVariants({ variant, size, className }))}
onClick={(e) => e.stopPropagation()}
{...props}
>
{showCloseButton && onClose && (
<button
onClick={onClose}
className="absolute top-4 right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
>
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</button>
)}
{children}
</div>
)
)
DialogContent.displayName = "DialogContent"
const DialogHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 text-center sm:text-left p-6", className)}
{...props}
/>
))
DialogHeader.displayName = "DialogHeader"
const DialogFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 p-6 pt-0", className)}
{...props}
/>
))
DialogFooter.displayName = "DialogFooter"
const DialogTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h2
ref={ref}
className={cn("text-lg font-semibold leading-none tracking-tight", className)}
{...props}
/>
))
DialogTitle.displayName = "DialogTitle"
const DialogDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = "DialogDescription"
export { Dialog, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, dialogVariants, contentVariants }