Files
coder/site/src/utils/latency.ts
T
Jake Howell 3507ddc3cf feat: refactor <Latency /> colors (#21808)
This pull-request finds all of our previous instances of the MUI-based
Latency `color`'s and updates them to use the equivalents form the
Tailwind package.
2026-02-08 01:10:26 +11:00

30 lines
760 B
TypeScript

const latencyColors = {
good: { text: "text-content-success", background: "bg-content-success" },
warning: {
text: "text-content-warning",
background: "bg-content-yellow",
},
critical: {
text: "text-content-destructive",
background: "bg-content-destructive",
},
unknown: {
text: "text-content-secondary",
background: "bg-content-secondary",
},
} as const;
type LatencyLevel = keyof typeof latencyColors;
const getLatencyLevel = (latency?: number): LatencyLevel => {
if (!latency) return "unknown";
if (latency < 150) return "good";
if (latency < 300) return "warning";
return "critical";
};
export const getLatencyColor = (
latency?: number,
type: "text" | "background" = "text",
) => latencyColors[getLatencyLevel(latency)][type];