-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNavBar.tsx
101 lines (95 loc) · 3.06 KB
/
NavBar.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Link from "next/link";
import React, { useEffect, useState } from "react";
import { AiOutlineClose, AiOutlineMenu } from "react-icons/ai";
const NavBar = () => {
const [nav, setNav] = useState(false);
const [color, setColor] = useState("transparent");
const [textColor, setTextColor] = useState("white");
const handleNav = () => {
setNav(!nav);
};
useEffect(() => {
const changeColor = () => {
if (window.scrollY >= 90) {
setColor("#ffffff");
setTextColor("#000000");
} else {
setColor("transparent");
setTextColor("#ffffff");
}
};
window.addEventListener("scroll", changeColor);
}, []);
return (
<div
style={{ backgroundColor: `${color}` }}
className="fixed left-0 top-0 w-full z-10 ease-in duration-300"
>
<div className="max-w-[1240px] m-auto flex justify-between items-center p-4 text-white">
<Link href="/">
<h1 style={{ color: `${textColor}` }} className="font-bold text-4xl">
MK
</h1>
</Link>
<ul style={{ color: `${textColor}` }} className="hidden sm:flex">
<li className="p-4">
<Link href="/">Home</Link>
</li>
<li className="p-4">
<Link href="/#gallery">Gallery</Link>
</li>
<li className="p-4">
<Link href="/#portfolio">My roads</Link>
</li>
<li className="p-4">
<Link href="/#contact">Contact</Link>
</li>
</ul>
{/* Mobile Button */}
<div onClick={handleNav} className="block sm:hidden z-10">
{nav ? (
<AiOutlineClose size={20} style={{ color: `${textColor}` }} />
) : (
<AiOutlineMenu size={20} style={{ color: `${textColor}` }} />
)}
</div>
{/* Mobile Menu */}
<div
className={
nav
? "sm:hidden absolute top-0 left-0 right-0 bottom-0 flex justify-center items-center w-full h-screen bg-black text-center ease-in duration-300"
: "sm:hidden absolute top-0 left-[-100%] right-0 bottom-0 flex justify-center items-center w-full h-screen bg-black text-center ease-in duration-300"
}
>
<ul>
<li
onClick={handleNav}
className="p-4 text-4xl hover:text-gray-500"
>
<Link href="/">Home</Link>
</li>
<li
onClick={handleNav}
className="p-4 text-4xl hover:text-gray-500"
>
<Link href="/#gallery">Gallery</Link>
</li>
<li
onClick={handleNav}
className="p-4 text-4xl hover:text-gray-500"
>
<Link href="/#portfolio">My roads</Link>
</li>
<li
onClick={handleNav}
className="p-4 text-4xl hover:text-gray-500"
>
<Link href="/#contact">Contact</Link>
</li>
</ul>
</div>
</div>
</div>
);
};
export default NavBar;