Skip to content

Instantly share code, notes, and snippets.

@karenying
Created November 7, 2020 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenying/638dfe2c50e8ffab33507396d08507e3 to your computer and use it in GitHub Desktop.
Save karenying/638dfe2c50e8ffab33507396d08507e3 to your computer and use it in GitHub Desktop.
// 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