Skip to content

Commit 5450755

Browse files
skrthebosscrisbeto
authored andcommitted
fix(material/core): fix opacity in elevation mixin (#26805)
* fix(material/core): fix opacity in elevation mixin * fixup! fix(material/core): fix opacity in elevation mixin (cherry picked from commit 514c113)
1 parent 7d8c5d7 commit 5450755

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/material/core/style/_elevation.scss

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,30 @@ $prefix: 'mat-elevation-z';
4343
@else {
4444
// Copied from @material/elevation/_elevation-theme.scss#_box-shadow
4545
// TODO(mmalerba): Add support for graceful handling of CSS var color to MDC.
46-
$shadow-color:
47-
if(meta.type-of($color) == color and $opacity != null, rgba($color, $opacity), $color);
4846
$umbra-z-value: map.get(mdc-elevation.$umbra-map, $zValue);
4947
$penumbra-z-value: map.get(mdc-elevation.$penumbra-map, $zValue);
5048
$ambient-z-value: map.get(mdc-elevation.$ambient-map, $zValue);
49+
50+
$color-opacity: if($opacity != null, $opacity, 1);
51+
$umbra-color: _compute-color-opacity($color, mdc-elevation.$umbra-opacity * $color-opacity);
52+
$penumbra-color:
53+
_compute-color-opacity($color, mdc-elevation.$penumbra-opacity * $color-opacity);
54+
$ambient-color: _compute-color-opacity($color, mdc-elevation.$ambient-opacity * $color-opacity);
55+
5156
$box-shadow: (
52-
#{'#{$umbra-z-value} #{$shadow-color}'},
53-
#{'#{$penumbra-z-value} #{$shadow-color}'},
54-
#{$ambient-z-value} $shadow-color
57+
#{'#{$umbra-z-value} #{$umbra-color}'},
58+
#{'#{$penumbra-z-value} #{$penumbra-color}'},
59+
#{$ambient-z-value} $ambient-color
5560
);
5661
@include mdc-elevation.shadow($box-shadow);
5762
}
5863
}
5964

6065
// Applies the elevation to an element in a manner that allows
6166
// consumers to override it via the Material elevation classes.
62-
@mixin overridable-elevation($zValue, $color: $color) {
67+
@mixin overridable-elevation($zValue, $color: $color, $opacity: null) {
6368
&:not([class*='#{$prefix}']) {
64-
@include elevation($zValue, $color);
69+
@include elevation($zValue, $color, $opacity);
6570
}
6671
}
6772

@@ -89,3 +94,12 @@ $prefix: 'mat-elevation-z';
8994
$easing: $transition-timing-function) {
9095
transition: private-transition-property-value($duration, $easing);
9196
}
97+
98+
@function _compute-color-opacity($color, $opacity) {
99+
@if meta.type-of($color) == color and $opacity != null {
100+
@return rgba($color, $opacity);
101+
}
102+
@else {
103+
@return $color;
104+
}
105+
}

0 commit comments

Comments
 (0)