|
1 | 1 | 'use client'; |
2 | 2 |
|
| 3 | +// Import the polyfill early |
| 4 | +import '../../lib/utils/radix-utils'; |
| 5 | + |
3 | 6 | import * as React from 'react'; |
| 7 | +import * as DialogPrimitive from '@radix-ui/react-dialog'; |
4 | 8 | import { X } from 'lucide-react'; |
5 | 9 | import { cn } from '@/lib/utils'; |
6 | 10 |
|
7 | | -// DISABLED FOR TESTING |
8 | | -// import * as DialogPrimitive from '@radix-ui/react-dialog'; |
9 | | -// interface CustomDialogContentProps |
10 | | -// extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> { |
11 | | -// headerTitle?: string; |
12 | | -// } |
13 | | - |
14 | | -// Mock interfaces and components to replace Radix UI |
15 | | -interface DialogProps { |
16 | | - children?: React.ReactNode; |
17 | | - open?: boolean; |
18 | | - onOpenChange?: (open: boolean) => void; |
19 | | -} |
20 | | - |
21 | | -interface DialogTriggerProps { |
22 | | - children?: React.ReactNode; |
23 | | - asChild?: boolean; |
24 | | -} |
25 | | - |
26 | | -interface DialogPortalProps { |
27 | | - children?: React.ReactNode; |
28 | | -} |
29 | | - |
30 | | -interface DialogCloseProps { |
31 | | - children?: React.ReactNode; |
32 | | - asChild?: boolean; |
33 | | - className?: string; |
34 | | -} |
35 | | - |
36 | | -interface DialogOverlayProps { |
37 | | - className?: string; |
38 | | - [key: string]: any; |
39 | | -} |
40 | | - |
41 | | -interface CustomDialogContentProps { |
42 | | - className?: string; |
43 | | - children?: React.ReactNode; |
| 11 | +interface CustomDialogContentProps |
| 12 | + extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> { |
44 | 13 | headerTitle?: string; |
45 | | - onOpenAutoFocus?: (e: any) => void; |
46 | | - onEscapeKeyDown?: () => void; |
47 | | - onPointerDownOutside?: () => void; |
48 | | - [key: string]: any; |
49 | | -} |
50 | | - |
51 | | -interface DialogTitleProps { |
52 | | - className?: string; |
53 | | - children?: React.ReactNode; |
54 | | - [key: string]: any; |
55 | | -} |
56 | | - |
57 | | -interface DialogDescriptionProps { |
58 | | - className?: string; |
59 | | - children?: React.ReactNode; |
60 | | - [key: string]: any; |
61 | 14 | } |
62 | 15 |
|
63 | | -// Mock components |
64 | | -const Dialog: React.FC<DialogProps> = ({ children }) => <div className="mock-dialog">{children}</div>; |
65 | | -const DialogTrigger: React.FC<DialogTriggerProps> = ({ children }) => <>{children}</>; |
66 | | -const DialogPortal: React.FC<DialogPortalProps> = ({ children }) => <>{children}</>; |
67 | | -const DialogClose: React.FC<DialogCloseProps> = ({ children }) => <>{children}</>; |
68 | | -const DialogOverlay = React.forwardRef<HTMLDivElement, DialogOverlayProps>( |
69 | | - (props, ref) => <div ref={ref} className="hidden" {...props} /> |
70 | | -); |
71 | | -DialogOverlay.displayName = 'DialogOverlay'; |
72 | | - |
73 | | -const DialogContent = React.forwardRef<HTMLDivElement, CustomDialogContentProps>( |
74 | | - ({ className, children, headerTitle, ...props }, ref) => ( |
75 | | - <div |
| 16 | +const Dialog = DialogPrimitive.Root; |
| 17 | +const DialogTrigger = DialogPrimitive.Trigger; |
| 18 | +const DialogPortal = DialogPrimitive.Portal; |
| 19 | +const DialogClose = DialogPrimitive.Close; |
| 20 | + |
| 21 | +const DialogOverlay = React.forwardRef< |
| 22 | + React.ElementRef<typeof DialogPrimitive.Overlay>, |
| 23 | + React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> |
| 24 | +>(({ className, ...props }, ref) => ( |
| 25 | + <DialogPrimitive.Overlay |
| 26 | + ref={ref} |
| 27 | + className={cn( |
| 28 | + 'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0', |
| 29 | + className |
| 30 | + )} |
| 31 | + {...props} |
| 32 | + /> |
| 33 | +)); |
| 34 | +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; |
| 35 | + |
| 36 | +const DialogContent = React.forwardRef< |
| 37 | + React.ElementRef<typeof DialogPrimitive.Content>, |
| 38 | + CustomDialogContentProps |
| 39 | +>(({ className, children, headerTitle, ...props }, ref) => ( |
| 40 | + <DialogPortal> |
| 41 | + <DialogOverlay /> |
| 42 | + <DialogPrimitive.Content |
76 | 43 | ref={ref} |
77 | | - className={cn('fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2', className)} |
| 44 | + className={cn( |
| 45 | + 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border-0 bg-background p-0 shadow-lg duration-200', |
| 46 | + headerTitle && 'sm:rounded-lg', |
| 47 | + className |
| 48 | + )} |
78 | 49 | {...props} |
79 | 50 | > |
80 | 51 | {headerTitle && ( |
81 | 52 | <div className='bg-brand-pink p-2 flex items-center justify-between sm:rounded-t-lg'> |
82 | | - <div className='text-xl font-semibold text-white'> |
| 53 | + <DialogPrimitive.Title className='text-xl font-semibold text-white'> |
83 | 54 | {headerTitle} |
84 | | - </div> |
85 | | - <button className='text-white' aria-label='Close'> |
86 | | - <X size={24} /> |
87 | | - </button> |
| 55 | + </DialogPrimitive.Title> |
| 56 | + <DialogPrimitive.Close asChild> |
| 57 | + <button className='text-white' aria-label='Close'> |
| 58 | + <X size={24} /> |
| 59 | + </button> |
| 60 | + </DialogPrimitive.Close> |
88 | 61 | </div> |
89 | 62 | )} |
90 | 63 | <div className={headerTitle ? 'p-4 bg-gray-50 sm:rounded-b-lg' : 'p-4'}> |
91 | 64 | {children} |
92 | 65 | </div> |
93 | | - </div> |
94 | | - ) |
95 | | -); |
96 | | -DialogContent.displayName = 'DialogContent'; |
| 66 | + </DialogPrimitive.Content> |
| 67 | + </DialogPortal> |
| 68 | +)); |
| 69 | + |
| 70 | +DialogContent.displayName = DialogPrimitive.Content.displayName; |
97 | 71 |
|
98 | 72 | const DialogHeader = ({ |
99 | 73 | className, |
@@ -123,31 +97,32 @@ const DialogFooter = ({ |
123 | 97 | ); |
124 | 98 | DialogFooter.displayName = 'DialogFooter'; |
125 | 99 |
|
126 | | -const DialogTitle = React.forwardRef<HTMLHeadingElement, DialogTitleProps>( |
127 | | - ({ className, children, ...props }, ref) => ( |
128 | | - <h2 |
129 | | - ref={ref} |
130 | | - className={cn('text-lg font-semibold leading-none tracking-tight', className)} |
131 | | - {...props} |
132 | | - > |
133 | | - {children} |
134 | | - </h2> |
135 | | - ) |
136 | | -); |
137 | | -DialogTitle.displayName = 'DialogTitle'; |
138 | | - |
139 | | -const DialogDescription = React.forwardRef<HTMLParagraphElement, DialogDescriptionProps>( |
140 | | - ({ className, children, ...props }, ref) => ( |
141 | | - <p |
142 | | - ref={ref} |
143 | | - className={cn('text-sm text-muted-foreground', className)} |
144 | | - {...props} |
145 | | - > |
146 | | - {children} |
147 | | - </p> |
148 | | - ) |
149 | | -); |
150 | | -DialogDescription.displayName = 'DialogDescription'; |
| 100 | +const DialogTitle = React.forwardRef< |
| 101 | + React.ElementRef<typeof DialogPrimitive.Title>, |
| 102 | + React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> |
| 103 | +>(({ className, ...props }, ref) => ( |
| 104 | + <DialogPrimitive.Title |
| 105 | + ref={ref} |
| 106 | + className={cn( |
| 107 | + 'text-lg font-semibold leading-none tracking-tight', |
| 108 | + className |
| 109 | + )} |
| 110 | + {...props} |
| 111 | + /> |
| 112 | +)); |
| 113 | +DialogTitle.displayName = DialogPrimitive.Title.displayName; |
| 114 | + |
| 115 | +const DialogDescription = React.forwardRef< |
| 116 | + React.ElementRef<typeof DialogPrimitive.Description>, |
| 117 | + React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> |
| 118 | +>(({ className, ...props }, ref) => ( |
| 119 | + <DialogPrimitive.Description |
| 120 | + ref={ref} |
| 121 | + className={cn('text-sm text-muted-foreground', className)} |
| 122 | + {...props} |
| 123 | + /> |
| 124 | +)); |
| 125 | +DialogDescription.displayName = DialogPrimitive.Description.displayName; |
151 | 126 |
|
152 | 127 | export { |
153 | 128 | Dialog, |
|
0 commit comments