Skip to content

Conversation

amyleadem
Copy link
Contributor

@amyleadem amyleadem commented Sep 26, 2024

Summary

A potential addition to PR #6048

Added support for generating custom breakpoints for layout grid utility classes.

Breaking change

This is not a breaking change.

Related issue

Related to #5984

Related pull requests

Potential addition to #6048

Preview link

Storybook

Problem statement

In PR #6048, we added support to create custom breakpoints with the theme setting $theme-utility-breakpoints-custom. However, this setting did not generate custom breakpoints for layout grid.

Solution

This PR generates custom responsive variants for grid-col, grid-gap, grid-offset, and grid-container classes.

Note

The media queries for grid-container have some pre-existing quirks that should probably be broken out into a separate issue. Here is an example:

@media all and (min-width: 30em) and (min-width: 64em){
  .mobile-lg\:grid-container-card{
    padding-left:2rem;
    padding-right:2rem;
  }
}

These media queries have multiple min-width declarations, which are redundant and at times contradictory. This PR does not attempt to address this pre-existing issue.

Performance impact

Including custom breakpoints for layout grid classes adds 8kb to the compiled CSS file. Here are the details on CSS size:

Description CSS size
With default breakpoints 524kb
With 1 new custom breakpoint without layout grid (cm-custom-breakpoints branch) 572kb
With 1 new custom breakpoint with layout grid (this branch) 580kb

Testing and review

  • Checkout the al-test-custom-breakpoints branch in uswds-sandbox.
  • Use the following code in uswds-theme.scss:
    @use "uswds-core" with (
      $theme-utility-breakpoints-custom: (
        "new-breakpoint": 800px
      ),
      $theme-utility-breakpoints: (
        widescreen: true,
      )
    );
  • Run npx gulp buildSass and navigate to _site/assets/css/styles.css
  • In styles.css, search for:
    • .widescreen\:grid-container and .new-breakpoint\:grid-container. Confirm that the style rules match for the two rules, with the exception of a different media query width.
    • .widescreen\:grid-gap and .new-breakpoint\:grid-gap. Confirm that the style rules match for the two rules, with the exception of a different media query width.
    • .widescreen\:grid-col and .new-breakpoint\:grid-col. Confirm that the style rules match for the two rules, with the exception of a different media query width.
    • .widescreen\:grid-offset and .new-breakpoint\:grid-offset. Confirm that the style rules match for the two rules, with the exception of a different media query width.

@@ -6,6 +6,9 @@

$namespace-grid: ns("grid");

$custom-breakpoints: map-deep-get($system-properties, breakpoints, extended);
$all-breakpoints: map-collect($system-breakpoints, $custom-breakpoints);
Copy link
Contributor Author

@amyleadem amyleadem Sep 26, 2024

Choose a reason for hiding this comment

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

Note

Interestingly, layout grid and icon list size use $system-breakpoints in breakpoints.scss and the other utilities build from $system-properties.breakpoints in _properties.scss. Both seem to collect the same values:

/*breakpoints.scss*/
$system-breakpoints: general.map-collect(
  map.get(spacing.$system-spacing, "large"),
  map.get(spacing.$system-spacing, "larger"),
  map.get(spacing.$system-spacing, "largest")
);
/*_properties.scss*/
  breakpoints: (
    standard:
      map-collect(
        map.get($system-spacing, "large"),
        map.get($system-spacing, "larger"),
        map.get($system-spacing, "largest")
      ),
    extended: (),
  ),

Flagging in case we want to standardize this and potentially replace $system-breakpoints with $system-properties, breakpoints, standard here. To keep things scoped, I am leaving $system-breakpoints as is for now. Let me know if you would like this to change incorporated into this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@amyleadem good find. Do you have an initial recommendation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could remove the reference to $system-breakpoints and instead use the same technique from _utility-builder.scss to grab $our-breakpoints from $system-properties. Initial testing on this branch shows that this change creates the correct number of references in the CSS, but it would need further testing to confirm that the generated CSS is correct. What do you think - should we pursue now or explore as a possible follow-up?

Suggested change
$all-breakpoints: map-collect($system-breakpoints, $custom-breakpoints);
$our-breakpoints: map-deep-get($system-properties, breakpoints, standard);
$all-breakpoints: map-collect($our-breakpoints, $custom-breakpoints);

Copy link
Contributor

Choose a reason for hiding this comment

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

@amyleadem inclined to say follow-up so as to not delay the release.

@amyleadem amyleadem marked this pull request as ready for review September 26, 2024 23:04
@amyleadem amyleadem requested review from mejiaj, cathybaptista and CTGM-Bixal and removed request for cathybaptista September 26, 2024 23:10
@amyleadem amyleadem added this to the uswds 3.9.0 milestone Sep 26, 2024
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.

@amyleadem a nice addition, good work.

I was able to confirm new layout utils are generated when I add a custom breakpoint.

Input

// _settings-utilities.scss
$theme-utility-breakpoints-custom: (
  "jumbo": 2000px,
)

Output

// uswds.css
/* … */
@media all and (min-width: 125em){
  .grid-row.jumbo\:grid-gap-0{
    margin-left:0;
    margin-right:0;
  }
  .grid-row.jumbo\:grid-gap-0 > *{
    padding-left:0;
    padding-right:0;
  }

Copy link
Contributor

@CTGM-Bixal CTGM-Bixal left a comment

Choose a reason for hiding this comment

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

Confirming the following:

  • .widescreen\:grid-container and .new-breakpoint\:grid-container match after updating custom breakpoint
  • .widescreen\:grid-gap and .new-breakpoint\:grid-gap match after updating custom breakpoint
  • .widescreen\:grid-col and .new-breakpoint\:grid-col match after updating custom breakpoint
  • .widescreen\:grid-offset and .new-breakpoint\:grid-offset match after updating custom breakpoint

Thus, everything looks good to me!

@amyleadem
Copy link
Contributor Author

amyleadem commented Oct 1, 2024

Since we have two approvals on this, I'm going to merge it into the cm-custom-breakpoints branch for final testing.

@amyleadem amyleadem merged commit 9c6fbd7 into cm-custom-breakpoints Oct 1, 2024
3 checks passed
@amyleadem amyleadem removed this from the uswds 3.9.0 milestone Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants