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

@@ -3,6 +3,7 @@ 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";
@@ -10,16 +11,32 @@ import { formatCheckTimestamp } from "./timeFormat";
const CELLS = 25;
const MIN_HEIGHT_PCT = 6;
export type BarKind = "up" | "down" | "empty";
interface Props {
checks: CheckSnapshot[];
classPrefix: string;
/** 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;
statsGap?: number;
}
const tone = (check: CheckSnapshot): "up" | "down" => (check.status ? "up" : "down");
const tone = (check: CheckSnapshot): Exclude<BarKind, "empty"> =>
check.status ? "up" : "down";
export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) => {
export const ThemedHistogram = ({
checks,
containerSx,
barSx,
statsSx,
classPrefix,
statsGap = 1,
}: Props) => {
const { t } = useTranslation();
const useSxApi = Boolean(barSx);
const { padded, max, avg, peak } = useMemo(() => {
const source = checks.slice(0, CELLS).reverse();
@@ -35,12 +52,25 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) =>
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 className={`${classPrefix}-histogram`}>
<Box {...containerProps}>
{padded.map((check, i) => {
if (!check) {
return (
return useSxApi ? (
<Box
key={`empty-${i}`}
sx={barSx!("empty", MIN_HEIGHT_PCT)}
/>
) : (
<Box
key={`empty-${i}`}
className={`${classPrefix}-bar ${classPrefix}-empty`}
@@ -77,11 +107,18 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) =>
arrow
placement="top"
>
<Box
className={`${classPrefix}-bar ${classPrefix}-${tone(check)}`}
style={{ height: `${height}%` }}
aria-label={`${check.responseTime} ms`}
/>
{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`}
/>
)}
</Tooltip>
);
})}
@@ -89,7 +126,7 @@ export const ThemedHistogram = ({ checks, classPrefix, statsGap = 1 }: Props) =>
<Stack
direction="row"
justifyContent="space-between"
className={`${classPrefix}-chart-stats`}
{...statsProps}
>
<span>{t("pages.statusPages.monitorsList.chart.avg", { value: avg })}</span>
<span>{t("pages.statusPages.monitorsList.chart.max", { value: peak })}</span>