Skip to content

Instantly share code, notes, and snippets.

@fredyang
Created May 7, 2020 02:47
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 fredyang/ef3bafc9752fd655020554118b1c9205 to your computer and use it in GitHub Desktop.
Save fredyang/ef3bafc9752fd655020554118b1c9205 to your computer and use it in GitHub Desktop.
//this function return a color in constrast with the input color
// https://medium.com/@MikeKellyWeb/calculating-color-contrast-with-sass-eff39ef23f96
// Color contrast
// see demo https://codepen.io/fredyang/pen/RwWQJVo
$yiq-text-dark: $gray-900 !default;
$yiq-text-light: $white !default;
$yiq-contrasted-threshold: 150 !default
@function color-yiq($color, $dark: $yiq-text-dark, $light: $yiq-text-light) {
$r: red($color);
$g: green($color);
$b: blue($color);
$yiq: (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
@if ($yiq >= $yiq-contrasted-threshold) {
@return $dark;
} @else {
@return $light;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment