Files
frigate/web/src/components/dynamic/CameraFeatureToggle.tsx
T

89 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-03-01 17:43:02 -07:00
import { IconType } from "react-icons";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { isDesktop } from "react-device-detect";
import { cn } from "@/lib/utils";
import ActivityIndicator from "../indicators/activity-indicator";
2024-03-01 17:43:02 -07:00
const variants = {
primary: {
active: "font-bold text-white bg-selected rounded-lg",
inactive: "text-secondary-foreground bg-secondary rounded-lg",
2025-03-03 09:30:52 -06:00
disabled:
"text-secondary-foreground bg-secondary rounded-lg cursor-not-allowed opacity-50",
2024-03-01 17:43:02 -07:00
},
overlay: {
active: "font-bold text-white bg-selected rounded-full",
2024-03-05 13:00:27 +00:00
inactive:
"text-primary rounded-full bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500",
2025-03-03 09:30:52 -06:00
disabled:
"bg-gradient-to-br from-gray-400 to-gray-500 bg-gray-500 rounded-full cursor-not-allowed opacity-50",
2024-03-01 17:43:02 -07:00
},
};
type CameraFeatureToggleProps = {
className?: string;
variant?: "primary" | "overlay";
2024-03-01 17:43:02 -07:00
isActive: boolean;
Icon: IconType;
title: string;
onClick?: () => void;
disabled?: boolean;
loading?: boolean;
2024-03-01 17:43:02 -07:00
};
export default function CameraFeatureToggle({
className = "",
variant = "primary",
isActive,
Icon,
title,
onClick,
disabled = false,
loading = false,
2024-03-01 17:43:02 -07:00
}: CameraFeatureToggleProps) {
const content = (
<div
2025-03-03 09:30:52 -06:00
onClick={disabled ? undefined : onClick}
className={cn(
2024-05-14 10:06:44 -05:00
"flex flex-col items-center justify-center",
2025-03-03 09:30:52 -06:00
disabled
? variants[variant].disabled
: variants[variant][isActive ? "active" : "inactive"],
2025-02-10 10:42:35 -06:00
className,
)}
2024-03-01 17:43:02 -07:00
>
{loading ? (
<ActivityIndicator className="size-5 md:m-[6px]" />
) : (
<Icon
className={cn(
"size-5 md:m-[6px]",
disabled
? "text-gray-400"
: isActive
? "text-white"
: "text-secondary-foreground",
)}
/>
)}
2024-03-01 17:43:02 -07:00
</div>
);
if (isDesktop) {
return (
<Tooltip>
2025-03-03 09:30:52 -06:00
<TooltipTrigger disabled={disabled}>{content}</TooltipTrigger>
2024-03-01 17:43:02 -07:00
<TooltipContent side="bottom">
<p>{title}</p>
</TooltipContent>
</Tooltip>
);
}
return content;
}