Skip to content

USWDS - Table: Update color styles to use theme settings #4712

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

Merged
merged 7 commits into from
Jun 3, 2022

Conversation

amyleadem
Copy link
Contributor

@amyleadem amyleadem commented May 24, 2022

Description

Closes #4389

Problem

Theme table settings are not consistently applied to table styles. This results in an unpredictable user experience and undesired visual presentation.

  1. $theme-table-border-color is defined but not used
  2. $theme-table-sorted-icon-color is defined but not used
  3. $theme-table-sorted-icon-colorand $theme-table-unsorted-icon-color do not check for accessible contrast ratio
  4. In limited circumstances, settings colors are overwritten by project defaults, despite the setting having an accessible contrast ratio

An example that demonstrates most of these issues can be seen by customizing the following variables, which returns the screenshot below:

/* _settings-components.scss*/
$theme-table-border-color: "red-cool-30" !default;
$theme-table-header-background-color: "magenta-70" !default;
$theme-table-header-text-color: "blue-60" !default;
$theme-table-stripe-background-color: "blue-warm-10" !default;
$theme-table-stripe-text-color: "indigo-60" !default;
$theme-table-text-color: "cyan-60" !default;
$theme-table-sorted-header-background-color: "green-cool-10" !default;
$theme-table-sorted-background-color: "orange-warm-10" !default;
$theme-table-sorted-stripe-background-color: "indigo-10" !default;
$theme-table-sorted-icon-color: "red-60" !default;
$theme-table-unsorted-icon-color: "green-cool-10" !default;

Note that the table border and sort icons are not receiving defined values, and that the unsorted icon on the borderless table does not have acceptable contrast ratio

image

Solution

  1. Use the settings vars$theme-table-border-color and $theme-table-sorted-icon-color to define related style rules
  2. Run both $theme-table-sorted-icon-color and $theme-table-unsorted-icon-color through a contrast check to increase the likelihood of an acceptable contrast token.
  3. Use the theme setting variable in $preferred-text-token rather than placing that value in $fallback-text-token

Testing

To test, simply customize $theme-table colors and check the rendered results. I've included some samples below as a starting point.

Desired result: Rendered colors should match the declared settings, and should differ from these settings only when the supplied color does not meet contrast requirements. If no accessible colors are available, the user should receive a compile warning and instructions to choose another color.

Limitations

There are limited instances when the functions will return defaults instead of settings values. See dark body background section below for an example.

Light body background

This demo uses the same settings as above. Note that all colors are being rendered as expected, except for the borderless unsorted icon, which instead is delivering a color with accessible contrast. The header text color is changed to white because the provided color does not create accessible contrast ratio.

/* _settings-components.scss*/
$theme-table-border-color: "red-cool-30" !default;
$theme-table-header-background-color: "magenta-70" !default;
$theme-table-header-text-color: "blue-60" !default;
$theme-table-stripe-background-color: "blue-warm-10" !default;
$theme-table-stripe-text-color: "indigo-60" !default;
$theme-table-text-color: "cyan-60" !default;
$theme-table-sorted-header-background-color: "green-cool-10" !default;
$theme-table-sorted-background-color: "orange-warm-10" !default;
$theme-table-sorted-stripe-background-color: "indigo-10" !default;
$theme-table-sorted-icon-color: "red-60" !default;
$theme-table-unsorted-icon-color: "green-cool-10" !default;

image

Dark body background

If a user sets both $theme-text-reverse-color and $theme-table settings to dark colors, the $theme-table settings color will be overwritten with project defaults, even if it has an accessible contrast ratio. In this case below, $theme-table-header-text-color and $theme-table-stripe-text-color are being overwritten, despite having an accessible contrast ratio.

Because all settings here have been given values with accessible color contrast, these colors are rendering as expected with no warnings.

/* _settings-color.scss*/
// Body
$theme-body-background-color: "ink" !default;

// Text
$theme-text-color: "white" !default;
$theme-text-reverse-color: "ink" !default;

