-
Notifications
You must be signed in to change notification settings - Fork 934
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
USWDS - Prose: Placeholder fix. Resolves #5094 #5158
Conversation
|
@mejiaj @amyleadem This is the alternative solution mentioned in James' comment This maintains current develop styles but it does move them in the output CSS. Here is an easel that shows the relevant difference between files and verifies all necessary prose styles are present.: usa prose refactor I tried adding colored arrows to help connect the changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mahoneycm, I have started my review but need to step away for a bit. In the meantime, I found an error when $theme-global-content-styles is set to true because it is looking for the now missing usa-prose-link. I've also added some comments below with notes and a couple questions about code redundancy. I will cycle back later, but let me know if you have questions in the meantime.
So far the new solution appears to be on track, but there just a couple things to look at.
| p { | ||
| line-height: line-height($theme-body-font-family, $theme-body-line-height); | ||
| margin-bottom: 0; | ||
| margin-top: 0; | ||
| max-width: measure($theme-text-measure); | ||
|
|
||
| + * { | ||
| margin-top: $theme-paragraph-margin-top; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious - this appears to be redundant with a good chunk of the typeset-p mixin. Is there a way to reduce redundancy without having a negative impact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been able to successfully use the typeset mixins without it incorrectly setting *+.usa-prose p as the top-margin selector, unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that, I'm going to use @mejiaj's typset-base recommendation to alleviate some of the redundancy!
| @include u-margin-y(0); | ||
| clear: both; | ||
|
|
||
| + * { | ||
| margin-top: $theme-paragraph-margin-top; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here - feels redundant with the rules with typeset-heading. Can we reduce code redundancy here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution outputs what I would expect. If we go this route we should consider adding guidance to users (if any) that were using the removed extends.
Alternatively, we should consider simplifying in the future. By doing something like:
.usa-prose {
& > {
@include usa-list-styles;
@include usa-table-styles;
// Adds consistent margin to *all* child elements
* + * {
margin-top: $theme-paragraph-margin-top !important;
}
…H1-H6 styles
// Only override headers
* + {
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: $theme-heading-margin-top !important;
}
}
}
}| line-height: line-height($theme-body-font-family, $theme-body-line-height); | ||
| margin-bottom: 0; | ||
| margin-top: 0; | ||
| max-width: measure($theme-text-measure); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid duplication, you could create a typeset-heading-base and typeset-p-base that include these styles in typeset.scss.
//
// typeset.scss
//
@mixin typeset-heading-base {
@include u-margin-y(0);
clear: both;
}
@mixin typeset-heading {
@include typeset-heading-base;
* + & {
margin-top: $theme-heading-margin-top;
}
+ * {
margin-top: $theme-paragraph-margin-top;
}
}
// typeset element mixins
@mixin typset-p-base {
line-height: line-height($theme-body-font-family, $theme-body-line-height);
margin-bottom: 0;
margin-top: 0;
max-width: measure($theme-text-measure);
}
@mixin typeset-p {
@include typset-p-base;
* + & {
margin-top: $theme-paragraph-margin-top;
}
+ * {
margin-top: $theme-paragraph-margin-top;
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. I think it'll clean up the usa-prose class nicely!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to use the typset-p/heading-base mixin and I personally like the clean-up it offers!
Using * + * did not work as expected but I was able to use *:not(:first-child) to achieve the same result
This will assist us in eliminating repeated code for usa-prose
… typeset-heading-base
|
@mejiaj @amyleadem ok! So I've completed some refactoring by a combination of creating I've taken a stab at some basic SASS unit testing to make sure that our nested selectors are working as expected! I'd love your feedback whenever you have a chance to see if there are other enhancements I may be missing, or if we can test further with the unit tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, minor comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mahoneycm This is looking good! It is feeling cleaner with each iteration. Thanks a ton for hanging in there with this one. Only thing I have to flag is the failed Sass test that is causing the build error.
- Confirm that vertical margins look correct in the
usa-prosestory - Confirm that vertical margins look correct when
$theme-global-paragraph-styles and$theme-global-content-styles are set to true - Confirm that
* + &references have been accounted for in the compiled CSS - Confirm that the error is resolved in the test repo
- Confirm that updating values in
$theme-heading-margin-topand$theme-paragraph-margin-topupdates relevant values. - Confirm
npm startruns without error - Confirm
npm testruns without error- Receiving an error with the prose Sass test
- Confirm
gulp buildSassruns without error - Confirm no errors when
$theme-global-content-stylesis set to true - Check visual display on Safari, Firefox, Edge, Chrome
|
@mahoneycm can you please look into the failing test? |
|
@mejiaj @amyleadem Looks like when I broke it when I tried formatting the test scss. I believe it was only because of the order of the output not matching the expected order. Moving the expected results to match the actual outputs did the trick! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the test!
|
@thisisdano Ready for final review! |
|
I'll draw up a changelog PR for this change. |
|
@thisisdano I created a changelog of this one before I left yesterday as well, let me know if you want me to go ahead and close this ticket: uswds/uswds-site#2095 I also wanted to note I did mark it as a breaking change because it removes the |
Alternative solution from #4962
Summary
Reverts
usa-proseplaceholders to use typeset mixins to resolve compilation errors.Breaking change
usa-prose-mixins and placeholders. Users should instead usetypeset-mixins in their place.Site changelog PR
uswds/uswds-site#2095
Related issue
Closes #4962
Preview link
Prose →
Problem statement
This work resolves two separate issues:
%usa-prose-placeholders.& >selector1: Build errors with placeholder:
Sass can throw errors when we rely on
@extendand placeholders in certain situations.From #4962:
2: Compilation errors with mixins nested under the
& >selectorThis would result in the unexpected assignment of the
&selector and in turn, incorrectly attach styles to classesSolution
usa-proseplaceholder to a mixintypesetmixins and directly into theusa-prosestyle definitionsusa-prosemixins in favor oftypeset-mixinsFrom @amyleadem in #5043:
Sass seems to get confused when * + & is brought in from another file via a mixin (more details in #4576). Additionally, Sass can throw errors in limited circumstances when we rely on @extend and placeholders.
The key conclusion is that
* + &does not currently seem to be a viable addition to mixins or placeholders. By moving all* + &out of mixins and placeholders and directly into the style definitions, we can remove the risk of Sass confusion.Note: The downside of this solution is that it requires some code repetition, but that might be slightly mitigated by creating variables/settings for the heading and paragraph top margins.
Major changes
This PR removes
usa-prose-mixins and placeholders. Users should instead usetypeset-mixins in their place.List of mixins removed:
New settings variables
$theme-heading-margin-top$theme-paragraph-margin-topTesting and review
usa-prosestyles and make sure* + &selectors are correctly targetting headings and p tagsnpm linkto create a symlink to the packagenpm link @uswds/uswdsto replace USWDS package with the symlinknpm buildand confirm no build errorsgit pull origin [base branch]to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch isdevelop).npm run prettier:scssto format any Sass updates.npm testand confirm that all tests pass.