Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/ui/breadcrumbs/Breadcrumb.tsx
T

79 lines
2.8 KiB
TypeScript

import { Link, useParams } from "react-router";
import clsx from "clsx";
import { useTranslation } from "react-i18next";
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
import UrlUtils from "~/utils/app/UrlUtils";
import { HomeIcon } from "~/components/ui/icons/vendor";
interface MenuItem {
title: string;
routePath?: string;
}
interface Props {
menu: MenuItem[];
className?: string;
home?: string;
}
export default function Breadcrumb({ className = "", home = "", menu = [] }: Props) {
const params = useParams();
const { t } = useTranslation();
function getHomeItem() {
if (params.tenant) {
return UrlUtils.currentTenantUrl(params, "dashboard");
} else {
return adminPath("dashboard", { mode: "host-aware" });
}
}
return (
<nav className={clsx(className, "border-border-default bg-surface-neutral-primary flex overflow-x-auto border-b")} aria-label={t("components.breadcrumb.ariaLabel")}>
<ol className="flex w-full max-w-(--breakpoint-xl) space-x-4 px-4 sm:px-6 lg:px-8">
<li className="flex">
<div className="flex items-center">
<Link to={home.length > 0 ? home : getHomeItem()} className="hover:text-text-neutral-tertiary text-text-neutral-tertiary">
<HomeIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
<span className="sr-only">{t("shared.home")}</span>
</Link>
</div>
</li>
{menu.map((item, idx) => {
return (
<li key={idx} className="flex">
<div className="flex items-center">
<svg
className="h-full w-5 shrink-0 text-gray-200 sm:w-6"
viewBox="0 0 24 44"
preserveAspectRatio="none"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
>
<path d="M.293 0l22 22-22 22h1.414l22-22-22-22H.293z" />
</svg>
{/* Subframe Breadcrumbs typo: 14px/normal item text (font-[400] leading-[20px]) */}
{(() => {
if (!item.routePath) {
return (
<div className="text-text-neutral-tertiary hover:text-text-neutral-primary ml-2 select-none truncate text-sm font-normal leading-5 sm:ml-4">
{item.title}
</div>
);
} else {
return (
<Link to={item.routePath} className="text-text-neutral-tertiary hover:text-text-neutral-primary ml-2 truncate text-sm font-normal leading-5 sm:ml-4">
{item.title}
</Link>
);
}
})()}
</div>
</li>
);
})}
</ol>
</nav>
);
}