[#646] improve dark color management (#648)

Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
Camille Moussu
2026-03-17 16:26:37 +01:00
committed by GitHub
parent a771b311b5
commit e665ea4a79
12 changed files with 49 additions and 101 deletions
+23
View File
@@ -0,0 +1,23 @@
import { darken, getContrastRatio, lighten, Theme } from "@linagora/twake-mui";
export function getAccessiblePair(baseColor: string, theme: Theme): string {
if (typeof baseColor !== "string") {
return theme.palette.getContrastText("#000");
}
const contrastToBlack = getContrastRatio(baseColor, "#000");
const contrastToWhite = getContrastRatio(baseColor, "#fff");
const isLight = contrastToBlack > contrastToWhite;
const adjusted = isLight ? darken(baseColor, 0.6) : lighten(baseColor, 0.7);
// Check if contrast meets 4.5
const contrast = getContrastRatio(baseColor, adjusted);
if (contrast >= 4.5) return adjusted;
if (isLight) {
return "#ffffffff";
}
return theme.palette.getContrastText(baseColor);
}