1
- import React , { useState } from "react" ;
1
+ import React , { useEffect , useRef , useState } from "react" ;
2
2
import { Dialog , DialogContent , DialogTitle } from "@/components/ui/dialog" ;
3
3
import { Button } from "@/components/ui/button" ;
4
4
import { Badge } from "@/components/ui/badge" ;
@@ -45,8 +45,9 @@ const IndividualStructure: React.FC<IndividualStructureProps> = ({
45
45
} ) => {
46
46
const [ expanded , setExpanded ] = useState ( false ) ;
47
47
const [ activeComponent , setActiveComponent ] = useState < React . ReactNode | null > ( null ) ;
48
- const [ modalSizePercentage , setModalSizePercentage ] = useState ( 100 ) ; // Default to 100%
48
+ const [ modalSizePercentage , setModalSizePercentage ] = useState ( 100 ) ;
49
49
const [ tooltip , setTooltip ] = useState < { visible : boolean ; text : string } | null > ( null ) ;
50
+ const modalRef = useRef < HTMLDivElement > ( null ) ;
50
51
51
52
const handleActionClick = ( actionText : string , component : React . ReactNode , sizePercentage : number = 100 ) => {
52
53
setActiveComponent ( component ) ;
@@ -75,10 +76,23 @@ const IndividualStructure: React.FC<IndividualStructureProps> = ({
75
76
} ;
76
77
} ;
77
78
79
+ useEffect ( ( ) => {
80
+ const handleOutsideClick = ( event : MouseEvent ) => {
81
+ if ( modalRef . current && ! modalRef . current . contains ( event . target as Node ) ) {
82
+ handleClose ( ) ;
83
+ setActiveComponent ( null )
84
+ }
85
+ } ;
86
+
87
+ document . addEventListener ( "mousedown" , handleOutsideClick ) ;
88
+ return ( ) => {
89
+ document . removeEventListener ( "mousedown" , handleOutsideClick ) ;
90
+ } ;
91
+ } , [ handleClose ] ) ;
92
+
78
93
return (
79
94
< Dialog defaultOpen >
80
95
< div className = "relative transition-all duration-500 ease-in-out" >
81
- { /* Main Modal */ }
82
96
{ ! activeComponent && (
83
97
< DialogContent
84
98
className = "p-4 rounded-3xl text-white max-w-xl mx-auto"
@@ -199,19 +213,10 @@ const IndividualStructure: React.FC<IndividualStructureProps> = ({
199
213
200
214
{ activeComponent && (
201
215
< DialogContent
202
- className = "p-4 rounded-3xl text-white mx-auto"
203
- style = { {
204
- background : 'linear-gradient(135deg, rgba(44, 79, 100, 0.7), rgba(95, 203, 195, 0.7))' ,
205
- width : '90%' ,
206
- height : '90%' ,
207
- maxWidth : '100%' ,
208
- maxHeight : '90%' ,
209
- position : 'fixed' ,
210
- top : '50%' ,
211
- left : '50%' ,
212
- transform : 'translate(-50%, -50%)' ,
213
- overflow : 'hidden' ,
214
- } }
216
+ className = { `p-4 rounded-3xl text-white mx-auto
217
+ w-[90%] h-[90%] max-w-full max-h-[95%] fixed top-1/2 left-1/2
218
+ transform -translate-x-1/2 -translate-y-1/2
219
+ overflow-hidden bg-[#1D2833]/90` }
215
220
>
216
221
< DialogTitle > </ DialogTitle >
217
222
< div className = "relative flex flex-col items-center justify-center h-full" >
@@ -227,6 +232,7 @@ const IndividualStructure: React.FC<IndividualStructureProps> = ({
227
232
</ div >
228
233
</ DialogContent >
229
234
) }
235
+
230
236
</ div >
231
237
</ Dialog >
232
238
) ;
0 commit comments