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

36 lines
835 B
TypeScript
Raw Normal View History

2023-04-27 13:23:13 +02:00
"use client";
2023-04-03 13:39:51 +02:00
2023-04-27 13:23:13 +02:00
import type { Item } from "#/ui/TabGroup";
import clsx from "clsx";
import Link from "next/link";
import { useSelectedLayoutSegment } from "next/navigation";
2023-04-03 13:39:51 +02:00
export const Tab = ({
path,
item: { slug, text },
}: {
path: string;
item: Item;
}) => {
const segment = useSelectedLayoutSegment();
2023-04-27 13:23:13 +02:00
const href = slug ? path + "/" + slug : path;
2023-04-03 13:39:51 +02:00
const isActive =
// Example home pages e.g. `/layouts`
(!slug && segment === null) ||
// Nested pages e.g. `/layouts/electronics`
segment === slug;
return (
<Link
href={href}
2023-04-27 13:23:13 +02:00
className={clsx("mt-2 mr-2 rounded-lg px-3 py-1 text-sm font-medium", {
"bg-gray-700 text-gray-100 hover:bg-gray-500 hover:text-white":
2023-04-03 13:39:51 +02:00
!isActive,
2023-04-27 13:23:13 +02:00
"bg-blue-500 text-white": isActive,
2023-04-03 13:39:51 +02:00
})}
>
{text}
</Link>
);
};