Skip to content

Commit

Permalink
feat(shape): add feature targeting to public mixins (#4384)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba authored and kfranqueiro committed Feb 8, 2019
1 parent ed4c945 commit e0860dd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 39 deletions.
18 changes: 10 additions & 8 deletions packages/mdc-button/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,18 @@
}

@mixin mdc-button-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
@include mdc-shape-radius(mdc-shape-resolve-percentage-radius($mdc-button-height, $radius), $rtl-reflexive);
}
@include mdc-shape-radius(
mdc-shape-resolve-percentage-radius($mdc-button-height, $radius),
$rtl-reflexive,
$query: $query
);

&.mdc-button--dense {
@include mdc-feature-targets($feat-structure) {
@include mdc-shape-radius(mdc-shape-resolve-percentage-radius($mdc-dense-button-height, $radius), $rtl-reflexive);
}
@include mdc-shape-radius(
mdc-shape-resolve-percentage-radius($mdc-dense-button-height, $radius),
$rtl-reflexive,
$query: $query
);
}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/mdc-card/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,7 @@
}

@mixin mdc-card-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
@include mdc-shape-radius($radius, $rtl-reflexive);
}
@include mdc-shape-radius($radius, $rtl-reflexive, $query: $query);
}

@mixin mdc-card-media-aspect-ratio($x, $y, $query: mdc-feature-all()) {
Expand Down
9 changes: 2 additions & 7 deletions packages/mdc-list/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@
.mdc-list-group__subheader {
$mdc-list-subheader-virtual-height: 3rem;
$mdc-list-subheader-leading: map-get(map-get($mdc-typography-styles, body1), line-height);
$mdc-list-subheader-margin:
($mdc-list-subheader-virtual-height - $mdc-list-subheader-leading) / 2;
$mdc-list-subheader-margin: ($mdc-list-subheader-virtual-height - $mdc-list-subheader-leading) / 2;

@include mdc-typography(subtitle1, $query);

Expand Down Expand Up @@ -335,12 +334,8 @@
}

@mixin mdc-list-item-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

.mdc-list-item {
@include mdc-feature-targets($feat-structure) {
@include mdc-shape-radius($radius, $rtl-reflexive);
}
@include mdc-shape-radius($radius, $rtl-reflexive, $query: $query);
}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/mdc-menu-surface/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@
}

@mixin mdc-menu-surface-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
@include mdc-shape-radius($radius, $rtl-reflexive);
}
@include mdc-shape-radius($radius, $rtl-reflexive, $query: $query);
}

//
Expand Down
28 changes: 17 additions & 11 deletions packages/mdc-shape/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@
// THE SOFTWARE.
//

@import "@material/feature-targeting/functions";
@import "@material/feature-targeting/mixins";
@import "./variables";
@import "./functions";

@mixin mdc-shape-radius($radius, $rtl-reflexive: false) {
// Even if $rtl-reflexive is true, only emit RTL styles if we can't easily tell that the given radius is symmetrical
$needs-flip: $rtl-reflexive and length($radius) > 1;
@mixin mdc-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@if ($needs-flip) {
/* @noflip */
}

border-radius: mdc-shape-prop-value($radius);
@include mdc-feature-targets($feat-structure) {
// Even if $rtl-reflexive is true, only emit RTL styles if we can't easily tell that the given radius is symmetrical
$needs-flip: $rtl-reflexive and length($radius) > 1;

@if ($needs-flip) {
@include mdc-rtl {
@if ($needs-flip) {
/* @noflip */
border-radius: mdc-shape-flip-radius(mdc-shape-prop-value($radius));
}

border-radius: mdc-shape-prop-value($radius);

@if ($needs-flip) {
@include mdc-rtl {
/* @noflip */
border-radius: mdc-shape-flip-radius(mdc-shape-prop-value($radius));
}
}
}
}
10 changes: 7 additions & 3 deletions test/scss/feature-targeting.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
@import "@material/button/mixins";
@import "@material/card/mixins";
@import "@material/menu-surface/mixins";
@import "@material/checkbox/mixins";
@import "@material/elevation/mixins";
@import "@material/feature-targeting/functions";
@import "@material/list/mixins";
@import "@material/menu-surface/mixins";
@import "@material/menu/mixins";
@import "@material/radio/mixins";
@import "@material/ripple/mixins";
@import "@material/typography/mixins";
@import "@material/shape/mixins";
@import "@material/switch/mixins";
@import "@material/list/mixins";
@import "@material/typography/mixins";

.mdc-test {
// Button
Expand Down Expand Up @@ -80,6 +81,9 @@
@include mdc-ripple-radius-bounded($query: mdc-feature-any());
@include mdc-ripple-radius-unbounded($query: mdc-feature-any());

// Shape
@include mdc-shape-radius(1px 2px, true, $query: mdc-feature-any());

// Switch
@include mdc-switch($query: mdc-feature-any());
@include mdc-switch-toggled-on-color(on-surface, $query: mdc-feature-any());
Expand Down

0 comments on commit e0860dd

Please sign in to comment.