/* _settings-components.scss*/
$theme-table-border-color: "red-cool-30" !default;
$theme-table-header-background-color: "magenta-10" !default;
$theme-table-header-text-color: "blue-70" !default;
$theme-table-stripe-background-color: "blue-warm-10" !default;
$theme-table-stripe-text-color: "indigo-60" !default;
$theme-table-text-color: "yellow-10" !default;
$theme-table-sorted-header-background-color: "green-cool-10" !default;
$theme-table-sorted-background-color: "orange-warm-10" !default;
$theme-table-sorted-stripe-background-color: "indigo-10" !default;
$theme-table-sorted-icon-color: "red-60" !default;
$theme-table-unsorted-icon-color: "green-60" !default;

image

Default settings

/* _settings-components.scss*/
$theme-table-border-color: "ink" !default;
$theme-table-header-background-color: "base-lighter" !default;
$theme-table-header-text-color: default !default;
$theme-table-stripe-background-color: "base-lightest" !default;
$theme-table-stripe-text-color: default !default;
$theme-table-text-color: default !default;
$theme-table-sorted-header-background-color: "accent-cool-light" !default;
$theme-table-sorted-background-color: "accent-cool-lighter" !default;
$theme-table-sorted-stripe-background-color: "blue-cool-10v" !default;
$theme-table-sorted-icon-color: default !default;
$theme-table-unsorted-icon-color: "base" !default;

image

Before you hit Submit, make sure you’ve done whichever of these applies to you:

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

@@ -5,13 +5,12 @@
@use "../utilities" as *;
@use "../typography/typeset" as *;

$table-text-color: color(
Copy link
Contributor Author

@amyleadem amyleadem May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the color function here so that we could use this variable with next-token() below for hover states

@@ -184,7 +184,7 @@ $theme-summary-box-link-color: default !default;
$theme-summary-box-text-color: default !default;

// Table
$theme-table-border-color: default !default;
$theme-table-border-color: "ink" !default;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$theme-table-border-color needs a defined token value or it will throw an error. ink is the current rendered default value.


&[aria-sort] {
color: $table-sorted-header-text-color;
}
}
/* stylelint-disable selector-class-pattern */
th[data-sortable]:not([aria-sort]) {
.usa-table__header__button .usa-icon > g.unsorted {
fill: color($table-text-color);
Copy link
Contributor Author

@amyleadem amyleadem May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a default fill for unsorted icons to match the header color

@amyleadem amyleadem marked this pull request as ready for review May 25, 2022 22:55
@amyleadem amyleadem requested review from mejiaj and mahoneycm May 25, 2022 22:55
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we double check the variables for color setting (lines 9-73)? There are some backgrounds being set as "white" with preferred text token of "white".

Comment on lines 11 to 12
$preferred-text-token: $theme-text-reverse-color,
$fallback-text-token: $theme-table-text-color,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the default $theme-table-text-color be the preferred token?

$bg-color: $theme-body-background-color // "white"
$preferred-text-token: $theme-text-reverse-color, // "white"
$fallback-text-token: $theme-table-text-color, // default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I will test out using the settings as the preferred token, not the fallback, throughout table.scss

);

$table-header-text-color: color(
get-color-token-from-bg(
$bg-color: $theme-table-header-background-color,
$preferred-text-token: $theme-text-reverse-color,
$fallback-text-token: $theme-table-header-text-color,
Copy link
Contributor Author

@amyleadem amyleadem May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the theme settings variables into the value for $preferred-text-token. Allowed $fallback-text-token to use the fallback from project defaults.

Comment on lines +54 to +67
$table-sorted-icon-color: color(
get-color-token-from-bg(
$bg-color: $theme-table-sorted-header-background-color,
$preferred-text-token: $theme-table-sorted-icon-color,
$context: "Table sorted icon",
)
);

$table-unsorted-icon-color: get-color-token-from-bg(
$bg-color: $theme-table-header-background-color,
$preferred-text-token: $theme-table-unsorted-icon-color,
$context: "Table unsorted icon",
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run $table-sorted-icon-color and $table-unsorted-icon-color through a contrast check

Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks Amy.

@mejiaj mejiaj requested a review from thisisdano June 2, 2022 15:42
Copy link
Contributor

@thisisdano thisisdano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@thisisdano thisisdano merged commit 1815376 into develop Jun 3, 2022
@thisisdano thisisdano deleted the al-table-color-settings branch June 3, 2022 16:19
@thisisdano thisisdano mentioned this pull request Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table border color Sass variable is not applied.
3 participants