Files
frigate/web/src/components/navigation/NavItem.tsx
T

77 lines
1.7 KiB
TypeScript
Raw Normal View History

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";
import { cn } from "@/lib/utils";
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: {
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) {
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 }) =>
cn(
2025-11-17 08:12:05 -06:00
"flex flex-col items-center justify-center rounded-lg p-[6px]",
className,
2026-06-04 10:56:11 -05:00
large && "size-12",
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">
<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
}