-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS - Card: Fix $theme-card-border-width
calculation errors
#5325
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
Conversation
Hi @mahoneycm,
This happens with many of the accepted token values for the setting. Is it possible to resolve these? |
@amyleadem For context, the rem unit is caused by the how do we feel about resolving the warning by adding $partial-values: (
zero-zero: (
0: 0,
+ 0rem: 0,
), or by adding a rem specific map similar to $system-spacing-em: $system-spacing-em: (
small: (
"05em": 0.5em,
1em: 1em,
105em: 1.5em,
2em: 2em,
),
); I see a benefit in this because $theme-card-border-width: 0;
.usa-card__media--exdent {
@include u-margin-right(units($theme-card-border-width) * -1);
@include u-margin-left(0);
} |
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 see the warnings Amy mentioned above. We should look at potential alternatives.
For context, the rem unit is caused by the
spacing-multiple()
function I added to the0
value in$system-spacing.special
. The functions that do not require the unit, drop the unit on output to just become0
(example of this below)
Are you saying this is what's causing the rem warning on compile? The warnings point to examples like this:
@include u-margin-left(units($theme-card-border-width) * -1);
Which makes sense because u-margin-left
expects tokens, not the value of units()
.
how do we feel about resolving the warning by adding
0rem
to the$partial-values
map? The warning disappears when this one line is added.
Adding unit specific values, in this case rem
seems like a can of worms. Because then we'd have to add in values for em, px, ch, and any other unit
that could potentially fail.
Have we investigated the following?
- Swapping utility mixins for native properties so we can pass
units()
. - Using internal logic to check for border width values of 0 or none and then passing that to
calc()
. - Alternatively, we could get rid of
calc()
, but this doesn't seem like a long term solution.
@mejiaj swapping the utility mixins for native properties works. Should I follow that pattern throughout the card scss? Or only where There also seems to be some general cleanup that can be done here. It references Let me know if you want me to go ahead and swap the native properties and I can push up a PR. I'll remove the exdent class definition as well and we can discuss from there |
I was originally thinking only where |
@mejiaj Nope! That sounds good to me and removed the errors in my initial testing! I was just curious on where you stood from a code consistency standpoint. I'll work on getting these updated. |
@mejiaj @amyleadem Updated and ready for review! I also updated the PR description and test repo I also found a visual bug that exists in develop. Reported at #5401 |
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 appreciate the test you built out, @mahoneycm . Always makes it easy.
Looks good to me!
- Confirm no compilation or
calc
errors with string tokens - Confirm no compilation or
calc
errors with0
value - Confirm no visual regression
- Confirm no compile warnings
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. I didn't find any visual regressions in USWDS or Sandbox branches.
I've tested and can confirm:
- Zero visual regressions.
- Zero compile errors.
- Border width tokens work in
$theme-card-border-width
1.
Sandbox testing
Thanks for including a test sandbox branch. I made additional changes locally. Changes include:
- Install and compare USWDS latest.
- Updating flag default to use media exdent.
Footnotes
-
⚠️ Documentation for$theme-card-border-width
showsunits
as token, but border width tokens only support $system-spacing maps for `smaller, small, and zero-zero. See _properties.scss, which depends on spacing.scss ↩
.usa-card__img { | ||
@include u-radius(0); | ||
@include u-radius-right($theme-card-border-radius); | ||
} |
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.
@@ -99,7 +99,7 @@ $system-spacing: ( | |||
// 1400px | |||
), | |||
"special": ( | |||
0: 0, | |||
0: spacing-multiple(0), |
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 as to why this was changed? The commit message doesn't seem to mention why. I just see:
Update 0 spacing unit in system-spacing special map
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 one is outlined under the solution section of the PR description. Essentially, it passes the value as 0rem
instead of a unitless 0
, which is needed for calc()
. SCSS does it's magic and drops the rem
unit when it is not needed automatically so it'll remain unitless elsewhere.
- Update
$system-spacing.special
0 value from0: 0
to0: spacing-multiple(0)
- This falls in line with other
$system-spacing
tokens
"05": spacing-multiple(0.5)
1: spacing-multiple(1),
units()
is the only function that references$project-spacing-standard
- Resolves this issue anywhere
units(0)
is used within acalc()
function
- Across USWDS, sass interpolation (
#{}
) is used withincalc()
to maintain therem
unit passed in by theunits()
function#{units($theme-card-border-width)}
results in0rem
- Other references to
units(0)
still result in unitless0
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 thanks for the reply and apologies for missing it. I must've confused it since the formatting is similar to the testing & review list 🤦.
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.
Excellent discussion/review to get to a really good, consistent, and understandable solution
Summary
Fixed a bug that prevented
$theme-card-border-width
from accepting0
or string tokens.Breaking change
This is not a breaking change.
Related issue
Closes #5162
Related pull requests
Changelog entry →
Preview link
Card storybook preview →
Test repo →
Problem statement
Setting
$theme-card-border-width
to zeroThis caused errors when setting the card radius using the
calc()
function becausecalc()
cannot take unitless numbers1Setting
$theme-card-border-width
to a string tokenExdent variants of card use the variable to set a negative border width the following calculation:
When using a string token like
"05"
, this results inu-margin-x(-"05")
which breaks the margin function because it is not a valid USWDS tokenSolution
$system-spacing.special
0 value from0: 0
to0: spacing-multiple(0)
$system-spacing
tokens"05": spacing-multiple(0.5)
1: spacing-multiple(1),
units()
is the only function that references$project-spacing-standard
units(0)
is used within acalc()
function#{}
) is used withincalc()
to maintain therem
unit passed in by theunits()
function#{units($theme-card-border-width)}
results in0rem
units(0)
still result in unitless0
_footer.scss
_border
u-margin
mixins for native solutions where$theme-card-border-width
is passed in.Testing and review
develop
, set$theme-card-border-width
to0
.usa-card__img
and verifycalc()
is not working correctly$theme-card-border-width
to"05"
(or another string token)$theme-card-border-width
will be set to0
by default.usa-card__img
and verifycalc()
is working correctly_uswds-theme.scss
and set$theme-card-border-width
to"05"
.usa-card__media--exdent
class and check negative margins are set correctlyTesting Checklist
$theme-card-border-width: 0
does not breakcalc()
function on.usa-card__img
$theme-card-border-width: "05"
does not cause build errorsAdditional info
I discovered an existing visual bug when setting the border to a large value. I created a ticket at #5401
Before opening this PR, make sure you’ve done whichever of these applies to you:
git 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:sass
to format any Sass updates.npm test
and confirm that all tests pass.Footnotes
https://sass-lang.com/documentation/values/calculations#:~:text=Other%20calculations%20don%E2%80%99t%20allow%20unitless%20numbers%20to%20be%20added%20to%2C%20subtracted%20from%2C%20or%20compared%20to%20numbers%20with%20units. ↩