Files
frigate/web/src/components/indicators/Chip.tsx
T

83 lines
2.1 KiB
TypeScript
Raw Normal View History

import { cn } from "@/lib/utils";
2024-04-07 14:36:08 -06:00
import { LogSeverity } from "@/types/log";
2026-03-05 08:42:38 -06:00
import { ReactNode, useMemo } from "react";
import { isIOS } from "react-device-detect";
2026-03-05 08:42:38 -06:00
import { AnimatePresence, motion } from "framer-motion";
2026-07-17 20:30:02 +08:00
import { useTranslation } from "react-i18next";
2024-02-10 05:30:53 -07:00
type ChipProps = {
className?: string;
2024-03-10 07:25:16 -06:00
children?: ReactNode | ReactNode[];
2024-02-10 05:30:53 -07:00
in?: boolean;
2024-03-10 07:25:16 -06:00
onClick?: () => void;
2024-02-10 05:30:53 -07:00
};
export default function Chip({
className,
children,
in: inProp = true,
2024-03-10 07:25:16 -06:00
onClick,
2024-02-10 05:30:53 -07:00
}: ChipProps) {
return (
2026-03-05 08:42:38 -06:00
<AnimatePresence>
{inProp && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.5, ease: "easeInOut" }}
className={cn(
"flex items-center rounded-2xl px-2 py-1.5",
className,
!isIOS && "z-10",
)}
onClick={(e) => {
e.stopPropagation();
2024-06-23 14:58:00 -06:00
2026-03-05 08:42:38 -06:00
if (onClick) {
onClick();
}
}}
>
{children}
</motion.div>
)}
</AnimatePresence>
2024-02-10 05:30:53 -07:00
);
}
2024-04-07 14:36:08 -06:00
type LogChipProps = {
severity: LogSeverity;
onClickSeverity?: () => void;
};
export function LogChip({ severity, onClickSeverity }: LogChipProps) {
2026-07-17 20:30:02 +08:00
const { t } = useTranslation(["views/settings"]);
2024-04-07 14:36:08 -06:00
const severityClassName = useMemo(() => {
switch (severity) {
case "info":
return "text-primary/60 bg-secondary hover:bg-secondary/60";
2024-04-07 14:36:08 -06:00
case "warning":
return "text-warning-foreground bg-warning hover:bg-warning/80";
case "error":
return "text-destructive-foreground bg-destructive hover:bg-destructive/80";
}
}, [severity]);
return (
2025-02-10 09:38:56 -06:00
<div className="min-w-16 lg:min-w-20">
<span
className={`rounded-md px-1 py-[1px] text-xs smart-capitalize ${onClickSeverity ? "cursor-pointer" : ""} ${severityClassName}`}
2025-02-10 09:38:56 -06:00
onClick={(e) => {
e.stopPropagation();
2024-04-07 14:36:08 -06:00
2025-02-10 09:38:56 -06:00
if (onClickSeverity) {
onClickSeverity();
}
}}
>
2026-07-17 20:30:02 +08:00
{t(`logger.logLevel.${severity}`, { ns: "views/settings" })}
2025-02-10 09:38:56 -06:00
</span>
2024-04-07 14:36:08 -06:00
</div>
);
}