-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(switch): add feature targeting for styles #4275
feat(switch): add feature targeting for styles #4275
Conversation
packages/mdc-switch/_mixins.scss
Outdated
@@ -21,10 +21,89 @@ | |||
// | |||
|
|||
@import "@material/theme/mixins"; | |||
@import "@material/ripple/common"; |
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 actually emits a bunch of styles, instead you should @include
the mixin version:
@mixin mdc-switch(...) {
$feat-animation: ...
$feat-color: ...
$feat-structure: ...
@include mdc-ripple-common($query);
...
}
You can add an entry for mdc-switch
here: https://github.com/material-components/material-components-web/blob/master/test/scss/feature-targeting.scss and then run npm run test:feature-targeting
to ensure that you've targeted all the styles
packages/mdc-switch/_mixins.scss
Outdated
@include mdc-switch-toggled-on-thumb-color($mdc-switch-baseline-theme-color); | ||
@include mdc-switch-toggled-off-track-color($mdc-switch-toggled-off-track-color); | ||
@include mdc-switch-toggled-off-thumb-color($mdc-switch-toggled-off-thumb-color); | ||
@include mdc-switch-toggled-off-ripple-color($mdc-switch-toggled-off-ripple-color); |
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.
mdc-states
can take a $query
, so pass it through here and then pass it through to mdc-states
packages/mdc-switch/_mixins.scss
Outdated
|
||
@include mdc-feature-targets($feat-structure) { | ||
@include mdc-rtl-reflexive-position(left, $mdc-switch-tap-target-initial-position); | ||
@include mdc-ripple-surface(); |
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.
mdc-ripple-surface
takes a $query
packages/mdc-switch/_mixins.scss
Outdated
} | ||
} | ||
|
||
@mixin mdc-switch__native-control_($query: mdc-feature-all()) { |
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.
since this whole mixin is structure, there's no need to pass in $query
, just wrap the @include
packages/mdc-switch/_mixins.scss
Outdated
$feat-structure: mdc-feature-create-target($query, structure); | ||
|
||
@include mdc-feature-targets($feat-structure) { | ||
@include mdc-elevation(2); |
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.
mdc-elevation
should actually be under color, since users can customize the shadow color
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.
Replying to this comment to note this hasn't been fixed yet.
Updated based on the feedback from @mmalerba. |
08f8f7f
to
7d64bdc
Compare
// postcss-bem-linter: end | ||
} | ||
|
||
@mixin mdc-switch-toggled-on-color($color, $query: mdc-feature-all()) { |
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.
@kfranqueiro should we add feature targeting to only the main public mixin, or these ones too? (If we are adding it here too, we should add these mixins to the test that verifies nothing is emitted for empty query, I think it would fail currently)
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.
That's a good point, this mixin is not invoked by the base styles, so we don't necessarily need to cover it, if the goal is specifically to add feature targeting to the base emitted styles. If you're fine with that, then I think we can omit $query
from mdc-switch-toggled-on-color
and mdc-switch-toggled-off-color
.
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 could also see doing it, just for the sake of consistency on public mixins. If we always do it then people don't have to think about whether this is one of the ones that supports it.
Also for things like disabling animations, you probably do want to have the ability to exclude the animation
feature from all mixins, not just the base one.
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.
If we're parameterizing $query
here, then I think we need to enclose the first 2 mixin invocations within a color feature-targets block (same for mdc-switch-toggled-off-color
), and invoke these in test/scss/feature-targeting.scss
as Miles suggested.
It looks like the order of some of the rules got swapped around. I'm not sure if it matters or not (potentially could due to specificity reasons). Here's the before and after for diffing: |
I don't think there's much overlap between the different style declarations so we shouldn't run into any issues with ordering. |
7d64bdc
to
f40bcc3
Compare
@kfranqueiro I've rebased the PR and double-checked the output changes. It seems like a couple of unrelated styles got swapped which didn't have a visual effect. |
f40bcc3
to
c4a4751
Compare
Looks like the changes that catch nested feature target mixins caught a couple in this PR. I moved a couple of styles around to fix the errors. |
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 made a few suggestions, including some that make the diff easier to look at, but it looks like all the styles are intact.
// postcss-bem-linter: end | ||
} | ||
|
||
@mixin mdc-switch-toggled-on-color($color, $query: mdc-feature-all()) { |
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.
If we're parameterizing $query
here, then I think we need to enclose the first 2 mixin invocations within a color feature-targets block (same for mdc-switch-toggled-off-color
), and invoke these in test/scss/feature-targeting.scss
as Miles suggested.
packages/mdc-switch/_mixins.scss
Outdated
$feat-color: mdc-feature-create-target($query, color); | ||
$feat-structure: mdc-feature-create-target($query, structure); | ||
|
||
@include mdc-states($mdc-switch-baseline-theme-color, false, $query); |
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.
Move mdc-states
after mdc-ripple-surface
(mdc-ripple-surface
first is a common pattern across the packages that use it)
packages/mdc-switch/_mixins.scss
Outdated
@include mdc-ripple-common($query); | ||
|
||
.mdc-switch { | ||
@include mdc-switch-toggled-off-ripple-color($mdc-switch-toggled-off-ripple-color, $query); |
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.
Move this to the end of this block to keep it near the other related color styles (and reduce diff)
packages/mdc-switch/_mixins.scss
Outdated
@include mdc-switch__thumb-underlay_($query); | ||
} | ||
|
||
.mdc-switch__native-control { |
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.
Move this above .mdc-switch__track
to reduce diff
c4a4751
to
ed2bbf5
Compare
@kfranqueiro I've addressed the latest set of feedback. Can you take a look at |
ed2bbf5
to
bbc93a2
Compare
Sets up style feature targeting for the switch component.
bbc93a2
to
5f6ad5f
Compare
The update to |
Sets up style feature targeting for the switch component.