53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import Link from "next/link";
|
|
import { MenuIcon, XIcon } from "lucide-react";
|
|
import { Button } from "./ui/button";
|
|
import { login } from "@/lib/user/actions";
|
|
import Image from "next/image";
|
|
|
|
type NavLink = { id: string; href: string; label: string };
|
|
|
|
export function MobileNav({ links, isAuthenticated }: { links: NavLink[]; isAuthenticated: boolean }) {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
return (
|
|
<div className="md:hidden">
|
|
<Button variant="ghost" size="icon" onClick={() => setOpen(true)} aria-label="Open menu">
|
|
<MenuIcon />
|
|
</Button>
|
|
{open && (
|
|
<div className="fixed inset-0 z-50 bg-white flex flex-col">
|
|
<div className="flex items-center justify-between h-16 px-4">
|
|
<Link href="/" onClick={() => setOpen(false)} className="flex items-center gap-4 shrink-0">
|
|
<Image src="/emblem.png" width={28} height={28} alt="Emblem of the European Federation" />
|
|
<h3 className="hidden sm:block">European Federation</h3>
|
|
</Link>
|
|
<Button variant="ghost" size="icon" onClick={() => setOpen(false)} aria-label="Close menu">
|
|
<XIcon />
|
|
</Button>
|
|
</div>
|
|
<nav className="flex flex-col gap-2.5 p-4">
|
|
{links.map((link) => (
|
|
<Link key={link.id} href={link.href} onClick={() => setOpen(false)} className="hover:underline underline-offset-8 decoration-2 duration-200">
|
|
<h2>{link.label}</h2>
|
|
</Link>
|
|
))}
|
|
<div className="mt-4">
|
|
{isAuthenticated ? (
|
|
<Link href="/account" onClick={() => setOpen(false)}>
|
|
<Button>Account</Button>
|
|
</Link>
|
|
) : (
|
|
<form action={login}>
|
|
<Button size="lg" type="submit">Sign in with Kotosoft ID</Button>
|
|
</form>
|
|
)}
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
} |