Skip to content

USWDS - Settings: Update sass map pattern #5216

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 8 commits into from
May 26, 2023
Merged

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Apr 6, 2023

Summary

Updates sass map pattern to allow users to only define overrides while keeping defaults for the other values

Breaking change

This is potentially a breaking change.

Previously, if a user left an item out of a map, it would be set to false and thus deactivating it. After this update, an item left out of the map will maintain its default value.

If users deactivated certain settings by not declaring them, this update will cause those variables to be activated. Note that we did not recommend that pattern, but it's possible for users to have done so on their own

Related issue

Closes #5215

Related pull requests

Update sass map instructions on utility pages: uswds/uswds-site#2077

Problem statement

Currently, if you choose to update a USWDS setting within a sass map, you must define each setting within the map even if you are keeping the default values for the other.

Solution

We can use map-merge with a default values map to only replace updated settings keys without needing to redefine default values.

This solution

  • Doesn't break existing sass map settings users have previously set
  • BUT if users left an element out of the map, (effectively disabling it) this PR would re-enable the default setting.

This PR updates $theme-[map-name]s to $theme-[map-name]-complete wherever the setting is called.

This allows users still use existing setting names, such as $theme-utility-breakpoints, to update which breakpoints are active, while using the -complete map to restore defaults to undefined elements.

Note: I considered naming the complete maps as -defaults but I believe this makes less contextual sense wherever the maps are being called.

Updated maps

  • $theme-namespace
  • $theme-utility-breakpoints
  • $[utility-module]-settings

Ignored maps

These maps were either, empty, set to false by default, or only had example values. In all three settings, we would want the users override to be the only value, which is currently how they are set up.

  • $theme-fontface-tokens
  • $theme-font-[family]-src
  • $[utility-module]-manual-calues

Testing and review

  1. Checkout this test uswds-sandbox repo
  2. The test repo should already have this branch installed as it's USWDS package
  3. Run npm run start on the test repo
  4. View each test page and review instructions
  5. Visit _uswds-theme.scss and expirament enabling/disabling different settings
  6. Revisit index page in browser and view the changes
  7. Confirm that
    • : Default breakpoints are working as expected
    • : Updating one breakpoint, doesn't deactivate the others
    • : Updated breakpoints work as expected
  8. Look over all maps listed on the settings page
  9. Inspect their default values in the USWDS settings and verify there aren't any additional updates to make

These tests are simple and mostly just enable different background colors as a quick visual feedback. Feel free to experiment with other utility settings to verify the new pattern is working!

Default maps for reference:

Breakpoints

@use "uswds-core" with (
  $theme-utility-breakpoints: (
      "card": false,
      "card-lg": false,
      "mobile": false,
      "mobile-lg": true,
      "tablet": true,
      "tablet-lg": false,
      "desktop": true,
      "desktop-lg": false,
      "widescreen": false,
    )
);

Namespace

$theme-namespace: (
  "grid": (
    namespace: "grid-",
    output: true
  ),
  "utility": (
    namespace: "u-",
    output: false,
  ),
),

Before opening this PR, make sure you’ve done whichever of these applies to you:

  • Confirm that this code follows the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run git pull origin [base branch] to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch is develop).
  • Run npm run prettier:scss to format any Sass updates.

@mahoneycm mahoneycm marked this pull request as ready for review April 6, 2023 19:42
@mahoneycm mahoneycm requested review from amyleadem and mejiaj April 6, 2023 19:42
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.

A nice enhancement! I tested in uswds-sandbox and can confirm:

  • Settings for mobile and card are specified in src/_styles/_uswds-theme.scss
  • Settings are added to the defaults, giving me 5 total breakpoints (from three)
  • Removing the overrides for mobile and card will fallback to default (mobile-lg, tablet, desktop)
  • ⚠️ Passing an invalid breakpoint jumbo: true results in no errors. Current behavior on develop.

BTW, instead of manually linking via npm link you can install a git branch directly. You just need to run npm i "uswds/uswds#cm-theme-setting-maps" in your test branch.


Just a few requests:

  1. The description marks this as potentially breaking, could you add examples of where this would be a breaking change?
  2. Can you create a PR for necessary site updates?
  3. Can you link that PR to this one in the related pull requests section

@mahoneycm
Copy link
Contributor Author

@mejiaj @amyleadem If we like this implementation, should I go ahead and begin to look updating other maps to match this pattern?

