Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
feat(elevation): add feature targeting for styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Jan 29, 2019
1 parent 9206472 commit 9332960
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
22 changes: 10 additions & 12 deletions packages/mdc-button/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,19 @@
$feat-animation: mdc-feature-create-target($query, animation);
$feat-color: mdc-feature-create-target($query, color);

@include mdc-feature-targets($feat-color) {
@include mdc-elevation(2);
@include mdc-elevation(2, $query: $query);

&:hover,
&:focus {
@include mdc-elevation(4);
}
&:hover,
&:focus {
@include mdc-elevation(4, $query: $query);
}

&:active {
@include mdc-elevation(8);
}
&:active {
@include mdc-elevation(8, $query: $query);
}

&:disabled {
@include mdc-elevation(0);
}
&:disabled {
@include mdc-elevation(0, $query: $query);
}

@include mdc-feature-targets($feat-animation) {
Expand Down
19 changes: 13 additions & 6 deletions packages/mdc-elevation/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
// THE SOFTWARE.
//

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

// Applies the correct CSS rules to an element to give it the elevation specified by $z-value.
// The $z-value must be between 0 and 24.
// If $color has an alpha channel, it will be ignored and overridden. To increase the opacity of the shadow, use
// $opacity-boost.
@mixin mdc-elevation($z-value, $color: $mdc-elevation-baseline-color, $opacity-boost: 0) {
@mixin mdc-elevation($z-value, $color: $mdc-elevation-baseline-color, $opacity-boost: 0, $query: mdc-feature-all()) {
@if type-of($z-value) != number or not unitless($z-value) {
@error "$z-value must be a unitless number, but received '#{$z-value}'";
}
Expand All @@ -36,6 +38,8 @@
@error "$z-value must be between 0 and 24, but received '#{$z-value}'";
}

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

$color: mdc-theme-prop-value($color);

$umbra-z-value: map-get($mdc-elevation-umbra-map, $z-value);
Expand All @@ -46,10 +50,12 @@
$penumbra-color: rgba($color, $mdc-elevation-penumbra-opacity + $opacity-boost);
$ambient-color: rgba($color, $mdc-elevation-ambient-opacity + $opacity-boost);

box-shadow:
#{"#{$umbra-z-value} #{$umbra-color}"},
#{"#{$penumbra-z-value} #{$penumbra-color}"},
#{$ambient-z-value} $ambient-color;
@include mdc-feature-targets($feat-color) {
box-shadow:
#{"#{$umbra-z-value} #{$umbra-color}"},
#{"#{$penumbra-z-value} #{$penumbra-color}"},
#{$ambient-z-value} $ambient-color;
}
}

// Returns a string that can be used as the value for a `transition` property for elevation.
Expand All @@ -64,6 +70,7 @@
// ```
@function mdc-elevation-transition-value(
$duration: $mdc-elevation-transition-duration,
$easing: $mdc-elevation-transition-timing-function) {
$easing: $mdc-elevation-transition-timing-function
) {
@return #{$mdc-elevation-property} #{$duration} #{$easing};
}
5 changes: 5 additions & 0 deletions test/scss/feature-targeting.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "@material/button/mixins";
@import "@material/checkbox/mixins";
@import "@material/elevation/mixins";
@import "@material/feature-targeting/functions";
@import "@material/menu/mixins";
@import "@material/radio/mixins";
Expand All @@ -13,6 +14,10 @@

@include mdc-checkbox($query: mdc-feature-any());

// Elevation

@include mdc-elevation(0, $query: mdc-feature-any());

// Menu

@include mdc-menu($query: mdc-feature-any());
Expand Down

0 comments on commit 9332960

Please sign in to comment.