Frontend/src/app/components/navbar.tsx

78 lines
1.9 KiB
TypeScript
Raw Normal View History

"use client";
2024-04-14 17:46:37 +00:00
import Link from "next/link";
import { usePathname } from "next/navigation";
2024-04-18 02:51:41 +00:00
import { ReactElement } from "react";
2024-04-18 06:46:22 +00:00
import { HrefButton } from "./href-button";
2024-04-14 17:46:37 +00:00
import Logo from "./logo";
2024-04-16 20:18:08 +00:00
import { ToggleThemeButton } from "./theme-toggle-button";
2024-04-14 17:46:37 +00:00
type Page = {
2024-04-18 06:06:16 +00:00
/**
* The name of the button for the navbar.
*/
name: string;
/**
* The URL to go to.
*/
2024-04-14 17:46:37 +00:00
url: string;
2024-04-18 06:06:16 +00:00
/**
* Whether clicking the button will
* open the link in a new tab.
*/
2024-04-18 00:45:27 +00:00
openInNewTab?: boolean;
2024-04-14 17:46:37 +00:00
};
const pages: Page[] = [
2024-04-18 06:06:16 +00:00
{ name: "Player", url: "/player" },
{ name: "Server", url: "/server/java" },
{ name: "Mojang", url: "/mojang/status" },
{ name: "API", url: "https://api.mcutils.xyz", openInNewTab: true },
2024-04-14 17:46:37 +00:00
];
2024-04-18 02:51:41 +00:00
export default function NavBar(): ReactElement {
const path = usePathname();
2024-04-14 17:46:37 +00:00
return (
<div className="bg-secondary w-full rounded-lg flex items-center gap-3 mt-2 bg-opacity-85 h-12">
<Link href="/" className="flex items-center gap-2 pl-3 pr-1">
2024-04-14 17:46:37 +00:00
<Logo />
2024-04-18 02:16:05 +00:00
<p className="hidden md:block">Minecraft Utilities</p>
2024-04-16 21:07:43 +00:00
</Link>
2024-04-18 02:32:38 +00:00
2024-04-18 06:06:16 +00:00
<div className="flex-grow" />
2024-04-18 02:32:38 +00:00
<div className="flex gap-4">
{pages.map((page, index) => {
const isActive = path.includes(page.url);
return (
<HrefButton
className={isActive ? "text-primary" : ""}
key={index}
title={page.name}
url={page.url}
openInNewTab={page.openInNewTab}
/>
);
})}
</div>
2024-04-18 06:06:16 +00:00
<div className="flex-grow" />
2024-04-16 20:18:08 +00:00
<div className="mr-4 flex items-center gap-2">
2024-04-16 21:50:42 +00:00
<div className="hidden md:block">
2024-04-18 06:46:22 +00:00
<HrefButton
2024-04-16 20:40:56 +00:00
title="Star us on Github!"
url="https://github.com/RealFascinated/minecraft-helper"
openInNewTab
/>
</div>
2024-04-16 20:18:08 +00:00
<ToggleThemeButton />
</div>
2024-04-14 17:46:37 +00:00
</div>
);
}