@@ -4,40 +4,54 @@ import Close from '@/shared/assets/icons/close_32.svg';
44import User from '@/shared/assets/icons/user_24.svg' ;
55import Link from 'next/link' ;
66import { usePathname } from 'next/navigation' ;
7- import { useEffect , useRef } from 'react' ;
7+ import { useEffect , useRef , useState } from 'react' ;
88import gsap from 'gsap' ;
99import { useAuthStore } from '@/shared/@store/auth' ;
1010
1111interface Props {
1212 isClicked : boolean ;
1313 setIsClicked : ( state : boolean ) => void ;
14+ visible : boolean ;
15+ setVisible : ( state : boolean ) => void ;
1416}
1517
16- function DropdownMenu ( { isClicked, setIsClicked } : Props ) {
18+ function DropdownMenu ( { isClicked, setIsClicked, visible , setVisible } : Props ) {
1719 const pathname = usePathname ( ) ;
1820 const menuRef = useRef < HTMLDivElement > ( null ) ;
1921 const textRef = useRef < ( HTMLSpanElement | null ) [ ] > ( [ ] ) ;
22+ const tlRef = useRef < GSAPTimeline | null > ( null ) ;
2023
2124 const { isLoggedIn, logout } = useAuthStore ( ) ;
2225
2326 useEffect ( ( ) => {
2427 if ( ! menuRef . current ) return ;
28+ if ( ! tlRef . current ) {
29+ const tl = gsap . timeline ( {
30+ paused : true ,
31+ onReverseComplete : ( ) => {
32+ setVisible ( false ) ;
33+ } ,
34+ } ) ;
2535
26- if ( isClicked ) {
27- gsap . fromTo (
36+ tl . fromTo (
2837 menuRef . current ,
29- {
30- x : - 200 ,
31- opacity : 0 ,
32- } ,
33- {
34- x : 0 ,
35- opacity : 1 ,
36- duration : 0.8 ,
37- ease : 'expo.inOut' ,
38- }
38+ { x : - 200 , opacity : 0 } ,
39+ { x : 0 , opacity : 1 , duration : 0.5 , ease : 'expo.inOut' }
3940 ) ;
41+
42+ tlRef . current = tl ;
4043 }
44+
45+ if ( isClicked ) {
46+ setVisible ( true ) ;
47+ tlRef . current . play ( ) ;
48+ } else {
49+ tlRef . current . reverse ( ) ;
50+ }
51+
52+ return ( ) => {
53+ // tl.kill();
54+ } ;
4155 } , [ isClicked ] ) ;
4256
4357 const handleMouseEnter = ( index : number ) => {
@@ -62,7 +76,7 @@ function DropdownMenu({ isClicked, setIsClicked }: Props) {
6276
6377 return (
6478 < nav
65- className = " w-full h-screen bg-secondary absolute top-0 left-0 px-[12px] font-serif block sm:hidden"
79+ className = { ` w-full h-screen bg-secondary absolute top-0 left-0 px-[12px] font-serif block sm:hidden ${ visible ? 'block' : 'hidden' } ` }
6680 role = "navigation"
6781 aria-label = "메인 네비게이션 메뉴"
6882 tabIndex = { - 1 }
0 commit comments