Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Add Navbar #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading