Github integration (#6414)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -35,3 +35,17 @@ export const stringToColor = (input: string) => {
|
||||
*/
|
||||
export const toRGB = (color: string) =>
|
||||
Object.values(parseToRgb(color)).join(", ");
|
||||
|
||||
/**
|
||||
* Returns the text color that contrasts the given background color
|
||||
*
|
||||
* @param background - A color string
|
||||
* @returns A color string
|
||||
*/
|
||||
export const getTextColor = (background: string) => {
|
||||
const r = parseInt(background.substring(1, 3), 16);
|
||||
const g = parseInt(background.substring(3, 5), 16);
|
||||
const b = parseInt(background.substring(5, 7), 16);
|
||||
const yiq = (r * 299 + g * 587 + b * 114) / 1000;
|
||||
return yiq >= 128 ? "black" : "white";
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user