After doing some design on some icons1
This commit is contained in:
parent
b0630d9364
commit
ea937d3084
@ -13,43 +13,98 @@ export type PageHeaderProps = {
|
||||
mb?: number;
|
||||
};
|
||||
|
||||
/** Page title row — keeps actions aligned on the right on small screens (Referral-style). */
|
||||
function renderTitle(title: ReactNode) {
|
||||
if (typeof title === 'string') {
|
||||
return (
|
||||
<Typography
|
||||
variant="h4"
|
||||
sx={{ fontWeight: 900, fontSize: { xs: '1.5rem', sm: '2.125rem' }, letterSpacing: 0.2 }}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
function renderSubtitle(subtitle: ReactNode) {
|
||||
if (typeof subtitle === 'string') {
|
||||
return (
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{subtitle}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page title row — actions stay on the title row (top-right), subtitle on a second line.
|
||||
* Matches the Referral program layout on narrow screens.
|
||||
*/
|
||||
export function PageHeader({ icon, title, subtitle, leading, actions, mb = 2 }: PageHeaderProps) {
|
||||
const hasSubtitle = subtitle != null;
|
||||
const columns = [
|
||||
leading ? 'auto' : null,
|
||||
icon ? 'auto' : null,
|
||||
'minmax(0, 1fr)',
|
||||
actions != null ? 'auto' : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
|
||||
let col = 1;
|
||||
const leadingCol = leading ? col++ : 0;
|
||||
const iconCol = icon ? col++ : 0;
|
||||
const textCol = col++;
|
||||
const actionsCol = actions != null ? col : 0;
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction="row"
|
||||
spacing={1.5}
|
||||
useFlexGap
|
||||
sx={{ alignItems: 'center', mb, flexWrap: 'wrap' }}
|
||||
<Box
|
||||
sx={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: columns,
|
||||
gridTemplateRows: hasSubtitle ? 'auto auto' : 'auto',
|
||||
columnGap: 1.5,
|
||||
rowGap: 0.5,
|
||||
alignItems: 'start',
|
||||
mb,
|
||||
}}
|
||||
>
|
||||
{leading}
|
||||
{icon}
|
||||
<Box sx={{ flex: '1 1 auto', minWidth: { xs: 0, sm: 200 } }}>
|
||||
{typeof title === 'string' ? (
|
||||
<Typography
|
||||
variant="h4"
|
||||
sx={{ fontWeight: 900, fontSize: { xs: '1.5rem', sm: '2.125rem' }, letterSpacing: 0.2 }}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
) : (
|
||||
title
|
||||
)}
|
||||
{subtitle != null &&
|
||||
(typeof subtitle === 'string' ? (
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mt: 0.5 }}>
|
||||
{subtitle}
|
||||
</Typography>
|
||||
) : (
|
||||
subtitle
|
||||
))}
|
||||
</Box>
|
||||
{actions != null && (
|
||||
<Stack direction="row" spacing={0.5} useFlexGap sx={{ flexShrink: 0, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
{actions}
|
||||
</Stack>
|
||||
{leading && (
|
||||
<Box sx={{ gridColumn: leadingCol, gridRow: hasSubtitle ? '1 / -1' : 1, alignSelf: 'start' }}>
|
||||
{leading}
|
||||
</Box>
|
||||
)}
|
||||
</Stack>
|
||||
{icon && (
|
||||
<Box
|
||||
sx={{
|
||||
gridColumn: iconCol,
|
||||
gridRow: hasSubtitle ? '1 / -1' : 1,
|
||||
alignSelf: 'start',
|
||||
pt: 0.25,
|
||||
lineHeight: 0,
|
||||
}}
|
||||
>
|
||||
{icon}
|
||||
</Box>
|
||||
)}
|
||||
<Box sx={{ gridColumn: textCol, gridRow: 1, minWidth: 0, alignSelf: 'center' }}>
|
||||
{renderTitle(title)}
|
||||
</Box>
|
||||
{hasSubtitle && (
|
||||
<Box sx={{ gridColumn: textCol, gridRow: 2, minWidth: 0 }}>
|
||||
{renderSubtitle(subtitle)}
|
||||
</Box>
|
||||
)}
|
||||
{actions != null && (
|
||||
<Box sx={{ gridColumn: actionsCol, gridRow: 1, alignSelf: 'start' }}>
|
||||
<Stack direction="row" spacing={0.5} useFlexGap sx={{ flexShrink: 0, alignItems: 'center' }}>
|
||||
{actions}
|
||||
</Stack>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@ -73,19 +128,22 @@ type PageSectionHeaderProps = {
|
||||
mb?: number;
|
||||
};
|
||||
|
||||
/** Section title inside a card — title and actions stay on one row when possible. */
|
||||
/** Section title inside a card — title and actions stay on one row. */
|
||||
export function PageSectionHeader({ title, actions, mb = 2 }: PageSectionHeaderProps) {
|
||||
return (
|
||||
<Stack
|
||||
direction="row"
|
||||
spacing={1}
|
||||
useFlexGap
|
||||
sx={{ alignItems: 'center', mb, flexWrap: 'wrap' }}
|
||||
<Box
|
||||
sx={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'minmax(0, 1fr) auto',
|
||||
columnGap: 1,
|
||||
alignItems: 'center',
|
||||
mb,
|
||||
}}
|
||||
>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, flex: '1 1 auto', minWidth: 0 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, minWidth: 0 }}>
|
||||
{title}
|
||||
</Typography>
|
||||
{actions != null && <Box sx={{ flexShrink: 0 }}>{actions}</Box>}
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user