1- import React from 'react' ;
1+ import React , { useState , useEffect } from 'react' ;
22import './ContactModal.css' ;
3- import { X , Envelope , LinkedinLogo , TwitterLogo } from '@phosphor-icons/react' ;
3+ import { X , Envelope , LinkedinLogo , TwitterLogo } from '@phosphor-icons/react' ;
44
55const colorizeText = ( text ) => {
66 return text . split ( ' ' ) . map ( ( word , index ) => {
@@ -13,16 +13,38 @@ const colorizeText = (text) => {
1313} ;
1414
1515const ContactModal = ( { isOpen, onClose } ) => {
16+ const [ isClosing , setIsClosing ] = useState ( false ) ;
17+
18+ useEffect ( ( ) => {
19+ if ( ! isOpen ) {
20+ setIsClosing ( false ) ;
21+ }
22+ } , [ isOpen ] ) ;
23+
24+ const handleClose = ( ) => {
25+ setIsClosing ( true ) ;
26+ setTimeout ( ( ) => {
27+ onClose ( ) ;
28+ setIsClosing ( false ) ;
29+ } , 300 ) ; // Corresponds to animation duration
30+ } ;
31+
1632 if ( ! isOpen ) {
1733 return null ;
1834 }
1935
2036 return (
21- < div className = "modal-overlay" onClick = { onClose } >
22- < div className = "modal-content" onClick = { ( e ) => e . stopPropagation ( ) } >
37+ < div
38+ className = { `modal-overlay ${ isOpen && ! isClosing ? 'fade-in' : 'fade-out' } ` }
39+ onClick = { handleClose }
40+ >
41+ < div
42+ className = { `modal-content ${ isOpen && ! isClosing ? 'slide-up' : 'slide-down' } ` }
43+ onClick = { ( e ) => e . stopPropagation ( ) }
44+ >
2345 < div className = "modal-header" >
2446 < h2 > { colorizeText ( 'Contact Me' ) } </ h2 >
25- < button onClick = { onClose } className = "close-button" >
47+ < button onClick = { handleClose } className = "close-button" >
2648 < X size = { 24 } />
2749 </ button >
2850 </ div >
0 commit comments