refactor(status-page): convert refined theme to MUI sx + theme tokens

The reviewer's feedback on this PR is that the themes ship hardcoded class names against per-theme CSS files instead of following the project's MUI sx + theme.spacing()/palette pattern. This commit handles the refined theme as a proof of concept; the other three follow.

What changed
- New src/Pages/StatusPage/Status/themes/refined/styles.ts: a single function (tokens, isDark) -> sx recipes that mirror every rule in the deleted refined.css. All values are derived from the tokens already declared in tokens.ts so the colour/spacing source of truth doesn't change.
- RefinedStatusPage.tsx: drops the className= attributes and the import "./refined.css" in favour of sx={styles.x} drawn from the recipe map. Hardcoded class strings gone.
- refined.css: deleted (was 420 lines).
- Shared themed components (ThemedHeatmap, ThemedHistogram, ThemedInfrastructure): grew an opt-in sx-based API alongside the existing classPrefix one. The new API is what refined uses; bold / modern / editorial keep working unchanged on the legacy classPrefix path until they are migrated, after which the legacy code path is removed.

Verified
- tsc --noEmit clean
- prettier clean
- Pre-existing vite build error on this branch (flag-icons resolve, unrelated) is untouched

Next
- Convert the bold, modern and editorial themes the same way and remove the legacy classPrefix branch from the shared components.
This commit is contained in:
gorkem-bwl committed 2026-04-27 18:21:31 -04:00
1 parent 944ee74a1d
commit 163f5ec1ec
6 files changed
+553 -493

No files matched your search

@@ -2,18 +2,25 @@ import Tooltip from "@mui/material/Tooltip";
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import type { SxProps, Theme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
import type { CheckSnapshot } from "@/Types/Check";
import { formatCheckTimestamp } from "./timeFormat";
const CELLS = 25;
export type HeatCellKind = "fast" | "med" | "slow" | "down" | "empty";
interface Props {
checks: CheckSnapshot[];
classPrefix: string;
/** 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;
}
const classify = (check: CheckSnapshot): "fast" | "med" | "slow" | "down" => {
const classify = (check: CheckSnapshot): Exclude<HeatCellKind, "empty"> => {
if (!check.status) return "down";
const rt = check.responseTime ?? 0;
if (rt > 500) return "slow";
@@ -21,8 +28,9 @@ const classify = (check: CheckSnapshot): "fast" | "med" | "slow" | "down" => {
return "fast";
};
export const ThemedHeatmap = ({ checks, classPrefix }: Props) => {
export const ThemedHeatmap = ({ checks, containerSx, cellSx, classPrefix }: Props) => {
const { t } = useTranslation();
const useSxApi = Boolean(cellSx);
const source = checks.slice(0, CELLS).reverse();
const padded: (CheckSnapshot | null)[] = [
@@ -30,9 +38,18 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => {
...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
className={`${classPrefix}-heatmap`}
{...containerProps}
role="img"
aria-label={t("pages.statusPages.monitorsList.chart.heatmapAria")}
>
@@ -41,11 +58,11 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => {
return (
<Box
key={`empty-${i}`}
className={`${classPrefix}-heatmap-cell ${classPrefix}-empty`}
{...cellProps("empty")}
/>
);
}
const cls = classify(check);
const kind = classify(check);
const tooltipContent = (
<Stack gap={0.25}>
<Typography
@@ -72,7 +89,7 @@ export const ThemedHeatmap = ({ checks, classPrefix }: Props) => {
placement="top"
>
<Box
className={`${classPrefix}-heatmap-cell ${classPrefix}-${cls}`}
{...cellProps(kind)}
aria-label={`${check.responseTime} ms, ${check.status ? "up" : "down"}`}
/>
</Tooltip>