Files
zitadel/apps/login/ui/GlobalNav.tsx

103 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-04-14 17:22:59 +02:00
"use client";
2023-04-03 13:39:51 +02:00
2023-04-14 17:22:59 +02:00
import { demos, type Item } from "#/lib/demos";
import { ZitadelLogo } from "#/ui/ZitadelLogo";
import Link from "next/link";
import { useSelectedLayoutSegment } from "next/navigation";
import clsx from "clsx";
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/solid";
import { useState } from "react";
2023-04-03 13:39:51 +02:00
export function GlobalNav() {
const [isOpen, setIsOpen] = useState(false);
const close = () => setIsOpen(false);
return (
2023-04-24 09:54:47 +02:00
<div className="fixed top-0 z-10 flex w-full flex-col border-b border-divider-light dark:border-divider-dark bg-background-light-700 dark:bg-background-dark-700 lg:bottom-0 lg:z-auto lg:w-72 lg:border-r">
2023-04-03 13:39:51 +02:00
<div className="flex h-14 items-center py-4 px-4 lg:h-auto">
<Link
href="/"
className="group flex w-full items-center space-x-2.5"
onClick={close}
>
2023-04-14 17:22:59 +02:00
<div className="">
2023-04-03 13:39:51 +02:00
<ZitadelLogo />
</div>
2023-04-19 10:37:35 +02:00
<h2 className="text-blue-500 font-bold uppercase transform translate-y-2 text-sm">
2023-04-14 17:22:59 +02:00
Login
2023-04-03 13:39:51 +02:00
</h2>
</Link>
</div>
<button
type="button"
className="group absolute right-0 top-0 flex h-14 items-center space-x-2 px-4 lg:hidden"
onClick={() => setIsOpen(!isOpen)}
>
<div className="font-medium text-gray-100 group-hover:text-gray-400">
Menu
</div>
{isOpen ? (
<XMarkIcon className="block w-6 text-gray-300" />
) : (
<Bars3Icon className="block w-6 text-gray-300" />
)}
</button>
<div
2023-04-14 17:22:59 +02:00
className={clsx("overflow-y-auto lg:static lg:block", {
"fixed inset-x-0 bottom-0 top-14 mt-px bg-white dark:bg-black":
isOpen,
2023-04-03 13:39:51 +02:00
hidden: !isOpen,
})}
>
<nav className="space-y-6 px-2 py-5">
{demos.map((section) => {
return (
<div key={section.name}>
2023-04-25 09:16:19 +02:00
<div className="mb-2 px-3 text-xs font-semibold uppercase tracking-wider text-text-light dark:text-text-dark">
2023-04-03 13:39:51 +02:00
<div>{section.name}</div>
</div>
<div className="space-y-1">
{section.items.map((item) => (
<GlobalNavItem key={item.slug} item={item} close={close} />
))}
</div>
</div>
);
})}
</nav>
</div>
</div>
);
}
function GlobalNavItem({
item,
close,
}: {
item: Item;
close: () => false | void;
}) {
const segment = useSelectedLayoutSegment();
const isActive = item.slug === segment;
return (
<Link
onClick={close}
href={`/${item.slug}`}
className={clsx(
2023-04-14 17:22:59 +02:00
"block rounded-md px-3 py-2 text-sm font-medium hover:text-black dark:hover:text-gray-300",
2023-04-03 13:39:51 +02:00
{
2023-04-25 09:16:19 +02:00
"text-text-light-secondary dark:text-text-dark-secondary hover:text-text-light hover:dark:text-text-dark":
2023-04-14 17:22:59 +02:00
!isActive,
2023-04-25 09:16:19 +02:00
"text-primary-light-500 dark:text-primary-dark-500": isActive,
2023-04-14 17:22:59 +02:00
}
2023-04-03 13:39:51 +02:00
)}
>
{item.name}
</Link>
);
}