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