navTabs.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. const pathname = usePathname();
  12. const dragScroll = useDragScroll<HTMLDivElement>();
  13. const scroll = useCallback((dir: 'left' | 'right') => {
  14. const el = dragScroll.ref.current;
  15. if (!el) return;
  16. el.scrollBy({ left: dir === 'left' ? -SCROLL_AMOUNT : SCROLL_AMOUNT, behavior: 'smooth' });
  17. }, [dragScroll.ref]);
  18. return (
  19. <div id="tabs-wrapper">
  20. <button type='button' className='scroll-arrow left' onClick={() => scroll('left')} aria-label='왼쪽 스크롤'>
  21. <FontAwesomeIcon icon={faChevronLeft} />
  22. </button>
  23. <div id="tabs" ref={dragScroll.ref} onMouseDown={dragScroll.onMouseDown} onMouseMove={dragScroll.onMouseMove} onMouseUp={dragScroll.onMouseUp} onMouseLeave={dragScroll.onMouseLeave}>
  24. {[
  25. { href: "/profile", label: "내 정보" },
  26. { href: "/change-password", label: "비밀번호 변경" },
  27. { href: "/my-posts", label: "작성 게시글" },
  28. { href: "/my-comments", label: "작성 댓글" },
  29. { href: "/exp-logs", label: "경험치 내역" },
  30. { href: "/login-log", label: "로그인 기록" },
  31. { href: "/withdraw", label: "회원탈퇴" }
  32. ].map(({ href, label }) => (
  33. <Link key={href} href={href} className={pathname === href ? 'active' : undefined}>{label}</Link>
  34. ))}
  35. </div>
  36. <button type='button' className='scroll-arrow right' onClick={() => scroll('right')} aria-label='오른쪽 스크롤'>
  37. <FontAwesomeIcon icon={faChevronRight} />
  38. </button>
  39. </div>
  40. );
  41. }