Created
November 26, 2023 15:37
-
-
Save Steellgold/de49ed7dd36f4d2dab16a2ae835ee99f to your computer and use it in GitHub Desktop.
Your text need to be dark or white?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const textIsWhite = (color: string): boolean => { | |
const hex = color.replace("#", ""); | |
const c_r = parseInt(hex.slice(0, 2), 16); | |
const c_g = parseInt(hex.slice(2, 4), 16); | |
const c_b = parseInt(hex.slice(4, 6), 16); | |
const brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; | |
return brightness < 155; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Role: Component<RoleProps> = ({ name, color }) => { | |
return ( | |
<Badge style={{ backgroundColor: color, color: textIsWhite(color) ? "white" : "black" }}> | |
{name} | |
</Badge> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment