Skip to content

Commit

Permalink
frontend: Add Navbar
Browse files Browse the repository at this point in the history
This adds a UNO themed navbar to the frontend. The navbar is responsive
and collapses into a hamburger menu on smaller screens.

It can have multiple links, which can be defined on use.

Fixes #19

Signed-off-by: Sagnik Mandal <[email protected]>
  • Loading branch information
criticic committed Jun 6, 2024
1 parent 19abe9b commit 5e27ae6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"fix-format": "prettier --write src"
},
"dependencies": {
"@heroicons/react": "^2.1.3",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"react": "^18.2.0",
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/Navbar.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions frontend/src/library/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Link } from 'react-router-dom';
import { useState } from 'react';
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/solid';
import { NavbarLink } from '../pages/AppLayout';

function NavbarItem({ link }: { link: NavbarLink }) {
return (
<Link
to={link.path}
className="text-[#ECD407] font-bold text-xl hover:underline"
>
{link.label}
</Link>
);
}

function Navbar({ links }: { links: NavbarLink[] }) {
const [menuOpen, setMenuOpen] = useState(false);

return (
<div className="flex flex-row sticky top-0 bg-[#D72600] p-3 shadow-md justify-between items-center">
<div className="text-[#ECD407] tracking-tight font-black text-4xl drop-shadow-[-7px_0px_0px_rgba(0,0,0,1)]">
<Link to="/">UNO</Link>
</div>
<div className="hidden md:flex space-x-4">
{links.map((link, index) => (
<NavbarItem key={index} link={link} />
))}
</div>
<div className="md:hidden flex items-center">
<button onClick={() => setMenuOpen(!menuOpen)}>
{menuOpen ? (
<XMarkIcon className="w-5 h-5 text-[#ECD407]" />
) : (
<Bars3Icon className="w-6 h-6 text-[#ECD407]" />
)}
</button>
</div>
{menuOpen && (
<div className="absolute top-16 left-0 w-full bg-[#D72600] p-3 flex flex-col space-y-4 md:hidden">
{links.map((link, index) => (
<NavbarItem key={index} link={link} />
))}
</div>
)}
</div>
);
}

export default Navbar;
13 changes: 11 additions & 2 deletions frontend/src/pages/AppLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Outlet } from 'react-router-dom';
import Navbar from '../Navbar';
import Navbar from '../library/Navbar';

export type NavbarLink = {
path: string;
label: string;
};

function AppLayout() {
const links: NavbarLink[] = [
{ path: '/about', label: 'About' },
{ path: '/play', label: 'Play' },
];
return (
<div>
<Navbar />
<Navbar links={links} />
<Outlet />
{/* todo: Add a footer component */}
</div>
Expand Down

0 comments on commit 5e27ae6

Please sign in to comment.