navTabs.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: "/change-password", label: "비밀번호 변경" },
  30. { href: "/my-posts", label: "작성 게시글" },
  31. { href: "/my-comments", label: "작성 댓글" },
  32. { href: "/charge-logs", label: "(P) 충전 내역" },
  33. { href: "/exp-logs", label: "경험치 내역" },
  34. { href: "/login-log", label: "로그인 기록" },
  35. { href: "/withdraw", label: "회원탈퇴" }
  36. ].map(({ href, label }) => (
  37. <Link key={href} href={href} className={pathname === href ? 'active' : undefined}>{label}</Link>
  38. ))}
  39. </div>
  40. <button type='button' className='scroll-arrow right' onClick={() => scroll('right')} aria-label='오른쪽 스크롤'>
  41. <FontAwesomeIcon icon={faChevronRight} />
  42. </button>
  43. </div>
  44. );
  45. }