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

81 lines
2.0 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";
2024-04-18 03:51:41 +01:00
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-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
/**
* 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:40:08 +01:00
{ name: "API", url: "https://api.mcutils.xyz", openInNewTab: true },
{ name: "Docs", url: "/documentation" },
2024-04-14 18:46:37 +01:00
];
2024-04-18 03:51:41 +01:00
export default function NavBar(): ReactElement {
const path = usePathname();
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 */}
2024-04-19 15:41:35 +01:00
<div className="z-50">
<Link href="/" className="flex items-center gap-2">
<Logo />
<p className="hidden lg:block text-lg font-semibold">Minecraft Utilities</p>
2024-04-19 15:41:35 +01:00
</Link>
</div>
2024-04-18 03:32:38 +01:00
2024-04-19 15:29:26 +01:00
{/* Links */}
2024-04-19 22:32:11 +01:00
<div className="absolute inset-x-0 flex justify-center">
2024-04-19 15:29:26 +01:00
<div className="flex gap-4">
{pages.map((page, index) => {
const isActive = path.includes(page.url);
2024-04-19 15:29:26 +01:00
return (
<HrefButton
className={isActive ? "text-primary" : ""}
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 />
2024-04-19 15:22:03 +01:00
<GithubStar />
</div>
2024-04-19 21:53:11 +01:00
</Card>
2024-04-14 18:46:37 +01:00
);
}