Timeline: Use theme getContrastText to calculate value color based on background color (#34072)

* Timeline: Use theme getContrastText to calculate value color based on background color

* Changed back to using the old functions fill, and stroke
This commit is contained in:
Torkel Ödegaard
2021-05-13 21:41:40 +02:00
committed by GitHub
parent 36c4083264
commit 917a9ace57
3 changed files with 33 additions and 21 deletions
@@ -73,7 +73,7 @@ export interface ThemeHoverStrengh {}
/** @beta */
export interface ThemeColors extends ThemeColorsBase<ThemeRichColor> {
/** Returns a text color for the background */
getContrastText(background: string): string;
getContrastText(background: string, threshold?: number): string;
/* Brighten or darken a color by specified factor (0-1) */
emphasize(color: string, amount?: number): string;
}
@@ -255,11 +255,9 @@ export function createColors(colors: ThemeColorsInput): ThemeColors {
...other
} = colors;
function getContrastText(background: string) {
function getContrastText(background: string, threshold: number = contrastThreshold) {
const contrastText =
getContrastRatio(background, dark.text.maxContrast) >= contrastThreshold
? dark.text.maxContrast
: light.text.maxContrast;
getContrastRatio(background, dark.text.maxContrast) >= threshold ? dark.text.maxContrast : light.text.maxContrast;
// todo, need color framework
return contrastText;
}