Skip to content

Instantly share code, notes, and snippets.

@chaance
Created August 25, 2020 01:07
Show Gist options
  • Save chaance/e069d1111dda799ff1b683ec6de8988d to your computer and use it in GitHub Desktop.
Save chaance/e069d1111dda799ff1b683ec6de8988d to your computer and use it in GitHub Desktop.
alt-PurusAnte
/**
* 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