Skip to content

Commit edf4e7c

Browse files
authored
[CW2-9] Add navbar / hamburger menu to mobile (#8)
* added id for sponsors and added hamburger menu
1 parent e552db1 commit edf4e7c

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

components/Hamburger.tsx

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import { AnimatePresence, motion, useCycle } from 'framer-motion';
3+
import Link from 'next/link';
4+
5+
export default function Hamburger() {
6+
const [isOpen, toggleOpen] = useCycle(false, true);
7+
8+
return (
9+
<button
10+
onClick={() => {
11+
toggleOpen();
12+
}}
13+
>
14+
<svg
15+
className="w-10 h-10"
16+
fill="none"
17+
stroke="currentColor"
18+
viewBox="0 0 24 24"
19+
xmlns="http://www.w3.org/2000/svg"
20+
>
21+
<path
22+
strokeLinecap="round"
23+
strokeLinejoin="round"
24+
strokeWidth={2}
25+
d="M4 6h16M4 12h16m-7 6h7"
26+
/>
27+
</svg>
28+
<AnimatePresence>
29+
{isOpen && (
30+
<motion.div
31+
initial={{ opacity: 0, y: -10 }}
32+
animate={{ opacity: 1, y: 0 }}
33+
exit={{ opacity: 0, y: -10 }}
34+
transition={{ duration: 0.2 }}
35+
className="absolute top-16 right-0 bg-[#3977F9] p-4 shadow-lg w-40 rounded-2xl"
36+
>
37+
<ul>
38+
<li className="py-2 text-lg">
39+
<Link href={'./about'}>About Us</Link>
40+
</li>
41+
<li className="py-2 text-lg">
42+
<Link href={'./events'}>Events</Link>
43+
</li>
44+
<li className="py-2 text-lg">
45+
<Link href={'./resources'}>Resources</Link>
46+
</li>
47+
<li className="py-2 text-lg">
48+
<Link href={'./sponsors'}>Sponsors</Link>
49+
</li>
50+
</ul>
51+
</motion.div>
52+
)}
53+
</AnimatePresence>
54+
</button>
55+
);
56+
}

components/Navbar.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Image from 'next/image';
22
import Link from 'next/link';
33
import { useEffect, useState } from 'react';
4+
import Hamburger from './Hamburger';
45

56
const Navbar = () => {
67
const [path, setPath] = useState<string>('');
@@ -28,7 +29,7 @@ const Navbar = () => {
2829
<p className="text-[0.6rem] text-[#C4C5C8]">01</p>
2930
<div>{'//'} about us</div>
3031
</Link>
31-
<Link href="events">
32+
<Link href="#events">
3233
<p className="text-[0.6rem] text-[#C4C5C8]">02</p>
3334
<div>{'//'} events</div>
3435
</Link>
@@ -41,6 +42,9 @@ const Navbar = () => {
4142
<div>{'//'} sponsors</div>
4243
</Link>
4344
</div>
45+
<div className="md:hidden xl:hidden lg:hidden text-right font-bold block">
46+
<Hamburger />
47+
</div>
4448
</div>
4549
</nav>
4650
);

components/Sponsors/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const Sponsors = () => {
99
'xl:p-16 p-10 flex justify-center items-center xl:col-span-3 sm:col-span-5 col-span-10 xl:row-start-2 xl:row-end-3 sm:row-start-4 sm:row-end-5 sm:h-auto h-36';
1010

1111
return (
12-
<section className="flex flex-col min-h-screen py-8 xl:px-24 sm:px-10 px-8 relative mt-20">
12+
<section
13+
className="flex flex-col min-h-screen py-8 xl:px-24 sm:px-10 px-8 relative mt-20"
14+
id="sponsors"
15+
>
1316
<div className="text-center">
1417
<p className="text-[#3977F8] font-game text-xl">04</p>
1518
<h2 className="font-bold text-6xl">SUPPORT CSESOC</h2>

package-lock.json

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@types/react-dom": "18.2.7",
2020
"autoprefixer": "10.4.15",
2121
"eslint-config-next": "13.4.19",
22+
"framer-motion": "^11.1.2",
2223
"next": "13.4.19",
2324
"postcss": "8.4.29",
2425
"react": "18.2.0",

0 commit comments

Comments
 (0)