refactor(status-page): convert bold, modern and editorial themes to MUI sx
Finishes the migration started for refined. Each theme now consumes the same pattern: - A typed *Styles interface that names every entry the page consumes (no `as Function` casts at the call site) - A *Styles factory that takes (tokens, isDark) and returns sx recipes derived from existing tokens.ts plus the shared toneColor/toneSoft helpers in shared/overallStatus - A useMemo around the factory call so MUI's sx processor sees referential equality across renders that don't change tokens - modern.css's keyframes (pulse + staggered fade-in + reduced-motion guard) ported via @mui/system keyframes inside the modern styles factory - bold.css's hero glow + conic logo + pseudo-elements ported as inline sx via "&::before" / "& > *" selectors - editorial.css's serif typography + hairline dividers + flat rectangular badges ported as plain sx with the serif/sans family stacks named at module scope Drop the four .css files (~1789 lines) along with the className= attributes and the import "./*.css" lines in each StatusPage component. The shared themed components (ThemedHeatmap, ThemedHistogram, ThemedInfrastructure) lose their legacy classPrefix branch entirely now that no theme uses it. The dual-API gate is gone; there is one path. Verified: tsc --noEmit clean, prettier clean. Note: theme-overrides.css remains for the legacy non-themed status page components (StatusBar, MonitorsList, HeaderStatusPageControls). That's separate scope from the four-theme work the reviewer flagged; can be migrated in a follow-up.
This commit is contained in:
1 parent
b95d8886b9
commit
c6c50063d8
12 files changed
+1442
-1616
No files matched your search
@@ -13,11 +13,8 @@ export type HeatCellKind = "fast" | "med" | "slow" | "down" | "empty";
|
||||
|
||||
interface Props {
|
||||
checks: CheckSnapshot[];
|
||||
/** sx-based API — preferred. Themes pass their own container + cell recipes. */
|
||||
containerSx?: SxProps<Theme>;
|
||||
cellSx?: (kind: HeatCellKind) => SxProps<Theme>;
|
||||
/** Legacy className-based API — kept for unmigrated themes. Will be removed once all themes move to sx. */
|
||||
classPrefix?: string;
|
||||
containerSx: SxProps<Theme>;
|
||||
cellSx: (kind: HeatCellKind) => SxProps<Theme>;
|
||||
}
|
||||
|
||||
const classify = (check: CheckSnapshot): Exclude<HeatCellKind, "empty"> => {
|
||||
@@ -28,9 +25,8 @@ const classify = (check: CheckSnapshot): Exclude<HeatCellKind, "empty"> => {
|
||||
return "fast";
|
||||
};
|
||||
|
||||
export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Props) => {
|
||||
export const ThemedHeatmap = ({ checks, containerSx, cellSx }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const useSxApi = Boolean(containerSx && cellSx);
|
||||
|
||||
const source = checks.slice(0, CELLS).reverse();
|
||||
const padded: (CheckSnapshot | null)[] = [
|
||||
@@ -38,18 +34,9 @@ export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Prop
|
||||
...source,
|
||||
];
|
||||
|
||||
const containerProps = useSxApi
|
||||
? { sx: containerSx }
|
||||
: { className: `${classPrefix}-heatmap` };
|
||||
|
||||
const cellProps = (kind: HeatCellKind) =>
|
||||
useSxApi
|
||||
? { sx: cellSx!(kind) }
|
||||
: { className: `${classPrefix}-heatmap-cell ${classPrefix}-${kind}` };
|
||||
|
||||
return (
|
||||
<Box
|
||||
{...containerProps}
|
||||
sx={containerSx}
|
||||
role="img"
|
||||
aria-label={t("pages.statusPages.monitorsList.chart.heatmapAria")}
|
||||
>
|
||||
@@ -58,7 +45,7 @@ export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Prop
|
||||
return (
|
||||
<Box
|
||||
key={`empty-${i}`}
|
||||
{...cellProps("empty")}
|
||||
sx={cellSx("empty")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -89,7 +76,7 @@ export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Prop
|
||||
placement="top"
|
||||
>
|
||||
<Box
|
||||
{...cellProps(kind)}
|
||||
sx={cellSx(kind)}
|
||||
aria-label={`${check.responseTime} ms, ${check.status ? "up" : "down"}`}
|
||||
/>
|
||||
</Tooltip>
|
||||
|
||||
@@ -15,12 +15,9 @@ export type BarKind = "up" | "down" | "empty";
|
||||
|
||||
interface Props {
|
||||
checks: CheckSnapshot[];
|
||||
/** sx-based API — preferred. */
|
||||
containerSx?: SxProps<Theme>;
|
||||
barSx?: (kind: BarKind, heightPct: number) => SxProps<Theme>;
|
||||
statsSx?: SxProps<Theme>;
|
||||
/** Legacy className-based API. Will be removed once all themes move to sx. */
|
||||
classPrefix?: string;
|
||||
containerSx: SxProps<Theme>;
|
||||
barSx: (kind: BarKind, heightPct: number) => SxProps<Theme>;
|
||||
statsSx: SxProps<Theme>;
|
||||
statsGap?: number;
|
||||
}
|
||||
|
||||
@@ -32,11 +29,9 @@ export const ThemedHistogram = ({
|
||||
containerSx,
|
||||
barSx,
|
||||
statsSx,
|
||||
classPrefix,
|
||||
statsGap = 1,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const useSxApi = Boolean(containerSx && barSx && statsSx);
|
||||
|
||||
const { padded, max, avg, peak } = useMemo(() => {
|
||||
const source = checks.slice(0, CELLS).reverse();
|
||||
@@ -52,29 +47,15 @@ export const ThemedHistogram = ({
|
||||
return { padded: out, max: maxRt, avg: avgRt, peak: valid.length ? maxRt : 0 };
|
||||
}, [checks]);
|
||||
|
||||
const containerProps = useSxApi
|
||||
? { sx: containerSx }
|
||||
: { className: `${classPrefix}-histogram` };
|
||||
|
||||
const statsProps = useSxApi
|
||||
? { sx: statsSx }
|
||||
: { className: `${classPrefix}-chart-stats` };
|
||||
|
||||
return (
|
||||
<Stack gap={statsGap}>
|
||||
<Box {...containerProps}>
|
||||
<Box sx={containerSx}>
|
||||
{padded.map((check, i) => {
|
||||
if (!check) {
|
||||
return useSxApi ? (
|
||||
return (
|
||||
<Box
|
||||
key={`empty-${i}`}
|
||||
sx={barSx!("empty", MIN_HEIGHT_PCT)}
|
||||
/>
|
||||
) : (
|
||||
<Box
|
||||
key={`empty-${i}`}
|
||||
className={`${classPrefix}-bar ${classPrefix}-empty`}
|
||||
style={{ height: `${MIN_HEIGHT_PCT}%` }}
|
||||
sx={barSx("empty", MIN_HEIGHT_PCT)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -107,18 +88,10 @@ export const ThemedHistogram = ({
|
||||
arrow
|
||||
placement="top"
|
||||
>
|
||||
{useSxApi ? (
|
||||
<Box
|
||||
sx={barSx!(tone(check), height)}
|
||||
aria-label={`${check.responseTime} ms`}
|
||||
/>
|
||||
) : (
|
||||
<Box
|
||||
className={`${classPrefix}-bar ${classPrefix}-${tone(check)}`}
|
||||
style={{ height: `${height}%` }}
|
||||
aria-label={`${check.responseTime} ms`}
|
||||
/>
|
||||
)}
|
||||
<Box
|
||||
sx={barSx(tone(check), height)}
|
||||
aria-label={`${check.responseTime} ms`}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
})}
|
||||
@@ -126,7 +99,7 @@ export const ThemedHistogram = ({
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
{...statsProps}
|
||||
sx={statsSx}
|
||||
>
|
||||
<span>{t("pages.statusPages.monitorsList.chart.avg", { value: avg })}</span>
|
||||
<span>{t("pages.statusPages.monitorsList.chart.max", { value: peak })}</span>
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Monitor } from "@/Types/Monitor";
|
||||
|
||||
export type GaugeFillLevel = "ok" | "warm" | "hot";
|
||||
|
||||
interface InfraSx {
|
||||
export interface InfraSx {
|
||||
containerSx: SxProps<Theme>;
|
||||
emptySx: SxProps<Theme>;
|
||||
gaugeSx: SxProps<Theme>;
|
||||
@@ -19,10 +19,7 @@ interface InfraSx {
|
||||
|
||||
interface Props {
|
||||
monitor: Monitor & { checks?: Monitor["recentChecks"] };
|
||||
/** sx-based API — preferred. */
|
||||
sxApi?: InfraSx;
|
||||
/** Legacy className-based API. Will be removed once all themes move to sx. */
|
||||
classPrefix?: string;
|
||||
sxApi: InfraSx;
|
||||
}
|
||||
|
||||
interface Gauge {
|
||||
@@ -37,19 +34,13 @@ const PCT = 100;
|
||||
const heatLevel = (value: number): GaugeFillLevel =>
|
||||
value > 85 ? "hot" : value > 70 ? "warm" : "ok";
|
||||
|
||||
export const ThemedInfrastructure = ({ monitor, sxApi, classPrefix }: Props) => {
|
||||
export const ThemedInfrastructure = ({ monitor, sxApi }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const useSxApi = Boolean(sxApi);
|
||||
const latest = monitor.recentChecks?.[0] ?? monitor.checks?.[0];
|
||||
|
||||
const renderEmpty = () => {
|
||||
const message = t("pages.statusPages.monitorsList.noData");
|
||||
return useSxApi ? (
|
||||
<Box sx={sxApi!.emptySx}>{message}</Box>
|
||||
) : (
|
||||
<Box className={`${classPrefix}-infra-empty`}>{message}</Box>
|
||||
);
|
||||
};
|
||||
const renderEmpty = () => (
|
||||
<Box sx={sxApi.emptySx}>{t("pages.statusPages.monitorsList.noData")}</Box>
|
||||
);
|
||||
|
||||
if (!latest) return renderEmpty();
|
||||
|
||||
@@ -94,49 +85,21 @@ export const ThemedInfrastructure = ({ monitor, sxApi, classPrefix }: Props) =>
|
||||
|
||||
if (gauges.length === 0) return renderEmpty();
|
||||
|
||||
if (useSxApi) {
|
||||
const s = sxApi!;
|
||||
return (
|
||||
<Box sx={s.containerSx}>
|
||||
{gauges.map((g) => (
|
||||
<Box
|
||||
key={g.key}
|
||||
sx={s.gaugeSx}
|
||||
>
|
||||
<Box sx={s.gaugeLabelSx}>{g.label}</Box>
|
||||
<Box sx={s.gaugeValueSx}>{g.value.toFixed(0)}%</Box>
|
||||
<Box sx={s.gaugeBarSx}>
|
||||
<Box sx={s.gaugeFillSx(heatLevel(g.value), Math.min(100, g.value))} />
|
||||
</Box>
|
||||
<Box sx={s.gaugeSubSx}>{g.sub}</Box>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box className={`${classPrefix}-infra`}>
|
||||
{gauges.map((g) => {
|
||||
const level = heatLevel(g.value);
|
||||
const heatClass = level === "ok" ? "" : `${classPrefix}-${level}`;
|
||||
return (
|
||||
<Box
|
||||
key={g.key}
|
||||
className={`${classPrefix}-gauge`}
|
||||
>
|
||||
<Box className={`${classPrefix}-gauge-label`}>{g.label}</Box>
|
||||
<Box className={`${classPrefix}-gauge-value`}>{g.value.toFixed(0)}%</Box>
|
||||
<Box className={`${classPrefix}-gauge-bar`}>
|
||||
<Box
|
||||
className={`${classPrefix}-gauge-fill ${heatClass}`}
|
||||
style={{ width: `${Math.min(100, g.value)}%` }}
|
||||
/>
|
||||
</Box>
|
||||
<Box className={`${classPrefix}-gauge-sub`}>{g.sub}</Box>
|
||||
<Box sx={sxApi.containerSx}>
|
||||
{gauges.map((g) => (
|
||||
<Box
|
||||
key={g.key}
|
||||
sx={sxApi.gaugeSx}
|
||||
>
|
||||
<Box sx={sxApi.gaugeLabelSx}>{g.label}</Box>
|
||||
<Box sx={sxApi.gaugeValueSx}>{g.value.toFixed(0)}%</Box>
|
||||
<Box sx={sxApi.gaugeBarSx}>
|
||||
<Box sx={sxApi.gaugeFillSx(heatLevel(g.value), Math.min(100, g.value))} />
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
<Box sx={sxApi.gaugeSubSx}>{g.sub}</Box>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user