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

78 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-01-23 19:58:37 +00:00
import MuiBreadcrumbs from "@mui/material/Breadcrumbs";
import Typography from "@mui/material/Typography";
import { Link, useLocation } from "react-router-dom";
import { useTheme } from "@mui/material/styles";
2026-01-24 20:41:21 +00:00
import { ChevronRight } from "lucide-react";
2026-01-23 19:58:37 +00:00
2026-01-24 20:41:21 +00:00
const isId = (segment: string): boolean => {
return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment);
};
export const Breadcrumb = () => {
2026-01-23 19:58:37 +00:00
const theme = useTheme();
const location = useLocation();
2026-01-24 20:41:21 +00:00
const segments = location.pathname.split("/").filter((x) => x);
2026-01-23 19:58:37 +00:00
2026-01-24 20:41:21 +00:00
// Build simplified breadcrumb: "uptime" or "uptime / details"
const basePage = segments[0] || "home";
const hasDetailsPage = segments.length > 1 && isId(segments[1]);
2026-01-23 19:58:37 +00:00
return (
<MuiBreadcrumbs
separator={
<ChevronRight
size={16}
strokeWidth={1.5}
/>
}
sx={{
fontSize: "14px",
marginBottom: theme.spacing(6),
"& .MuiBreadcrumbs-separator": {
color: theme.palette.text.secondary,
},
}}
>
2026-01-24 20:41:21 +00:00
{hasDetailsPage ? (
<Link
to={`/${basePage}`}
style={{ textDecoration: "none" }}
2026-01-23 19:58:37 +00:00
>
<Typography
sx={{
fontSize: "14px",
2026-01-24 20:41:21 +00:00
color: theme.palette.text.secondary,
"&:hover": {
color: theme.palette.primary.main,
},
2026-01-23 19:58:37 +00:00
}}
>
2026-01-24 20:41:21 +00:00
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
2026-01-23 19:58:37 +00:00
</Typography>
2026-01-24 20:41:21 +00:00
</Link>
) : (
<Typography
sx={{
fontSize: "14px",
fontWeight: 600,
color: theme.palette.primary.main,
}}
>
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
</Typography>
)}
{hasDetailsPage && (
<Typography
sx={{
fontSize: "14px",
fontWeight: 600,
color: theme.palette.primary.main,
}}
>
Details
</Typography>
)}
2026-01-23 19:58:37 +00:00
</MuiBreadcrumbs>
);
};