Created
May 7, 2020 02:47
-
-
Save fredyang/ef3bafc9752fd655020554118b1c9205 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
//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