| 1 |
$contrasted-dark-default: #000 !default; |
| 2 |
$contrasted-light-default: #fff !default; |
| 3 |
$contrasted-lightness-threshold: 30% !default; |
| 4 |
|
| 5 |
// Returns the `$light` color when the `$color` is dark |
| 6 |
// and the `$dark` color when the `$color` is light. |
| 7 |
// The `$threshold` is a percent between `0%` and `100%` and it determines |
| 8 |
// when the lightness of `$color` changes from "dark" to "light". |
| 9 |
@function contrast-color( |
| 10 |
$color, |
| 11 |
$dark: $contrasted-dark-default, |
| 12 |
$light: $contrasted-light-default, |
| 13 |
$threshold: $contrasted-lightness-threshold |
| 14 |
) { |
| 15 |
@return if(lightness($color) < $threshold, $light, $dark) |
| 16 |
} |
| 17 |
|
| 18 |
// Sets the specified background color and calculates a dark or light contrasted text color. |
| 19 |
// The arguments are passed through to the [contrast-color function](#function-contrast-color). |
| 20 |
@mixin contrasted( |
| 21 |
$background-color, |
| 22 |
$dark: $contrasted-dark-default, |
| 23 |
$light: $contrasted-light-default, |
| 24 |
$threshold: $contrasted-lightness-threshold |
| 25 |
) { |
| 26 |
background-color: $background-color; |
| 27 |
color: contrast-color($background-color, $dark, $light, $threshold); |
| 28 |
} |