@@ -14,149 +14,149 @@ const DialogPortal = DialogPrimitive.Portal;
14
14
const DialogClose = DialogPrimitive . Close ;
15
15
16
16
const DialogOverlay = React . forwardRef <
17
- React . ElementRef < typeof DialogPrimitive . Overlay > ,
18
- React . ComponentPropsWithoutRef < typeof DialogPrimitive . Overlay > & {
19
- showCloseWarning ?: boolean ;
20
- onAttemptClose ?: ( ) => void ;
21
- }
17
+ React . ElementRef < typeof DialogPrimitive . Overlay > ,
18
+ React . ComponentPropsWithoutRef < typeof DialogPrimitive . Overlay > & {
19
+ showCloseWarning ?: boolean ;
20
+ onAttemptClose ?: ( ) => void ;
21
+ }
22
22
> ( ( { className, showCloseWarning = false , onAttemptClose, ...props } , ref ) => (
23
- < DialogPrimitive . Overlay
24
- ref = { ref }
25
- className = { cn (
26
- "fixed inset-0 z-50 bg-black/30 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" ,
27
- className ,
28
- ) }
29
- { ...props }
30
- />
23
+ < DialogPrimitive . Overlay
24
+ ref = { ref }
25
+ className = { cn (
26
+ "fixed inset-0 z-50 bg-black/30 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" ,
27
+ className ,
28
+ ) }
29
+ { ...props }
30
+ />
31
31
) ) ;
32
32
DialogOverlay . displayName = DialogPrimitive . Overlay . displayName ;
33
33
34
34
const DialogContent = React . forwardRef <
35
- React . ElementRef < typeof DialogPrimitive . Content > ,
36
- React . ComponentPropsWithoutRef < typeof DialogPrimitive . Content > & {
37
- showCloseWarning ?: boolean ;
38
- onAttemptClose ?: ( ) => void ;
39
- xButtonRef ?: React . RefObject < HTMLButtonElement > ;
40
- }
35
+ React . ElementRef < typeof DialogPrimitive . Content > ,
36
+ React . ComponentPropsWithoutRef < typeof DialogPrimitive . Content > & {
37
+ showCloseWarning ?: boolean ;
38
+ onAttemptClose ?: ( ) => void ;
39
+ xButtonRef ?: React . RefObject < HTMLButtonElement > ;
40
+ }
41
41
> (
42
- (
43
- { className, children, showCloseWarning = false , onAttemptClose, xButtonRef, ...props } ,
44
- ref ,
45
- ) => {
46
- const handleCloseAttempt = React . useCallback ( ( ) => {
47
- // This handler is now only called when showCloseWarning is true
48
- if ( showCloseWarning ) {
49
- onAttemptClose ?.( ) ;
50
- }
51
- } , [ showCloseWarning , onAttemptClose ] ) ;
42
+ (
43
+ { className, children, showCloseWarning = false , onAttemptClose, xButtonRef, ...props } ,
44
+ ref ,
45
+ ) => {
46
+ const handleCloseAttempt = React . useCallback ( ( ) => {
47
+ // This handler is now only called when showCloseWarning is true
48
+ if ( showCloseWarning ) {
49
+ onAttemptClose ?.( ) ;
50
+ }
51
+ } , [ showCloseWarning , onAttemptClose ] ) ;
52
52
53
- // Common class names for both button types
54
- const buttonClassNames =
55
- "absolute right-4 top-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 text-muted-foreground z-[51]" ;
53
+ // Common class names for both button types
54
+ const buttonClassNames =
55
+ "absolute right-4 top-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 text-muted-foreground z-[51]" ;
56
56
57
- return (
58
- < DialogPortal >
59
- < DialogOverlay showCloseWarning = { showCloseWarning } onAttemptClose = { handleCloseAttempt } />
60
- < DialogPrimitive . Content
61
- ref = { ref }
62
- className = { cn (
63
- "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg" ,
64
- className ,
65
- ) }
66
- onEscapeKeyDown = { ( e ) => {
67
- if ( showCloseWarning ) {
68
- e . preventDefault ( ) ;
69
- handleCloseAttempt ( ) ;
70
- }
71
- } }
72
- onPointerDownOutside = { ( e ) => {
73
- // Prevent closing only if warning is active and click is outside content
74
- if ( showCloseWarning ) {
75
- // Basic check: If the target is the overlay, it's handled there.
76
- // More robust checks might be needed depending on content complexity.
77
- const contentElement = ( e . target as HTMLElement ) ?. closest ( '[role="dialog"]' ) ;
78
- if ( ! contentElement || contentElement !== e . currentTarget ) {
79
- e . preventDefault ( ) ;
80
- handleCloseAttempt ( ) ;
81
- }
82
- }
83
- } }
84
- { ...props }
85
- >
86
- { children }
57
+ return (
58
+ < DialogPortal >
59
+ < DialogOverlay showCloseWarning = { showCloseWarning } onAttemptClose = { handleCloseAttempt } />
60
+ < DialogPrimitive . Content
61
+ ref = { ref }
62
+ className = { cn (
63
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg" ,
64
+ className ,
65
+ ) }
66
+ onEscapeKeyDown = { ( e ) => {
67
+ if ( showCloseWarning ) {
68
+ e . preventDefault ( ) ;
69
+ handleCloseAttempt ( ) ;
70
+ }
71
+ } }
72
+ onPointerDownOutside = { ( e ) => {
73
+ // Prevent closing only if warning is active and click is outside content
74
+ if ( showCloseWarning ) {
75
+ // Basic check: If the target is the overlay, it's handled there.
76
+ // More robust checks might be needed depending on content complexity.
77
+ const contentElement = ( e . target as HTMLElement ) ?. closest ( '[role="dialog"]' ) ;
78
+ if ( ! contentElement || contentElement !== e . currentTarget ) {
79
+ e . preventDefault ( ) ;
80
+ handleCloseAttempt ( ) ;
81
+ }
82
+ }
83
+ } }
84
+ { ...props }
85
+ >
86
+ { children }
87
87
88
- { /* Conditionally render the close button */ }
89
- { showCloseWarning ? (
90
- < button
91
- ref = { xButtonRef } // Attach ref only needed for anchoring the custom popover
92
- type = "button"
93
- onClick = { handleCloseAttempt } // Call attempt handler
94
- className = { buttonClassNames }
95
- aria-label = "Close dialog with confirmation"
96
- >
97
- < X className = "w-4 h-4" />
98
- </ button >
99
- ) : (
100
- // Use DialogPrimitive.Close for standard behavior
101
- < DialogPrimitive . Close asChild >
102
- < button type = "button" className = { buttonClassNames } aria-label = "Close dialog" >
103
- < X className = "w-4 h-4" />
104
- </ button >
105
- </ DialogPrimitive . Close >
106
- ) }
107
- </ DialogPrimitive . Content >
108
- </ DialogPortal >
109
- ) ;
110
- } ,
88
+ { /* Conditionally render the close button */ }
89
+ { showCloseWarning ? (
90
+ < button
91
+ ref = { xButtonRef } // Attach ref only needed for anchoring the custom popover
92
+ type = "button"
93
+ onClick = { handleCloseAttempt } // Call attempt handler
94
+ className = { buttonClassNames }
95
+ aria-label = "Close dialog with confirmation"
96
+ >
97
+ < X className = "w-4 h-4" />
98
+ </ button >
99
+ ) : (
100
+ // Use DialogPrimitive.Close for standard behavior
101
+ < DialogPrimitive . Close asChild >
102
+ < button type = "button" className = { buttonClassNames } aria-label = "Close dialog" >
103
+ < X className = "w-4 h-4" />
104
+ </ button >
105
+ </ DialogPrimitive . Close >
106
+ ) }
107
+ </ DialogPrimitive . Content >
108
+ </ DialogPortal >
109
+ ) ;
110
+ } ,
111
111
) ;
112
112
DialogContent . displayName = DialogPrimitive . Content . displayName ;
113
113
114
114
const DialogHeader = ( { className, ...props } : React . HTMLAttributes < HTMLDivElement > ) => (
115
- < div className = { cn ( "flex flex-col space-y-1.5 text-center sm:text-left" , className ) } { ...props } />
115
+ < div className = { cn ( "flex flex-col space-y-1.5 text-center sm:text-left" , className ) } { ...props } />
116
116
) ;
117
117
DialogHeader . displayName = "DialogHeader" ;
118
118
119
119
const DialogFooter = ( { className, ...props } : React . HTMLAttributes < HTMLDivElement > ) => (
120
- < div
121
- className = { cn ( "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2" , className ) }
122
- { ...props }
123
- />
120
+ < div
121
+ className = { cn ( "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2" , className ) }
122
+ { ...props }
123
+ />
124
124
) ;
125
125
DialogFooter . displayName = "DialogFooter" ;
126
126
127
127
const DialogTitle = React . forwardRef <
128
- React . ElementRef < typeof DialogPrimitive . Title > ,
129
- React . ComponentPropsWithoutRef < typeof DialogPrimitive . Title >
128
+ React . ElementRef < typeof DialogPrimitive . Title > ,
129
+ React . ComponentPropsWithoutRef < typeof DialogPrimitive . Title >
130
130
> ( ( { className, ...props } , ref ) => (
131
- < DialogPrimitive . Title
132
- ref = { ref }
133
- className = { cn ( "text-lg font-semibold leading-none tracking-tight" , className ) }
134
- { ...props }
135
- />
131
+ < DialogPrimitive . Title
132
+ ref = { ref }
133
+ className = { cn ( "text-lg font-semibold leading-none tracking-tight" , className ) }
134
+ { ...props }
135
+ />
136
136
) ) ;
137
137
DialogTitle . displayName = DialogPrimitive . Title . displayName ;
138
138
139
139
const DialogDescription = React . forwardRef <
140
- React . ElementRef < typeof DialogPrimitive . Description > ,
141
- React . ComponentPropsWithoutRef < typeof DialogPrimitive . Description >
140
+ React . ElementRef < typeof DialogPrimitive . Description > ,
141
+ React . ComponentPropsWithoutRef < typeof DialogPrimitive . Description >
142
142
> ( ( { className, ...props } , ref ) => (
143
- < DialogPrimitive . Description
144
- ref = { ref }
145
- className = { cn ( "text-sm text-content-subtle" , className ) }
146
- { ...props }
147
- />
143
+ < DialogPrimitive . Description
144
+ ref = { ref }
145
+ className = { cn ( "text-sm text-content-subtle" , className ) }
146
+ { ...props }
147
+ />
148
148
) ) ;
149
149
DialogDescription . displayName = DialogPrimitive . Description . displayName ;
150
150
151
151
export {
152
- Dialog ,
153
- DialogPortal ,
154
- DialogOverlay ,
155
- DialogClose ,
156
- DialogTrigger ,
157
- DialogContent ,
158
- DialogHeader ,
159
- DialogFooter ,
160
- DialogTitle ,
161
- DialogDescription ,
162
- } ;
152
+ Dialog ,
153
+ DialogPortal ,
154
+ DialogOverlay ,
155
+ DialogClose ,
156
+ DialogTrigger ,
157
+ DialogContent ,
158
+ DialogHeader ,
159
+ DialogFooter ,
160
+ DialogTitle ,
161
+ DialogDescription ,
162
+ } ;
0 commit comments