2024-04-18 11:22:43 +01:00
|
|
|
"use client";
|
|
|
|
|
2024-04-14 18:46:37 +01:00
|
|
|
import Link from "next/link";
|
2024-04-18 11:22:43 +01:00
|
|
|
import { usePathname } from "next/navigation";
|
2024-04-22 02:11: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-20 02:35:52 +01:00
|
|
|
import { cn } from "@/app/common/utils";
|
2024-04-22 01:21:04 +01:00
|
|
|
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 {
|
2024-04-22 01:21:04 +01:00
|
|
|
const path: string = usePathname();
|
|
|
|
const isDocs: boolean = path ? path.includes("/docs") : false;
|
2024-04-18 11:22:43 +01:00
|
|
|
|
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-22 01:21:04 +01:00
|
|
|
<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>
|
2024-04-22 01:21:04 +01:00
|
|
|
|
|
|
|
{/* 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 */}
|
2024-04-22 01:21:04 +01:00
|
|
|
<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) => {
|
2024-04-21 17:13:46 +01:00
|
|
|
const isActive: boolean = path ? path.includes(page.url) : false;
|
2024-04-18 11:22:43 +01:00
|
|
|
|
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>
|
2024-04-18 05:18:25 +01:00
|
|
|
</div>
|
2024-04-16 19:27:48 +01:00
|
|
|
|
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-22 01:21:04 +01:00
|
|
|
<GithubStar className={isDocs ? "hidden md:flex" : "hidden"} />
|
2024-04-16 19:27:48 +01:00
|
|
|
</div>
|
2024-04-19 21:53:11 +01:00
|
|
|
</Card>
|
2024-04-14 18:46:37 +01:00
|
|
|
);
|
|
|
|
}
|