navTabs.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use client';
  2. import './style.scss';
  3. import { useCallback } from 'react';
  4. import Link from 'next/link';
  5. import { usePathname } from 'next/navigation';
  6. import useDragScroll from '@/hooks/useDragScroll';
  7. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  8. import { faChevronLeft, faChevronRight } from '@fortawesome/free-solid-svg-icons';
  9. const SCROLL_AMOUNT = 120;
  10. export default function NavTabs()
  11. {
  12. const pathname = usePathname();
  13. const dragScroll = useDragScroll<HTMLDivElement>();
  14. const scroll = useCallback((dir: 'left' | 'right') => {
  15. const el = dragScroll.ref.current;
  16. if (!el) {
  17. return;
  18. }
  19. el.scrollBy({ left: dir === 'left' ? -SCROLL_AMOUNT : SCROLL_AMOUNT, behavior: 'smooth' });
  20. }, [dragScroll.ref]);
  21. return (
  22. <div id="tabs-wrapper">
  23. <button type='button' className='scroll-arrow left' onClick={() => scroll('left')} aria-label='왼쪽 스크롤'>
  24. <FontAwesomeIcon icon={faChevronLeft} />
  25. </button>
  26. <div id="tabs" ref={dragScroll.ref} onMouseDown={dragScroll.onMouseDown} onMouseMove={dragScroll.onMouseMove} onMouseUp={dragScroll.onMouseUp} onMouseLeave={dragScroll.onMouseLeave}>
  27. {[
  28. { href: "/profile", label: "내 정보" },
  29. { href: "/level", label: "레벨·보상" },
  30. { href: "/inventory", label: "보관함" },
  31. { href: "/items", label: "아이템" },
  32. { href: "/orders", label: "주문 목록" },
  33. { href: "/charge-logs", label: "캐시 내역" },
  34. { href: "/my-posts", label: "작성 게시글" },
  35. { href: "/my-comments", label: "작성 댓글" },
  36. { href: "/exp-logs", label: "경험치 내역" },
  37. { href: "/login-log", label: "로그인 기록" },
  38. { href: "/change-password", label: "비밀번호 변경" },
  39. { href: "/withdraw", label: "회원탈퇴" }
  40. ].map(({ href, label }) => (
  41. <Link key={href} href={href} className={pathname === href ? 'active' : undefined}>{label}</Link>
  42. ))}
  43. </div>
  44. <button type='button' className='scroll-arrow right' onClick={() => scroll('right')} aria-label='오른쪽 스크롤'>
  45. <FontAwesomeIcon icon={faChevronRight} />
  46. </button>
  47. </div>
  48. );
  49. }