-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.tsx
77 lines (69 loc) · 1.99 KB
/
header.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use client';
import cx from 'classnames';
import Image from 'next/image';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useEffect, useRef, useState } from 'react';
import { useOutsideClick } from '@/hooks/useOutsideClick';
import { NAVIGATIONS } from '@/lib/constants';
import DownIcon from '@/public/svgs/down.svg';
export function Menu() {
const pathname = usePathname();
const [isOpen, setIsOpen] = useState(false);
const ref = useRef<HTMLElement>(null);
useEffect(() => {
setIsOpen(false);
}, [pathname]);
useOutsideClick(ref, () => setIsOpen(false));
return (
<header className="flex select-none items-start justify-between sm:items-center">
<Link
href="/"
className="rounded-full bg-orange-500 transition-transform hover:scale-110"
>
<Image
src="/images/memoji.png"
alt="Mehmet Sağır"
width={40}
height={40}
/>
</Link>
<nav
ref={ref}
className={cx(
isOpen ? 'flex' : 'hidden',
'flex-col items-center justify-start sm:flex sm:flex-row sm:gap-6 pr-1 sm:pr-0'
)}
>
{NAVIGATIONS.map(({ label, href }, index) => {
const isActive =
href === '/' ? pathname === href : pathname?.includes(href);
return (
<Link
key={index}
href={href}
className={cx(
'transition-colors py-2 sm:py-0 block w-full text-left',
isActive ? 'text-white' : 'text-gray-300/60'
)}
>
{label}
</Link>
);
})}
</nav>
{!isOpen && (
<button
type="button"
className="flex items-center py-2 sm:hidden"
onClick={() => {
setIsOpen(!isOpen);
}}
>
{NAVIGATIONS.find(item => item.href === pathname)?.label}
<DownIcon />
</button>
)}
</header>
);
}