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

Add package entrypoints for granular stylesheet loading #214

Merged
merged 2 commits into from
Apr 28, 2021
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented Apr 28, 2021

Why: To limit or control the loading of styles.

Use-cases:

  1. Avoid specificity conflicts between utility classes and a consuming project's custom components
  2. Load only required mixins and functions to support CSS code splitting

This also mirrors USWDS packages, with two main differences:

  • Simplifies naming of uswds-components and uswds-utilities to just components and utilities
  • Extracts utilities-required from utilities to allow non-rendering import of utility mixins.

See:

Next steps:

Per the above use-cases, this is useful for identity-idp and the following diff would help toward resolving existing specificity conflicts and simplify code splitting usage:

diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss
index 8576adb31..9a5ab78d6 100644
--- a/app/assets/stylesheets/application.css.scss
+++ b/app/assets/stylesheets/application.css.scss
@@ -1,6 +1,9 @@
 @import 'variables/colors';
 @import 'variables/app';
 @import 'vendor';
-@import 'identity-style-guide/dist/assets/scss/styles';
+@import 'identity-style-guide/dist/assets/scss/packages/required';
+@import 'identity-style-guide/dist/assets/scss/packages/global';
+@import 'identity-style-guide/dist/assets/scss/packages/components';
 @import 'components/all';
 @import 'print';
+@import 'identity-style-guide/dist/assets/scss/packages/utilities';
diff --git a/config/webpack/environment.js b/config/webpack/environment.js
index c55bb013f..65fd2682b 100644
--- a/config/webpack/environment.js
+++ b/config/webpack/environment.js
@@ -25,19 +25,8 @@ const sassLoader = environment.loaders.get('sass');
 sassLoader.use.find(({ loader }) => loader === 'sass-loader').options.additionalData = `
 $font-path: '~identity-style-guide/dist/assets/fonts';
 $image-path: '~identity-style-guide/dist/assets/img';
-@import '~identity-style-guide/dist/assets/scss/functions/asset-path';
-@import '~identity-style-guide/dist/assets/scss/functions/focus';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/custom-styles';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/general';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/typography';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/spacing';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/color';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/utilities';
-@import '~identity-style-guide/dist/assets/scss/uswds-theme/components';
-@import '~identity-style-guide/dist/assets/scss/uswds/packages/required';
-@import '~identity-style-guide/dist/assets/scss/uswds/utilities/palettes/all';
-@import '~identity-style-guide/dist/assets/scss/uswds/utilities/rules/all';
-@import '~identity-style-guide/dist/assets/scss/uswds/utilities/rules/package';`;
+@import '~identity-style-guide/dist/assets/scss/packages/required';
+@import '~identity-style-guide/dist/assets/scss/packages/utilities-required';`;
 
 sassLoader.use.find(({ loader }) => loader === 'css-loader').options.sourceMap = false;

Example conflicts:

**Why**: To limit or control the loading of styles.

Use-cases:

1. Avoid specificity conflicts between utility classes and a consuming project's custom components
2. Load only required mixins and functions to support CSS code splitting

This also mirrors USWDS packages, with two main differences:

- Simplifies naming of `uswds-components` and `uswds-utilities` to just `components` and `utilities`
- Extracts `utilities-required` from `utilities` to allow non-rendering import of utility mixins.

See:

- https://designsystem.digital.gov/components/packages/
- https://github.com/uswds/uswds/blob/develop/src/stylesheets/uswds.scss
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM

@aduth
Copy link
Member Author

aduth commented Apr 28, 2021

Test failure is visual regression for expected content changes to Usage page.

@aduth aduth merged commit aada50c into main Apr 28, 2021
@aduth aduth deleted the aduth-packages branch April 28, 2021 19:06
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.

2 participants