|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { Link } from 'react-router-dom' |
| 3 | +import { Menu } from 'lucide-react' |
| 4 | +import MobileNav from './MobileNav' |
| 5 | + |
| 6 | +const Header = () => { |
| 7 | + const [activeMenu, setActiveMenu] = useState<string | null>(null) |
| 8 | + const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) |
| 9 | + |
| 10 | + const toggleMobileMenu = () => { |
| 11 | + setIsMobileMenuOpen(!isMobileMenuOpen) |
| 12 | + } |
| 13 | + |
| 14 | + const navItems = [ |
| 15 | + { |
| 16 | + title: 'About', |
| 17 | + links: [ |
| 18 | + { name: '소개', path: '/about/introduction' }, |
| 19 | + { name: '조직도', path: '/about/organization' }, |
| 20 | + ], |
| 21 | + }, |
| 22 | + { |
| 23 | + title: '활동 기록', |
| 24 | + links: [ |
| 25 | + { name: '활동 현황', path: '/activities/status' }, |
| 26 | + { name: '다솜 소식', path: '/activities/news' }, |
| 27 | + ], |
| 28 | + }, |
| 29 | + { |
| 30 | + title: '가입안내', |
| 31 | + links: [{ name: '지원하기', path: '/join/apply' }], |
| 32 | + }, |
| 33 | + ] |
| 34 | + |
| 35 | + return ( |
| 36 | + <header |
| 37 | + onMouseLeave={() => setActiveMenu(null)} |
| 38 | + className={`w-full relative shadow-[2px_6px_11px_0px_rgba(0,0,0,0.25)] bg-mainBlack text-white transition-all duration-300 ease-in-out ${activeMenu ? 'md:h-[120px]' : 'md:h-[56px]'} h-[56px]`}> |
| 39 | + |
| 40 | + <div className="w-full max-w-screen-xl mx-auto px-4"> |
| 41 | + {/* 모바일 헤더 */} |
| 42 | + <div className="w-full h-[56px] flex md:hidden items-center justify-between"> |
| 43 | + <Link to="/" className="text-mainColor text-2xl font-pretendardBlack"> |
| 44 | + DASOM |
| 45 | + </Link> |
| 46 | + <button onClick={toggleMobileMenu} className="text-3xl hover:text-mainColor transition-colors duration-300"> |
| 47 | + <Menu /> |
| 48 | + </button> |
| 49 | + </div> |
| 50 | + |
| 51 | + {/* 데탑용 헤더 */} |
| 52 | + <div className="w-full hidden md:block"> |
| 53 | + <div className="flex items-center justify-between h-[56px]"> |
| 54 | + <Link to="/" className="text-mainColor text-2xl font-pretendardBlack">DASOM</Link> |
| 55 | + <div className="flex items-center space-x-16"> |
| 56 | + <nav className="flex items-center space-x-16 h-full"> |
| 57 | + {navItems.map((item) => ( |
| 58 | + <div |
| 59 | + key={item.title} |
| 60 | + onMouseEnter={() => setActiveMenu(item.title)} |
| 61 | + className="flex items-center h-[56px] cursor-pointer w-20 justify-center" |
| 62 | + > |
| 63 | + <span className="text-sm font-pretendardBold">{item.title}</span> |
| 64 | + </div> |
| 65 | + ))} |
| 66 | + </nav> |
| 67 | + <Link to="/auth/login" className="text-sm font-pretendardBold whitespace-nowrap">로그인 / 회원가입</Link> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + |
| 73 | + {/* 메뉴바 */} |
| 74 | + <div className={`absolute top-[56px] left-0 w-full bg-mainBlack transition-all duration-300 ease-in-out overflow-hidden hidden md:block ${activeMenu ? 'max-h-40' : 'max-h-0'}`}> |
| 75 | + <div className="w-full max-w-screen-xl mx-auto flex justify-end px-4"> |
| 76 | + <div className="flex items-center space-x-16"> |
| 77 | + <nav className="flex items-start space-x-16 h-full py-4"> |
| 78 | + {navItems.map((item) => ( |
| 79 | + <div key={item.title} className="flex h-full w-20 justify-center"> |
| 80 | + <div className="flex flex-col items-center space-y-2"> |
| 81 | + {item.links.map((link) => ( |
| 82 | + <Link |
| 83 | + key={link.name} |
| 84 | + to={link.path} |
| 85 | + className={`text-sm font-pretendardRegular hover:text-mainColor whitespace-nowrap transition-opacity ${activeMenu === item.title ? 'opacity-100' : 'opacity-0'}`}> |
| 86 | + {link.name} |
| 87 | + </Link> |
| 88 | + ))} |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + ))} |
| 92 | + </nav> |
| 93 | + <div className="invisible"> |
| 94 | + <Link to="/auth/login" className="text-sm font-pretendardBold whitespace-nowrap">로그인 / 회원가입</Link> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + |
| 100 | + {/* 모바일 메뉴바 */} |
| 101 | + {isMobileMenuOpen && <MobileNav navItems={navItems} onClose={toggleMobileMenu} />} |
| 102 | + </header> |
| 103 | + ) |
| 104 | +} |
| 105 | + |
| 106 | +export default Header |
0 commit comments