Files
Checkmate/client/src/Components/design-elements/OfflineBanner.tsx
T

63 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-02-10 17:53:00 +00:00
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import { useTheme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
import { WifiOff } from "lucide-react";
2026-02-10 23:53:06 +00:00
import { useState, useEffect } from "react";
2026-02-10 17:53:00 +00:00
interface OfflineBannerProps {
visible: boolean;
}
2026-02-10 23:53:06 +00:00
export const OfflineBanner = ({ visible }: OfflineBannerProps) => {
2026-02-10 17:53:00 +00:00
const theme = useTheme();
const { t } = useTranslation();
2026-02-10 23:53:06 +00:00
const [shouldRender, setShouldRender] = useState(visible);
const [isAnimating, setIsAnimating] = useState(false);
2026-02-10 17:53:00 +00:00
2026-02-10 23:53:06 +00:00
useEffect(() => {
if (visible) {
setShouldRender(true);
requestAnimationFrame(() => setIsAnimating(true));
} else {
setIsAnimating(false);
const timer = setTimeout(() => setShouldRender(false), 1000);
return () => clearTimeout(timer);
}
}, [visible]);
if (!shouldRender) return null;
2026-02-10 17:53:00 +00:00
return (
<Box
sx={{
position: "fixed",
2026-02-10 23:53:06 +00:00
top: isAnimating ? 0 : "-100%",
2026-02-10 17:53:00 +00:00
left: 0,
right: 0,
zIndex: theme.zIndex.snackbar,
backgroundColor: theme.palette.error.main,
color: theme.palette.error.contrastText,
px: theme.spacing(8),
py: theme.spacing(4),
2026-02-10 23:53:06 +00:00
transition: "top 1s ease-in-out",
2026-02-10 17:53:00 +00:00
}}
>
<Stack
direction="row"
alignItems="center"
justifyContent="center"
gap={theme.spacing(4)}
>
<WifiOff size={20} />
<Typography
variant="body2"
fontWeight={500}
>
{t("components.offlineBanner.serverUnreachable")}
</Typography>
</Stack>
</Box>
);
};