2024-02-27 14:39:05 -07:00
|
|
|
import { NavLink } from "react-router-dom";
|
|
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "@/components/ui/tooltip";
|
2024-02-29 17:59:26 -07:00
|
|
|
import { isDesktop } from "react-device-detect";
|
2024-03-04 07:34:23 -06:00
|
|
|
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
2024-04-11 14:54:09 -06:00
|
|
|
import { NavData } from "@/types/navigation";
|
|
|
|
|
import { IconType } from "react-icons";
|
2024-05-07 09:00:25 -05:00
|
|
|
import { cn } from "@/lib/utils";
|
2025-03-16 23:36:20 +08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-02-27 14:39:05 -07:00
|
|
|
|
|
|
|
|
const variants = {
|
|
|
|
|
primary: {
|
2024-04-16 14:55:24 -06:00
|
|
|
active: "font-bold text-white bg-selected hover:bg-selected/80",
|
|
|
|
|
inactive: "text-secondary-foreground bg-secondary hover:bg-muted",
|
2024-02-27 14:39:05 -07:00
|
|
|
},
|
|
|
|
|
secondary: {
|
2024-03-02 08:00:50 -07:00
|
|
|
active: "font-bold text-selected",
|
2024-04-04 14:55:04 -06:00
|
|
|
inactive: "text-secondary-foreground",
|
2024-02-27 14:39:05 -07:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type NavItemProps = {
|
2024-04-11 14:54:09 -06:00
|
|
|
className?: string;
|
|
|
|
|
item: NavData;
|
2024-02-27 14:39:05 -07:00
|
|
|
Icon: IconType;
|
|
|
|
|
onClick?: () => void;
|
2026-06-04 10:56:11 -05:00
|
|
|
large?: boolean;
|
2024-02-27 14:39:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function NavItem({
|
|
|
|
|
className,
|
2024-04-11 14:54:09 -06:00
|
|
|
item,
|
2024-02-27 14:39:05 -07:00
|
|
|
Icon,
|
|
|
|
|
onClick,
|
2026-06-04 10:56:11 -05:00
|
|
|
large,
|
2024-02-27 14:39:05 -07:00
|
|
|
}: NavItemProps) {
|
2025-03-16 23:36:20 +08:00
|
|
|
const { t } = useTranslation(["common"]);
|
2024-04-11 14:54:09 -06:00
|
|
|
if (item.enabled == false) {
|
2024-03-04 16:18:30 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2024-02-29 17:59:26 -07:00
|
|
|
|
2024-03-04 16:18:30 -07:00
|
|
|
const content = (
|
|
|
|
|
<NavLink
|
2024-04-11 14:54:09 -06:00
|
|
|
to={item.url}
|
2024-03-04 16:18:30 -07:00
|
|
|
onClick={onClick}
|
|
|
|
|
className={({ isActive }) =>
|
2024-05-07 09:00:25 -05:00
|
|
|
cn(
|
2025-11-17 08:12:05 -06:00
|
|
|
"flex flex-col items-center justify-center rounded-lg p-[6px]",
|
2024-05-07 09:00:25 -05:00
|
|
|
className,
|
2026-06-04 10:56:11 -05:00
|
|
|
large && "size-12",
|
2024-05-07 09:00:25 -05:00
|
|
|
variants[item.variant ?? "primary"][isActive ? "active" : "inactive"],
|
|
|
|
|
)
|
2024-03-04 16:18:30 -07:00
|
|
|
}
|
|
|
|
|
>
|
2026-06-04 10:56:11 -05:00
|
|
|
<Icon className={large ? "size-6" : "size-5"} />
|
2024-03-04 16:18:30 -07:00
|
|
|
</NavLink>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isDesktop) {
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger>{content}</TooltipTrigger>
|
2024-03-04 07:34:23 -06:00
|
|
|
<TooltipPortal>
|
|
|
|
|
<TooltipContent side="right">
|
2025-03-16 23:36:20 +08:00
|
|
|
<p>{t(item.title)}</p>
|
2024-03-04 07:34:23 -06:00
|
|
|
</TooltipContent>
|
|
|
|
|
</TooltipPortal>
|
2024-02-27 14:39:05 -07:00
|
|
|
</Tooltip>
|
2024-03-04 16:18:30 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content;
|
2024-02-27 14:39:05 -07:00
|
|
|
}
|