Skip to content

Commit

Permalink
Update some more downstream components
Browse files Browse the repository at this point in the history
- Only showing the Amsterdam callout when they’ve switched to the Amsterdam theme
- Added `makeGraphicColor()` SASS color function
- Added defaults to `makeHighContrastColor()` SASS color function
  • Loading branch information
cchaos committed Feb 21, 2020
1 parent 1de8ddd commit 3e57b70
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}

.guideRule__caption {
color: $euiColorSuccess;
color: $euiColorSuccessText;
}
}

Expand Down
46 changes: 30 additions & 16 deletions src-docs/src/views/guidelines/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EuiFormRow,
EuiCode,
EuiSwitch,
EuiCallOut,
} from '../../../../src/components';

const allowedColors = [
Expand Down Expand Up @@ -156,14 +157,19 @@ export default class extends Component {
const { selectedTheme } = this.props;

let palette;
if (selectedTheme === 'amsterdam-dark') {
palette = darkAmsterdamColors;
} else if (selectedTheme === 'amsterdam-light') {
palette = { ...lightColors, ...lightAmsterdamColors };
} else if (selectedTheme === 'dark') {
palette = darkColors;
} else {
palette = lightColors;
switch (selectedTheme) {
case 'amsterdam-dark':
palette = darkAmsterdamColors;
break;
case 'amsterdam-light':
palette = { ...lightColors, ...lightAmsterdamColors };
break;
case 'dark':
palette = darkColors;
break;
default:
palette = lightColors;
break;
}

// Vis colors are the same for all palettes
Expand Down Expand Up @@ -238,14 +244,22 @@ export default class extends Component {
combination that is <EuiBadge color="#333">AA</EuiBadge> or above
with the exception of using large text.
</p>
<p>
The Amsterdam theme introduces a more vibrant core color palette. In
order to maintain a WCAG contrast of at least 4.5 you should use the
text variants of the core color variables such as&nbsp;
<EuiCode>$euiColorSecondaryText</EuiCode>. Components that render
text such as <EuiCode>EuiText</EuiCode> will do so on their own
without any extra configuration.
</p>
{selectedTheme === 'amsterdam-light' && (
<EuiCallOut
color="warning"
iconType="accessibility"
title="Amsterdam changes in contrast levels">
<p>
The Amsterdam theme introduces a more vibrant core color
palette. In order to maintain a WCAG contrast of at least 4.5
you should use the text variants of the core color variables
such as&nbsp;
<EuiCode>$euiColorSecondaryText</EuiCode>. Components that
render text such as <EuiCode>EuiText</EuiCode> will do so on
their own without any extra configuration.
</p>
</EuiCallOut>
)}
<h3>Rating definitions</h3>
<ul>
<li>
Expand Down
11 changes: 7 additions & 4 deletions src/components/badge/notification_badge/_notification_badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
flex-shrink: 0; // Ensures it never scales down below its intended size
display: inline-block;
border-radius: $euiBorderRadius;
background: $euiColorAccent;
color: $euiColorEmptyShade;
font-size: $euiFontSizeXS;
font-weight: $euiFontWeightMedium;
line-height: $euiSize;
Expand All @@ -15,6 +13,10 @@
text-align: center;
transition: all $euiAnimSpeedFast ease-in;
cursor: default;

$backgroundColor: $euiColorAccent;
background: $backgroundColor;
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);
}

.euiNotificationBadge--medium {
Expand All @@ -26,6 +28,7 @@
}

.euiNotificationBadge--subdued {
background-color: tint($euiColorLightShade, 30%);
color: $euiColorFullShade;
$backgroundColor: tint($euiColorLightShade, 30%);
background: $backgroundColor;
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);
}
2 changes: 1 addition & 1 deletion src/components/expression/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Modifier naming and colors.
$euiExpressionColors: (
subdued: $euiColorMediumShade,
subdued: $euiColorDarkShade,
primary: $euiColorPrimaryText,
secondary: $euiColorSecondaryText,
warning: $euiColorWarningText,
Expand Down
2 changes: 1 addition & 1 deletion src/components/icon/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// This provides the default secondary color
.euiIcon__fillSecondary {
fill: $euiColorSecondary;
fill: makeGraphicColor($euiColorSecondary);
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/components/icon/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
$euiIconLoadingOpacity: .05;

// Modifier naming and colors.

$euiIconColors: (
text: $euiTextColor,
primary: $euiColorPrimary,
subdued: $euiColorMediumShade,
secondary: $euiColorSecondary,
success: $euiColorSuccess,
accent: $euiColorAccent,
warning: $euiColorWarning,
danger: $euiColorDanger,
subdued: makeGraphicColor($euiColorMediumShade),
primary: makeGraphicColor($euiColorPrimary),
secondary: makeGraphicColor($euiColorSecondary),
success: makeGraphicColor($euiColorSuccess),
accent: makeGraphicColor($euiColorAccent),
warning: makeGraphicColor($euiColorWarning),
danger: makeGraphicColor($euiColorDanger),
ghost: $euiColorGhost,
);

Expand Down
12 changes: 6 additions & 6 deletions src/components/toast/_toast.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
}

// Modifier naming and colors.
$toastTypes: (
primary: $euiColorPrimary,
success: $euiColorSecondary,
warning: $euiColorWarning,
danger: $euiColorDanger,
$euiToastTypes: (
primary: makeGraphicColor($euiColorPrimary, $euiColorEmptyShade),
success: makeGraphicColor($euiColorSecondary, $euiColorEmptyShade),
warning: makeGraphicColor($euiColorWarning, $euiColorEmptyShade),
danger: makeGraphicColor($euiColorDanger, $euiColorEmptyShade),
);

// Create button modifiders based upon the map.
@each $name, $color in $toastTypes {
@each $name, $color in $euiToastTypes {
.euiToast--#{$name} {
border-top: 2px solid $color;
}
Expand Down
11 changes: 9 additions & 2 deletions src/global_styling/functions/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@

// Given a $foreground and a $background, make the $foreground AA accessibility by slightly
// adjusting it till the contrast is high enough
// By default it will compare against the page background color

// ex: makeContrastColor($lightPink, #FFF) would continually shade the pink until
// it had higher than 4.5 contrast on a white background.
@function makeHighContrastColor($foreground, $background) {
@function makeHighContrastColor($foreground, $background: $euiPageBackgroundColor, $ratio: 4.5) {
$contrast: contrastRatio($foreground, $background);

// Determine the lightness factor of the background color first to
Expand All @@ -97,7 +98,7 @@

$highContrastTextColor: $foreground;

@while ($contrast < 4.5) {
@while ($contrast < $ratio) {
@if ($brightness > 50) {
$highContrastTextColor: shade($highContrastTextColor, 5%);
} @else {
Expand All @@ -119,3 +120,9 @@

@return $highContrastTextColor;
}

// Non-textual elements only need a contrast ration of 3:1
@function makeGraphicColor($color, $background: $euiPageBackgroundColor) {
@return makeHighContrastColor($color, $background, 3);
}

12 changes: 6 additions & 6 deletions src/global_styling/variables/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ $euiColorDarkestShade: #343741 !default;
$euiColorFullShade: #000 !default;

// Every color below must be based mathmatically on the set above.

$euiTextColor: $euiColorDarkestShade !default;
$euiTitleColor: shadeOrTint($euiTextColor, 50%, 0%) !default;
$euiLinkColor: $euiColorPrimary !default;
$euiFocusBackgroundColor: tintOrShade($euiColorPrimary, 90%, 50%) !default;
$euiPageBackgroundColor: tintOrShade($euiColorLightestShade, 50%, 30%) !default;

// Constrasty text variants
$euiColorPrimaryText: makeHighContrastColor($euiColorPrimary, $euiPageBackgroundColor);
$euiColorSecondaryText: makeHighContrastColor($euiColorSecondary, $euiPageBackgroundColor);
$euiColorAccentText: makeHighContrastColor($euiColorAccent, $euiPageBackgroundColor);
$euiColorWarningText: makeHighContrastColor($euiColorWarning, $euiPageBackgroundColor);
$euiColorDangerText: makeHighContrastColor($euiColorDanger, $euiPageBackgroundColor);
$euiColorPrimaryText: makeHighContrastColor($euiColorPrimary) !default;
$euiColorSecondaryText: makeHighContrastColor($euiColorSecondary) !default;
$euiColorAccentText: makeHighContrastColor($euiColorAccent) !default;
$euiColorWarningText: makeHighContrastColor($euiColorWarning) !default;
$euiColorDangerText: makeHighContrastColor($euiColorDanger) !default;
$euiColorSuccessText: $euiColorSecondaryText !default;

// Visualization colors

Expand Down

0 comments on commit 3e57b70

Please sign in to comment.