Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 5x 5x 5x 35x 5x 35x 36x 35x | import { ArrowBack, ArrowForward, SvgIconComponent } from "@mui/icons-material";
import { Box, IconButton, styled, Typography } from "@mui/material";
import { useTranslation } from "i18n";
import { DASHBOARD } from "i18n/namespaces";
import { ReactNode } from "react";
interface DashboardSectionHeaderProps {
icon: SvgIconComponent;
title: string;
// shown as a badge next to the title when greater than zero
count?: number;
// extra content shown before the arrows, e.g. a "manage" link
action?: ReactNode;
hasPrevious: boolean;
hasNext: boolean;
onPrevious: () => void;
onNext: () => void;
}
const Header = styled("div")(({ theme }) => ({
display: "flex",
alignItems: "flex-start",
justifyContent: "space-between",
gap: theme.spacing(1),
marginBottom: theme.spacing(1),
minHeight: 28,
}));
// one line of the title tall, so its content centres on the first line when the title wraps
const FirstLine = styled("span")({
display: "inline-flex",
alignItems: "center",
height: "1lh",
flexShrink: 0,
});
const Controls = styled("div")(({ theme }) => ({
// title typography so 1lh matches the title's first line, keeping the arrows level with it
...theme.typography.h2,
height: "1lh",
display: "flex",
alignItems: "center",
gap: 4,
// long translated titles must wrap rather than squash the arrows onto two lines
flexShrink: 0,
}));
export default function DashboardSectionHeader({
icon: Icon,
title,
count,
action,
hasPrevious,
hasNext,
onPrevious,
onNext,
}: DashboardSectionHeaderProps) {
const { t } = useTranslation([DASHBOARD]);
return (
<Header>
<Typography variant="h2" sx={{ display: "flex", alignItems: "flex-start", gap: 1 }}>
<FirstLine>
<Icon sx={{ fontSize: 20, color: "var(--mui-palette-primary-main)" }} />
</FirstLine>
<span>{title}</span>
{!!count && (
<FirstLine>
<Box
component="span"
sx={{
fontSize: 12,
fontWeight: 700,
color: "var(--mui-palette-text-secondary)",
background: "var(--mui-palette-grey-50)",
borderRadius: 999,
px: 1.125,
lineHeight: "20px",
}}
>
{count}
</Box>
</FirstLine>
)}
</Typography>
<Controls>
{action}
<IconButton
size="small"
onClick={onPrevious}
disabled={!hasPrevious}
color={hasPrevious ? "primary" : "default"}
aria-label={t("dashboard:prev_page_button_a11y")}
>
<ArrowBack fontSize="small" />
</IconButton>
<IconButton
size="small"
onClick={onNext}
disabled={!hasNext}
color={hasNext ? "primary" : "default"}
aria-label={t("dashboard:next_page_button_a11y")}
>
<ArrowForward fontSize="small" />
</IconButton>
</Controls>
</Header>
);
}
|