Created
November 7, 2020 13:14
-
-
Save karenying/638dfe2c50e8ffab33507396d08507e3 to your computer and use it in GitHub Desktop.
This file contains 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
// returns luminance as a number between 0 and 1 | |
get luminance() { | |
return getLuminance(this.hex); | |
} | |
/* returns contrast ratio with a second color, | |
calls contrastRatioPair */ | |
contrastRatioWith(hex2) { | |
return contrastRatioPair(this.hex, hex2); | |
} | |
// returns either textColors.BLACK / WHITE | |
get textColor() { | |
const { BLACK, WHITE } = textColors; | |
return this.contrastRatioWith(BLACK) > this.contrastRatioWith(WHITE) | |
? BLACK | |
: WHITE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment