|
1 | | -import { NavLink } from 'react-router'; |
2 | | -import { chatDefault, homeDefault, mypageDefault } from '@/assets/icons/nav'; |
3 | | -import { twMerge } from 'tailwind-merge'; |
4 | | -import HomeActive from '@/assets/icons/nav/HomeActive'; |
5 | | -import ChatActive from '@/assets/icons/nav/ChatActive'; |
6 | | -import MyPageActive from '@/assets/icons/nav/MyPageActive'; |
| 1 | +import { NavLink, useLocation } from 'react-router'; |
| 2 | +import { |
| 3 | + chatDefault, |
| 4 | + homeDefault, |
| 5 | + mypageDefault, |
| 6 | + HomeActive, |
| 7 | + ChatActive, |
| 8 | + MyPageActive, |
| 9 | +} from '@/assets/icons/nav'; |
| 10 | +import { cn } from '@/utils'; |
7 | 11 |
|
8 | 12 | const navItems = [ |
9 | | - { path: '/home', label: '홈', icons: { default: homeDefault, active: <HomeActive /> } }, |
| 13 | + { |
| 14 | + path: '/home', |
| 15 | + label: '홈', |
| 16 | + icons: { |
| 17 | + default: <img src={homeDefault} alt="홈 아이콘" className="w-6 h-6" />, |
| 18 | + active: <HomeActive />, |
| 19 | + }, |
| 20 | + }, |
10 | 21 | { |
11 | 22 | path: '/chat', |
12 | 23 | label: '채팅', |
13 | | - icons: { default: chatDefault, active: <ChatActive /> }, |
| 24 | + icons: { |
| 25 | + default: <img src={chatDefault} alt="채팅 아이콘" className="w-6 h-6" />, |
| 26 | + active: <ChatActive />, |
| 27 | + }, |
14 | 28 | }, |
15 | 29 | { |
16 | 30 | path: '/mypage', |
17 | 31 | label: '마이페이지', |
18 | | - icons: { default: mypageDefault, active: <MyPageActive /> }, |
| 32 | + icons: { |
| 33 | + default: <img src={mypageDefault} alt="마이페이지 아이콘" className="w-6 h-6" />, |
| 34 | + active: <MyPageActive />, |
| 35 | + }, |
19 | 36 | }, |
20 | 37 | ]; |
21 | 38 |
|
22 | 39 | export default function BottomNav() { |
| 40 | + const location = useLocation(); // 현재 URL 가져오기 |
| 41 | + //바텀 nav 바 필요한 페이지 |
| 42 | + const showNav = |
| 43 | + //메인 페이지 |
| 44 | + location.pathname === '/home' || |
| 45 | + //마이 페이지 |
| 46 | + location.pathname === '/mypage' || |
| 47 | + //유저 페이지 |
| 48 | + location.pathname.startsWith('/user') || |
| 49 | + //지난 대화 기록 페이지 |
| 50 | + location.pathname === '/chat'; |
| 51 | + |
| 52 | + if (!showNav) return null; |
| 53 | + |
23 | 54 | return ( |
24 | | - <nav className="fixed bottom-padding-nav bottom-0 left-1/2 -translate-x-1/2 z-40 flex max-w-[600px] min-w-[320px] w-full bg-secondary-1 py-1"> |
25 | | - {navItems.map(({ path, label, icons }) => ( |
26 | | - <NavLink |
27 | | - key={path} |
28 | | - to={path} |
29 | | - className="flex-1 flex flex-col items-center justify-center gap-0.5 py-0.5 hover:brightness-120 transition" |
30 | | - > |
31 | | - {({ isActive }) => ( |
32 | | - <> |
33 | | - {isActive ? ( |
34 | | - icons.active |
35 | | - ) : ( |
36 | | - <img src={icons.default} className="w-6 h-6" alt={`${label} Icon`} /> |
37 | | - )} |
| 55 | + <> |
| 56 | + <nav className="fixed bottom-padding-nav bottom-0 left-1/2 -translate-x-1/2 z-40 flex max-w-[600px] min-w-[320px] w-full bg-secondary-1 pt-1"> |
| 57 | + {navItems.map(({ path, label, icons }) => ( |
| 58 | + <NavLink |
| 59 | + key={path} |
| 60 | + to={path} |
| 61 | + className="flex-1 flex flex-col items-center justify-center gap-0.5 py-0.5 hover:brightness-120 transition" |
| 62 | + > |
| 63 | + {({ isActive }) => ( |
| 64 | + <> |
| 65 | + {isActive ? icons.active : icons.default} |
| 66 | + <span |
| 67 | + className={cn( |
| 68 | + 'text-[10px] leading-[18px', |
| 69 | + isActive ? 'text-primary-active' : 'text-gray-50', |
| 70 | + )} |
| 71 | + > |
| 72 | + {label} |
| 73 | + </span> |
| 74 | + </> |
| 75 | + )} |
| 76 | + </NavLink> |
| 77 | + ))} |
| 78 | + </nav> |
38 | 79 |
|
39 | | - <span |
40 | | - className={twMerge( |
41 | | - 'text-[10px] leading-[18px] text-gray-50', |
42 | | - isActive && 'text-primary-active', |
43 | | - )} |
44 | | - > |
45 | | - {label} |
46 | | - </span> |
47 | | - </> |
48 | | - )} |
49 | | - </NavLink> |
50 | | - ))} |
51 | | - </nav> |
| 80 | + {/* Spacer: 콘텐츠가 하단바에 가려지지 않도록 */} |
| 81 | + <div className="h-[62px]" /> |
| 82 | + </> |
52 | 83 | ); |
53 | 84 | } |
0 commit comments