Files
Frontend/src/app/components/navbar.tsx

91 lines
2.6 KiB
TypeScript
Raw Normal View History

"use client";
2024-04-14 18:46:37 +01:00
import Link from "next/link";
import { usePathname } from "next/navigation";
import { ReactElement } from "react";
2024-04-18 07:46:22 +01:00
import { HrefButton } from "./href-button";
2024-04-14 18:46:37 +01:00
import Logo from "./logo";
2024-04-16 21:18:08 +01:00
import { ToggleThemeButton } from "./theme-toggle-button";
2024-04-19 15:22:03 +01:00
import { GithubStar } from "@/app/components/github-star";
2024-04-19 21:53:11 +01:00
import { Card } from "@/app/components/card";
2024-04-20 02:35:52 +01:00
import { cn } from "@/app/common/utils";
import { CommandMenu } from "@/app/components/command-menu";
2024-04-14 18:46:37 +01:00
type Page = {
2024-04-18 07:06:16 +01:00
/**
* The name of the button for the navbar.
*/
name: string;
/**
* The URL to go to.
*/
2024-04-14 18:46:37 +01:00
url: string;
2024-04-18 07:06:16 +01:00
2024-04-20 00:44:40 +01:00
/**
* Whether to hide the button on mobile.
*/
hideOnMobile?: boolean;
2024-04-18 07:06:16 +01:00
/**
* Whether clicking the button will
* open the link in a new tab.
*/
2024-04-18 01:45:27 +01:00
openInNewTab?: boolean;
2024-04-14 18:46:37 +01:00
};
const pages: Page[] = [
2024-04-18 07:06:16 +01:00
{ name: "Player", url: "/player" },
{ name: "Server", url: "/server/java" },
{ name: "Mojang", url: "/mojang/status" },
2024-04-20 00:44:40 +01:00
{ name: "API", url: "https://api.mcutils.xyz", hideOnMobile: true, openInNewTab: true },
2024-04-20 22:18:50 +01:00
{ name: "Docs", url: "/docs" },
2024-04-14 18:46:37 +01:00
];
2024-04-18 03:51:41 +01:00
export default function NavBar(): ReactElement {
const path: string = usePathname();
const isDocs: boolean = path ? path.includes("/docs") : false;
2024-04-14 18:46:37 +01:00
return (
2024-04-19 21:53:11 +01:00
<Card
classNameCard="w-full p-0 mt-2 border-none"
classNameContent="p-0 relative rounded-lg flex justify-between items-center gap-3 px-3 bg-opacity-85 h-12"
>
2024-04-19 15:29:26 +01:00
{/* Left */}
<div className={cn("flex flex-row items-center gap-2 z-50", isDocs ? "w-full md:w-fit" : "w-fit")}>
2024-04-19 15:41:35 +01:00
<Link href="/" className="flex items-center gap-2">
<Logo />
</Link>
{/* Command Menu */}
<CommandMenu className={cn(isDocs ? "" : "hidden md:inline-flex")} />
2024-04-19 15:41:35 +01:00
</div>
2024-04-18 03:32:38 +01:00
2024-04-19 15:29:26 +01:00
{/* Links */}
<div className={cn("absolute inset-x-0 justify-center", isDocs ? "hidden md:flex" : "flex")}>
2024-04-19 15:29:26 +01:00
<div className="flex gap-4">
{pages.map((page, index) => {
const isActive: boolean = path ? path.includes(page.url) : false;
2024-04-19 15:29:26 +01:00
return (
<HrefButton
2024-04-20 00:44:40 +01:00
className={cn(isActive ? "text-primary" : "", page.hideOnMobile ? "hidden md:block" : "")}
2024-04-19 15:29:26 +01:00
key={index}
title={page.name}
url={page.url}
openInNewTab={page.openInNewTab}
/>
);
})}
</div>
</div>
2024-04-19 15:29:26 +01:00
{/* Right */}
2024-04-19 15:41:35 +01:00
<div className="flex gap-4 items-center z-50">
2024-04-16 21:18:08 +01:00
<ToggleThemeButton />
<GithubStar className={isDocs ? "hidden md:flex" : "hidden"} />
</div>
2024-04-19 21:53:11 +01:00
</Card>
2024-04-14 18:46:37 +01:00
);
}