The reason I ask, is because of the note I want to update on Site about updating all values of a map.

When modifying any settings stored as a map, you need to set all elements of the map, not just the element you wish to change.

I feel like the best route is to make updating map values uniform across the board so we only need to offer guidance on map settings once.


@mejiaj to answer your question of where this would be a breaking change:

Before this update, if a user updated breakpoint maps and excluded a breakpoint, it would be disabled. For example:

// User defined breakpoints
$theme-utility-breakpoints: (
  mobile: true,
  desktop: true,
)

mobile & desktop become the only enabled breakpoints. mobile-lg and tablet which are enabled by default, become disabled.

After this update, the default breakpoints will become enabled again despite not being defined, so the same settings as above would result in:

// User defined breakpoints
$theme-utility-breakpoints: (
  mobile: true,
  desktop: true,
)

// Results in the following breakpoints being enabled
mobile: true,
mobile-lg: true,
tablet: true,
desktop: true

I wanted to flag this because I thought it could potentially cause visual regressions for users who aren't expecting these values to become enabled.

Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

This enhancement is great @mahoneycm! To me it makes configuring USWDS sass maps much more intuitive and the solution feels elegant. Thank you for taking this on!

I have completed the following tests:

Confirmed that editing a single value (Example: ”card”: true):

  1. Adds the card breakpoint to the compiled CSS
  2. Does not remove existing breakpoints (ex: mobile-lg ) from the compiled CSS

This is up for debate, but I do think this functionality should be consistent across all USWDS settings maps before we release this enhancement. However, I haven’t fully investigated what would need to be included in that, so it might make sense to work on it in more than one PR and potentially release incrementally.

Additionally, we should prepare the following documentation updates before merging:

  • Add a summary of the break in the PR description so users can easily find what they need to check/fix
  • Consider adding a comment in _settings-utilities.scss that lets users know that they should update $theme-utility-breakpoints in their settings config and not $theme-utility-breakpoints-complete.
  • Check all references to $theme-utility-breakpoints in uswds-site
  • Update or remove the note When modifying any settings stored as a map, you need to set *all*  elements of the map, not just the element you wish to change. in uswds-site
  • Add changelog items for the Settings page and any affected utility pages. The changelog should indicate what might possibly break.

@@ -28,7 +28,8 @@ used by utilities or layout grid
----------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if it would be helpful if we added a note here that users should edit $theme-utility-breakpoints in the settings configuration and not $theme-utility-breakpoints-complete.

Added @use 'sass:map' to _settings.general.scss as required to use function
Updated all existing references of -namespace to -namespace-complete
map-merge() is outdated and no longer recommended by Sass
@mahoneycm mahoneycm changed the title USWDS - Settings: Breakpoints sass map USWDS - Settings: Update sass map pattern May 1, 2023
@mahoneycm mahoneycm requested review from amyleadem and mejiaj May 1, 2023 20:50
@mahoneycm
Copy link
Contributor Author

@amyleadem @mejiaj Ready for re-review! Restructured the PR to reflect all the sass maps affected and not just breakpoints!

Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

This is great, @mahoneycm! I am excited about this update. I also really appreciate the test pages you set up. They were very helpful. Good work!

I performed the following tests:

  • Confirmed that customizing the value of a single map key affects only the designated key and does not affect other items in the map. Tested the following settings:
    • $theme-utility-breakpoints
    • $theme-namespace
    • $background-color-settings
    • $border-color-settings
  • Confirmed all Sass maps inside packages/uswds-core/src/styles/settings/ have been updated
    • Confirmed all settings maps have been updated with map.merge or map.deep-merge and each have a -complete sibling
    • Confirmed all original utility settings and defaults are still there and that their defaults have not changed

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.

A nice improvement. I've tested:

  • References are accurate and up-to-date.
  • Selected breakpoints can be overridden without issues.

@mejiaj mejiaj requested a review from thisisdano May 24, 2023 17:14
@mahoneycm
Copy link
Contributor Author

@thisisdano ready for final review!

@thisisdano
Copy link
Contributor

A great improvement!

@thisisdano thisisdano merged commit c6e00f1 into develop May 26, 2023
@thisisdano thisisdano deleted the cm-theme-setting-maps branch May 26, 2023 20:40
@thisisdano thisisdano mentioned this pull request Jun 6, 2023
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.

USWDS - Feature: Update sass maps to allow single setting updates
4 participants