Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing highContrastTextColor sass function #1275

Merged
merged 3 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- `EuiComboBox` no longer throws a _Maximum update depth exceeded_ error when used in popovers/modals ([#1258](https://github.com/elastic/eui/pull/1258))
- `Escape` key now closes `EuiComboBox` options list ([#1258](https://github.com/elastic/eui/pull/1258))
- Fixed `highContrastTextColor` SASS function to account for background lightness and exit possible infinite loops ([#1275](https://github.com/elastic/eui/pull/1275))

## [`4.6.1`](https://github.com/elastic/eui/tree/v4.6.1)

Expand Down
21 changes: 20 additions & 1 deletion src/global_styling/functions/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,30 @@
@function makeHighContrastColor($foreground, $background) {
$contrast: contrastRatio($foreground, $background);

// Determine the lightness factor of the background color first to
// determine whether to shade or tint the foreground.
$brightness: lightness($background);

$highContrastTextColor: $foreground;

@while ($contrast < 4.5) {
$highContrastTextColor: shadeOrTint($highContrastTextColor, 5%, 5%);
@if ($brightness > 50) {
$highContrastTextColor: shade($highContrastTextColor, 5%);
} @else {
$highContrastTextColor: tint($highContrastTextColor, 5%);
}

$contrast: contrastRatio($highContrastTextColor, $background);

@if (lightness($highContrastTextColor) < 5) {
@warn 'High enough contrast could not be determined. Most likely your background color does not adjust for light mode.';
@return $highContrastTextColor;
}

@if (lightness($highContrastTextColor) > 95) {
@warn 'High enough contrast could not be determined. Most likely your background color does not adjust for dark mode.';
@return $highContrastTextColor;
}
}

@return $highContrastTextColor;
Expand Down