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

feat(switch): add feature targeting for styles #4275

Merged
merged 7 commits into from
Feb 1, 2019

Conversation

crisbeto
Copy link
Collaborator

Sets up style feature targeting for the switch component.

@@ -21,10 +21,89 @@
//

@import "@material/theme/mixins";
@import "@material/ripple/common";
Copy link
Collaborator

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

@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);
Copy link
Collaborator

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


@include mdc-feature-targets($feat-structure) {
@include mdc-rtl-reflexive-position(left, $mdc-switch-tap-target-initial-position);
@include mdc-ripple-surface();
Copy link
Collaborator

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

}
}

@mixin mdc-switch__native-control_($query: mdc-feature-all()) {
Copy link
Collaborator

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

$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
@include mdc-elevation(2);
Copy link
Collaborator

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

Copy link
Contributor

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.

@crisbeto
Copy link
Collaborator Author

Updated based on the feedback from @mmalerba.

// postcss-bem-linter: end
}

@mixin mdc-switch-toggled-on-color($color, $query: mdc-feature-all()) {
Copy link
Collaborator

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)

Copy link
Contributor

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.

Copy link
Collaborator

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.

Copy link
Contributor

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.

@mmalerba
Copy link
Collaborator

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:

switch-before.css
switch-after.css

@crisbeto
Copy link
Collaborator Author

I don't think there's much overlap between the different style declarations so we shouldn't run into any issues with ordering.

@crisbeto
Copy link
Collaborator Author

@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.

@crisbeto
Copy link
Collaborator Author

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.

Copy link
Contributor

@kfranqueiro kfranqueiro left a 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()) {
Copy link
Contributor

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.

$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);
Copy link
Contributor

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)

@include mdc-ripple-common($query);

.mdc-switch {
@include mdc-switch-toggled-off-ripple-color($mdc-switch-toggled-off-ripple-color, $query);
Copy link
Contributor

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)

@include mdc-switch__thumb-underlay_($query);
}

.mdc-switch__native-control {
Copy link
Contributor

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

@crisbeto
Copy link
Collaborator Author

@kfranqueiro I've addressed the latest set of feedback. Can you take a look at feature-targeting.scss in particular? I'm not sure that I completely understood what you meant with your comment.

@kfranqueiro
Copy link
Contributor

The update to feature-targeting.scss looked fine except that it also needed to invoke the baseline mdc-switch mixin to test feature targeting in that. I added that and fixed lint issues in the mixins (check with npm run lint:css locally to catch them early).

@kfranqueiro kfranqueiro merged commit 4836293 into material-components:master Feb 1, 2019
@jamesmfriedman jamesmfriedman mentioned this pull request Feb 5, 2019
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants