-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialog.tsx
More file actions
191 lines (166 loc) · 5.21 KB
/
Copy pathdialog.tsx
File metadata and controls
191 lines (166 loc) · 5.21 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import * as DialogPrimitive from '@radix-ui/react-dialog'
import {
DialogClose,
DialogDescription,
DialogPortal,
DialogTitle,
DialogTrigger,
Dialog as ShadcnDialog,
DialogFooter as ShadcnDialogFooter,
DialogOverlay as ShadcnDialogOverlay,
} from '@repo/shadcn/ui/dialog'
import * as React from 'react'
import { cn } from '../../../utils/cn'
import { CloseIcon } from '../../icons/close.icon'
/* -----------------------------------------------------------------------------
* Dialog Root
* -------------------------------------------------------------------------- */
interface DialogProps {
open?: boolean
onOpenChange?: (open: boolean) => void
defaultOpen?: boolean
children: React.ReactNode
}
function Dialog({ children, ...props }: DialogProps) {
return <ShadcnDialog {...props}>{children}</ShadcnDialog>
}
/* -----------------------------------------------------------------------------
* Dialog Overlay
* -------------------------------------------------------------------------- */
interface DialogOverlayProps {
className?: string
}
function DialogOverlay({ className, ...props }: DialogOverlayProps) {
return (
<ShadcnDialogOverlay
className={cn('bg-dialog-overlay/50 backdrop-blur-[2px]', className)}
{...props}
/>
)
}
/* -----------------------------------------------------------------------------
* Dialog Trigger
* -------------------------------------------------------------------------- */
interface DialogTriggerProps {
children: React.ReactNode
asChild?: boolean
}
function Trigger({ children, asChild = true }: DialogTriggerProps) {
return <DialogTrigger asChild={asChild}>{children}</DialogTrigger>
}
/* -----------------------------------------------------------------------------
* Dialog Content
* -------------------------------------------------------------------------- */
interface DialogContentProps {
children: React.ReactNode
className?: string
}
function Content({ children, className }: DialogContentProps) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
className={cn(
'dark:bg-muted dark:border-dialog-border 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 flex max-h-[80vh] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col gap-0 overflow-hidden rounded-lg bg-white p-0 shadow-xl duration-200 sm:max-w-lg dark:border [&>button:last-child]:hidden',
className,
)}
>
{children}
</DialogPrimitive.Content>
</DialogPortal>
)
}
/* -----------------------------------------------------------------------------
* Dialog Header
* -------------------------------------------------------------------------- */
interface DialogHeaderProps {
title: React.ReactNode
description?: React.ReactNode
onClose?: () => void
className?: string
descriptionClassName?: string
}
function Header({
title,
description,
onClose,
className,
descriptionClassName,
}: DialogHeaderProps) {
return (
<div
className={cn(
'dark:bg-muted dark:border-dialog-border flex shrink-0 flex-col gap-2 bg-white p-5',
className,
)}
>
<DialogTitle className="text-base font-semibold">{title}</DialogTitle>
{description && (
<DialogDescription className={cn('text-sm font-normal', descriptionClassName)}>
{description}
</DialogDescription>
)}
{onClose && (
<DialogClose className="absolute top-4 right-4 cursor-pointer" onClick={onClose}>
<CloseIcon />
</DialogClose>
)}
</div>
)
}
/* -----------------------------------------------------------------------------
* Dialog Body
* -------------------------------------------------------------------------- */
interface DialogBodyProps {
children: React.ReactNode
className?: string
}
function Body({ children, className }: DialogBodyProps) {
return (
<div
className={cn(
'min-h-0 max-h-[max(0px,calc(80vh-9rem))] flex-1 overflow-y-auto py-5',
className,
)}
>
{children}
</div>
)
}
/* -----------------------------------------------------------------------------
* Dialog Footer
* -------------------------------------------------------------------------- */
interface DialogFooterProps {
children: React.ReactNode
className?: string
}
function Footer({ children, className }: DialogFooterProps) {
return (
<ShadcnDialogFooter
className={cn(
'dark:bg-muted dark:border-dialog-border shrink-0 gap-3 bg-white p-5',
className,
)}
>
{children}
</ShadcnDialogFooter>
)
}
/* -----------------------------------------------------------------------------
* Compound Component Export
* -------------------------------------------------------------------------- */
Dialog.Trigger = Trigger
Dialog.Content = Content
Dialog.Header = Header
Dialog.Body = Body
Dialog.Footer = Footer
Dialog.Overlay = DialogOverlay
export { Dialog }
export type {
DialogBodyProps,
DialogContentProps,
DialogFooterProps,
DialogHeaderProps,
DialogProps,
DialogTriggerProps,
}