Created
August 25, 2020 01:07
-
-
Save chaance/e069d1111dda799ff1b683ec6de8988d to your computer and use it in GitHub Desktop.
alt-PurusAnte
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
/** | |
* Given a desired minimum contrast ratio, a base color, and an array of colors, | |
* return the first color in the array with an acceptable level of contrast | |
* against the base color. | |
* @param options | |
*/ | |
function getFirstUsableColorBasedOnContrastRatio(options: { | |
ratio: number; | |
baseColor: Color; | |
colors: Color[]; | |
}) { | |
for (let entry of options.colors) { | |
if (options.baseColor.hasSufficientContrastAgainst(entry, options.ratio)) { | |
return entry; | |
} | |
} | |
return options.colors[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment