38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { useLocation } from "react-router";
|
|
import clsx from "clsx";
|
|
import UrlUtils from "~/utils/app/UrlUtils";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
export default function HeadingWithTabs({ tabs }: { tabs: { name: string; href: string }[] }) {
|
|
const { t } = useTranslation();
|
|
const location = useLocation();
|
|
function isCurrent(idx: number) {
|
|
return currentTab() === tabs[idx];
|
|
}
|
|
const currentTab = () => {
|
|
return tabs.find((element) => element.href && UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.stripTrailingSlash(element.href));
|
|
};
|
|
return (
|
|
<div className="w-full sm:flex sm:items-baseline">
|
|
<h3 className="text-text-neutral-primary text-lg font-medium leading-6">{t("components.tabs.headingWithTabs.issues")}</h3>
|
|
<div className="mt-4 sm:ml-10 sm:mt-0">
|
|
<nav className="-mb-px flex space-x-8">
|
|
{tabs.map((tab, idx) => (
|
|
<a
|
|
key={tab.name}
|
|
href={tab.href}
|
|
className={clsx(
|
|
isCurrent(idx) ? "border-theme-500 text-theme-600" : "hover:border-border-default text-text-neutral-tertiary hover:text-text-neutral-primary/80 border-transparent",
|
|
"whitespace-nowrap border-b-2 px-1 pb-4 text-sm font-medium"
|
|
)}
|
|
aria-current={isCurrent(idx) ? "page" : undefined}
|
|
>
|
|
{tab.name}
|
|
</a>
|
|
))}
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|