Skip to content

Commit 7e94186

Browse files
authored
feat(material/core): move MDC-based elevation styles out of experimental (#25486)
* feat(material/core): move MDC-based elevation styles out of experimental * handle CSS var elevation colors * undo rearranging core theme mixins, since it broke some things * undo forwarding mdc-core-color to core-color * fix lint issues
1 parent c5c69d2 commit 7e94186

File tree

9 files changed

+44
-193
lines changed

9 files changed

+44
-193
lines changed

src/material-experimental/_index.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Structural
2-
@forward './mdc-core/elevation' as mdc-* show mdc-elevation, mdc-overridable-elevation;
3-
41
// Theme bundles
52
@forward './mdc-core/theming/all-theme' show all-mdc-component-themes;
63
@forward './mdc-core/color/all-color' show all-mdc-component-colors;

src/material-experimental/mdc-core/_core-theme.scss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
@use 'sass:map';
22
@use '@angular/material' as mat;
33

4-
@use './elevation';
5-
6-
74
@mixin color($config-or-theme) {
85
$config: mat.get-color-config($config-or-theme);
96

@@ -15,11 +12,11 @@
1512
// `mat-mdc-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the
1613
// element is elevated.
1714
@for $zValue from 0 through 24 {
18-
$selector: elevation.$prefix + $zValue;
15+
$selector: 'mat-mdc-elevation-z' + $zValue;
1916
// We need the `mat-mdc-elevation-specific`, because some MDC mixins
2017
// come with elevation baked in and we don't have a way of removing it.
2118
.#{$selector}, .mat-mdc-elevation-specific.#{$selector} {
22-
@include elevation.private-theme-elevation($zValue, $config);
19+
@include mat.private-theme-elevation($zValue, $config);
2320
}
2421
}
2522

@@ -38,7 +35,7 @@
3835

3936
@mixin typography($config-or-theme) {
4037
$config: mat.private-typography-to-2018-config(
41-
mat.get-typography-config($config-or-theme));
38+
mat.get-typography-config($config-or-theme));
4239

4340
@include mat.option-typography($config-or-theme);
4441
@include mat.optgroup-typography($config-or-theme);

src/material-experimental/mdc-core/_elevation.scss

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/material/core/_core-theme.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
@use './selection/pseudo-checkbox/pseudo-checkbox-theme';
88
@use './style/elevation';
99

10-
1110
@mixin color($config-or-theme) {
1211
$config: theming.get-color-config($config-or-theme);
12+
1313
// Wrapper element that provides the theme background when the user's content isn't
1414
// inside of a `mat-sidenav-container`. Note that we need to exclude the ampersand
1515
// selector in case the mixin is included at the top level.
@@ -25,7 +25,10 @@
2525
// `mat-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the element is
2626
// elevated.
2727
@for $zValue from 0 through 24 {
28-
.#{elevation.$prefix}#{$zValue} {
28+
$selector: elevation.$prefix + $zValue;
29+
// We need the `mat-mdc-elevation-specific`, because some MDC mixins
30+
// come with elevation baked in and we don't have a way of removing it.
31+
.#{$selector}, .mat-mdc-elevation-specific.#{$selector} {
2932
@include private.private-theme-elevation($zValue, $config);
3033
}
3134
}
@@ -51,6 +54,7 @@
5154
@include pseudo-checkbox-theme.theme($theme);
5255

5356
$color: theming.get-color-config($theme);
57+
5458
@if $color != null {
5559
@include color($color);
5660
}

src/material/core/style/_elevation.scss

Lines changed: 18 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
@use 'sass:map';
2-
@use 'sass:math';
32
@use 'sass:meta';
43
@use 'variables';
5-
4+
@use '@material/elevation/elevation-theme' as mdc-elevation;
65

76
// A collection of mixins and CSS classes that can be used to apply elevation to a material
87
// element.
@@ -23,113 +22,6 @@
2322
// For an explanation of the design behind how elevation is implemented, see the design doc at
2423
// https://goo.gl/Kq0k9Z.
2524

26-
// Colors for umbra, penumbra, and ambient shadows. As described in the design doc, each elevation
27-
// level is created using a set of 3 shadow values, one for umbra (the shadow representing the
28-
// space completely obscured by an object relative to its light source), one for penumbra (the
29-
// space partially obscured by an object), and one for ambient (the space which contains the object
30-
// itself). For a further explanation of these terms and their meanings, see
31-
// https://en.wikipedia.org/wiki/Umbra,_penumbra_and_antumbra.
32-
33-
// Maps for the different shadow sets and their values within each z-space. These values were
34-
// created by taking a few reference shadow sets created by Google's Designers and interpolating
35-
// all of the values between them.
36-
37-
@function _get-umbra-map($color, $opacity) {
38-
$shadow-color: if(meta.type-of($color) == color, rgba($color, $opacity * 0.2), $color);
39-
40-
@return (
41-
0: '0px 0px 0px 0px #{$shadow-color}',
42-
1: '0px 2px 1px -1px #{$shadow-color}',
43-
2: '0px 3px 1px -2px #{$shadow-color}',
44-
3: '0px 3px 3px -2px #{$shadow-color}',
45-
4: '0px 2px 4px -1px #{$shadow-color}',
46-
5: '0px 3px 5px -1px #{$shadow-color}',
47-
6: '0px 3px 5px -1px #{$shadow-color}',
48-
7: '0px 4px 5px -2px #{$shadow-color}',
49-
8: '0px 5px 5px -3px #{$shadow-color}',
50-
9: '0px 5px 6px -3px #{$shadow-color}',
51-
10: '0px 6px 6px -3px #{$shadow-color}',
52-
11: '0px 6px 7px -4px #{$shadow-color}',
53-
12: '0px 7px 8px -4px #{$shadow-color}',
54-
13: '0px 7px 8px -4px #{$shadow-color}',
55-
14: '0px 7px 9px -4px #{$shadow-color}',
56-
15: '0px 8px 9px -5px #{$shadow-color}',
57-
16: '0px 8px 10px -5px #{$shadow-color}',
58-
17: '0px 8px 11px -5px #{$shadow-color}',
59-
18: '0px 9px 11px -5px #{$shadow-color}',
60-
19: '0px 9px 12px -6px #{$shadow-color}',
61-
20: '0px 10px 13px -6px #{$shadow-color}',
62-
21: '0px 10px 13px -6px #{$shadow-color}',
63-
22: '0px 10px 14px -6px #{$shadow-color}',
64-
23: '0px 11px 14px -7px #{$shadow-color}',
65-
24: '0px 11px 15px -7px #{$shadow-color}'
66-
);
67-
}
68-
69-
@function _get-penumbra-map($color, $opacity) {
70-
$shadow-color: if(meta.type-of($color) == color, rgba($color, $opacity * 0.14), $color);
71-
72-
@return (
73-
0: '0px 0px 0px 0px #{$shadow-color}',
74-
1: '0px 1px 1px 0px #{$shadow-color}',
75-
2: '0px 2px 2px 0px #{$shadow-color}',
76-
3: '0px 3px 4px 0px #{$shadow-color}',
77-
4: '0px 4px 5px 0px #{$shadow-color}',
78-
5: '0px 5px 8px 0px #{$shadow-color}',
79-
6: '0px 6px 10px 0px #{$shadow-color}',
80-
7: '0px 7px 10px 1px #{$shadow-color}',
81-
8: '0px 8px 10px 1px #{$shadow-color}',
82-
9: '0px 9px 12px 1px #{$shadow-color}',
83-
10: '0px 10px 14px 1px #{$shadow-color}',
84-
11: '0px 11px 15px 1px #{$shadow-color}',
85-
12: '0px 12px 17px 2px #{$shadow-color}',
86-
13: '0px 13px 19px 2px #{$shadow-color}',
87-
14: '0px 14px 21px 2px #{$shadow-color}',
88-
15: '0px 15px 22px 2px #{$shadow-color}',
89-
16: '0px 16px 24px 2px #{$shadow-color}',
90-
17: '0px 17px 26px 2px #{$shadow-color}',
91-
18: '0px 18px 28px 2px #{$shadow-color}',
92-
19: '0px 19px 29px 2px #{$shadow-color}',
93-
20: '0px 20px 31px 3px #{$shadow-color}',
94-
21: '0px 21px 33px 3px #{$shadow-color}',
95-
22: '0px 22px 35px 3px #{$shadow-color}',
96-
23: '0px 23px 36px 3px #{$shadow-color}',
97-
24: '0px 24px 38px 3px #{$shadow-color}'
98-
);
99-
}
100-
101-
@function _get-ambient-map($color, $opacity) {
102-
$shadow-color: if(meta.type-of($color) == color, rgba($color, $opacity * 0.12), $color);
103-
104-
@return (
105-
0: '0px 0px 0px 0px #{$shadow-color}',
106-
1: '0px 1px 3px 0px #{$shadow-color}',
107-
2: '0px 1px 5px 0px #{$shadow-color}',
108-
3: '0px 1px 8px 0px #{$shadow-color}',
109-
4: '0px 1px 10px 0px #{$shadow-color}',
110-
5: '0px 1px 14px 0px #{$shadow-color}',
111-
6: '0px 1px 18px 0px #{$shadow-color}',
112-
7: '0px 2px 16px 1px #{$shadow-color}',
113-
8: '0px 3px 14px 2px #{$shadow-color}',
114-
9: '0px 3px 16px 2px #{$shadow-color}',
115-
10: '0px 4px 18px 3px #{$shadow-color}',
116-
11: '0px 4px 20px 3px #{$shadow-color}',
117-
12: '0px 5px 22px 4px #{$shadow-color}',
118-
13: '0px 5px 24px 4px #{$shadow-color}',
119-
14: '0px 5px 26px 4px #{$shadow-color}',
120-
15: '0px 6px 28px 5px #{$shadow-color}',
121-
16: '0px 6px 30px 5px #{$shadow-color}',
122-
17: '0px 6px 32px 5px #{$shadow-color}',
123-
18: '0px 7px 34px 6px #{$shadow-color}',
124-
19: '0px 7px 36px 6px #{$shadow-color}',
125-
20: '0px 8px 38px 7px #{$shadow-color}',
126-
21: '0px 8px 40px 7px #{$shadow-color}',
127-
22: '0px 8px 42px 7px #{$shadow-color}',
128-
23: '0px 9px 44px 8px #{$shadow-color}',
129-
24: '0px 9px 46px 8px #{$shadow-color}'
130-
);
131-
}
132-
13325
// The default duration value for elevation transitions.
13426
$transition-duration: 280ms !default;
13527

@@ -139,35 +31,35 @@ $transition-timing-function: variables.$fast-out-slow-in-timing-function;
13931
// The default color for elevation shadows.
14032
$color: black !default;
14133

142-
// The default opacity scaling value for elevation shadows.
143-
$opacity: 1 !default;
144-
14534
// Prefix for elevation-related selectors.
14635
$prefix: 'mat-elevation-z';
14736

14837
// Applies the correct css rules to an element to give it the elevation specified by $zValue.
14938
// The $zValue must be between 0 and 24.
150-
@mixin elevation($zValue, $color: $color, $opacity: $opacity) {
151-
@if meta.type-of($zValue) != number or not math.is-unitless($zValue) {
152-
@error '$zValue must be a unitless number';
39+
@mixin elevation($zValue, $color: $color) {
40+
@if meta.type-of($color) == color {
41+
@include mdc-elevation.elevation($zValue, $color);
15342
}
154-
@if $zValue < 0 or $zValue > 24 {
155-
@error '$zValue must be between 0 and 24';
43+
@else {
44+
// Copied from @material/elevation/_elevation-theme.scss#_box-shadow
45+
// TODO(mmalerba): Add support for graceful handling of CSS var color to MDC.
46+
$umbra-z-value: map.get(mdc-elevation.$umbra-map, $zValue);
47+
$penumbra-z-value: map.get(mdc-elevation.$penumbra-map, $zValue);
48+
$ambient-z-value: map.get(mdc-elevation.$ambient-map, $zValue);
49+
$box-shadow: (
50+
#{'#{$umbra-z-value} #{$color}'},
51+
#{'#{$penumbra-z-value} #{$color}'},
52+
#{$ambient-z-value} $color
53+
);
54+
@include mdc-elevation.shadow($box-shadow);
15655
}
157-
158-
box-shadow: #{map.get(_get-umbra-map($color, $opacity), $zValue)},
159-
#{map.get(_get-penumbra-map($color, $opacity), $zValue)},
160-
#{map.get(_get-ambient-map($color, $opacity), $zValue)};
16156
}
16257

16358
// Applies the elevation to an element in a manner that allows
16459
// consumers to override it via the Material elevation classes.
165-
@mixin overridable-elevation(
166-
$zValue,
167-
$color: $color,
168-
$opacity: $opacity) {
60+
@mixin overridable-elevation($zValue, $color: $color) {
16961
&:not([class*='#{$prefix}']) {
170-
@include elevation($zValue, $color, $opacity);
62+
@include elevation($zValue, $color);
17163
}
17264
}
17365

src/material/core/style/_private.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
@use 'sass:map';
22
@use './elevation';
33

4-
@mixin private-theme-elevation($zValue, $config, $opacity: elevation.$opacity) {
4+
@mixin private-theme-elevation($zValue, $config) {
55
$foreground: map.get($config, foreground);
66
$elevation-color: map.get($foreground, elevation);
77
$elevation-color-or-default: if($elevation-color == null, elevation.$color, $elevation-color);
88

9-
@include elevation.elevation($zValue, $elevation-color-or-default, $opacity);
9+
@include elevation.elevation($zValue, $elevation-color-or-default);
1010
}
1111

12-
@mixin private-theme-overridable-elevation($zValue, $config, $opacity: elevation.$opacity) {
12+
@mixin private-theme-overridable-elevation($zValue, $config) {
1313
$foreground: map.get($config, foreground);
1414
$elevation-color: map.get($foreground, elevation);
1515
$elevation-color-or-default: if($elevation-color == null, elevation.$color, $elevation-color);
1616

17-
@include elevation.overridable-elevation($zValue, $elevation-color-or-default, $opacity);
17+
@include elevation.overridable-elevation($zValue, $elevation-color-or-default);
1818
}
1919

2020
// If the mat-animation-noop class is present on the components root element,

src/material/legacy-core/_core-theme.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
@use './option/option-theme';
66
@use './option/optgroup-theme';
77

8-
98
@mixin color($config-or-theme) {
109
$config: theming.get-color-config($config-or-theme);
1110
@include core-theme.color($config-or-theme);

0 commit comments

Comments
 (0)