Skip to content

Commit a4846a9

Browse files
committed
fix(material/core): implement elevation classes in M3
Fixes that we didn't support elevation classes in M3 which was breaking some users. Fixes #28618.
1 parent 00022d9 commit a4846a9

File tree

7 files changed

+44
-24
lines changed

7 files changed

+44
-24
lines changed

src/material/core/_core-theme.scss

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
@use './theming/theming';
22
@use './theming/inspection';
33
@use './theming/validation';
4-
@use './style/private';
54
@use './ripple/ripple-theme';
65
@use './option/option-theme';
76
@use './option/optgroup-theme';
87
@use './selection/pseudo-checkbox/pseudo-checkbox-theme';
9-
@use './style/elevation';
108
@use './style/sass-utils';
119
@use './typography/typography';
1210
@use './tokens/token-utils';
@@ -41,6 +39,10 @@ $_has-inserted-loaded-marker: false;
4139
@include option-theme.base($theme);
4240
@include optgroup-theme.base($theme);
4341
@include pseudo-checkbox-theme.base($theme);
42+
@include sass-utils.current-selector-or-root() {
43+
@include token-utils.create-token-values(tokens-mat-app.$prefix,
44+
tokens-mat-app.get-unthemable-tokens());
45+
}
4446
}
4547

4648
// The marker is a concrete style no matter which Material version we're targeting.
@@ -60,18 +62,6 @@ $_has-inserted-loaded-marker: false;
6062
@include token-utils.create-token-values(tokens-mat-app.$prefix,
6163
tokens-mat-app.get-color-tokens($theme));
6264
}
63-
64-
// Provides external CSS classes for each elevation value. Each CSS class is formatted as
65-
// `mat-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the element is
66-
// elevated.
67-
@for $zValue from 0 through 24 {
68-
$selector: elevation.$prefix + $zValue;
69-
// We need the `mat-mdc-elevation-specific`, because some MDC mixins
70-
// come with elevation baked in and we don't have a way of removing it.
71-
.#{$selector}, .mat-mdc-elevation-specific.#{$selector} {
72-
@include private.private-theme-elevation($zValue, $theme);
73-
}
74-
}
7565
}
7666
}
7767

src/material/core/_core.scss

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use './tokens/m2/mat/app' as tokens-mat-app;
33
@use './tokens/token-utils';
44
@use './ripple/ripple';
5+
@use './style/elevation';
56
@use './focus-indicators/private';
67
@use './mdc-helpers/mdc-helpers';
78

@@ -18,13 +19,26 @@
1819
// Wrapper element that provides the theme background when the
1920
// user's content isn't inside of a `mat-sidenav-container`.
2021
@at-root {
21-
.mat-app-background {
22-
@include mdc-helpers.disable-mdc-fallback-declarations {
23-
@include token-utils.use-tokens(tokens-mat-app.$prefix, tokens-mat-app.get-token-slots()) {
24-
// Note: we need to emit fallback values here to avoid errors in internal builds.
22+
// Note: we need to emit fallback values here to avoid errors in internal builds.
23+
@include mdc-helpers.disable-mdc-fallback-declarations {
24+
@include token-utils.use-tokens(tokens-mat-app.$prefix, tokens-mat-app.get-token-slots()) {
25+
.mat-app-background {
2526
@include token-utils.create-token-slot(background-color, background-color, transparent);
2627
@include token-utils.create-token-slot(color, text-color, inherit);
2728
}
29+
30+
// Provides external CSS classes for each elevation value. Each CSS class is formatted as
31+
// `mat-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the element
32+
// is elevated.
33+
@for $zValue from 0 through 24 {
34+
$selector: elevation.$prefix + $zValue;
35+
// We need the `mat-mdc-elevation-specific`, because some MDC mixins
36+
// come with elevation baked in and we don't have a way of removing it.
37+
.#{$selector}, .mat-mdc-elevation-specific.#{$selector} {
38+
@include token-utils.create-token-slot(box-shadow, 'elevation-shadow-level-#{$zValue}',
39+
none);
40+
}
41+
}
2842
}
2943
}
3044
}

src/material/core/tokens/m2/mat/_app.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '@material/elevation/elevation-theme' as mdc-elevation;
2+
@use 'sass:map';
13
@use '../../token-utils';
24
@use '../../../theming/inspection';
35
@use '../../../style/sass-utils';
@@ -13,10 +15,19 @@ $prefix: (mat, app);
1315

1416
// Tokens that can be configured through Angular Material's color theming API.
1517
@function get-color-tokens($theme) {
16-
@return (
18+
$tokens: (
1719
background-color: inspection.get-theme-color($theme, background, background),
1820
text-color: inspection.get-theme-color($theme, foreground, text),
1921
);
22+
23+
@for $zValue from 0 through 24 {
24+
$elevation-color: inspection.get-theme-color($theme, foreground, elevation);
25+
$shadow: mdc-elevation.elevation-box-shadow($zValue,
26+
if($elevation-color == null, elevation.$color, $elevation-color));
27+
$tokens: map.set($tokens, 'elevation-shadow-level-#{$zValue}', $shadow);
28+
}
29+
30+
@return $tokens;
2031
}
2132

2233
// Tokens that can be configured through Angular Material's typography theming API.

src/material/core/tokens/m3/mat/_app.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use 'sass:map';
2+
@use '@material/elevation' as mdc-elevation;
23
@use '../../token-utils';
34

45
// The prefix used to generate the fully qualified name for tokens in this file.
@@ -10,10 +11,18 @@ $prefix: (mat, app);
1011
/// @param {Map} $token-slots Possible token slots
1112
/// @return {Map} A set of custom tokens for the app
1213
@function get-tokens($systems, $exclude-hardcoded, $token-slots) {
14+
$shadow-color: map.get($systems, md-sys-color, shadow);
1315
$tokens: (
1416
background-color: map.get($systems, md-sys-color, background),
1517
text-color: map.get($systems, md-sys-color, on-background),
1618
);
1719

20+
@if ($shadow-color) {
21+
@for $zValue from 0 through 24 {
22+
$shadow: mdc-elevation.elevation-box-shadow($zValue, $shadow-color);
23+
$tokens: map.set($tokens, 'elevation-shadow-level-#{$zValue}', $shadow);
24+
}
25+
}
26+
1827
@return token-utils.namespace-tokens($prefix, $tokens, $token-slots);
1928
}

src/material/schematics/ng-generate/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="mat-elevation-z8">
1+
<div class="mat-elevation-z2">
22
<table mat-table class="full-width-table" matSort aria-label="Elements">
33
<!-- Id Column -->
44
<ng-container matColumnDef="id">

src/material/tabs/tab-header.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!-- TODO: this also had `mat-elevation-z4`. Figure out what we should do with it. -->
21
<button class="mat-mdc-tab-header-pagination mat-mdc-tab-header-pagination-before"
32
#previousPaginator
43
aria-hidden="true"
@@ -30,7 +29,6 @@
3029
</div>
3130
</div>
3231

33-
<!-- TODO: this also had `mat-elevation-z4`. Figure out what we should do with it. -->
3432
<button class="mat-mdc-tab-header-pagination mat-mdc-tab-header-pagination-after"
3533
#nextPaginator
3634
aria-hidden="true"

src/material/tabs/tab-nav-bar/tab-nav-bar.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!-- TODO: this also had `mat-elevation-z4`. Figure out what we should do with it. -->
21
<button class="mat-mdc-tab-header-pagination mat-mdc-tab-header-pagination-before"
32
#previousPaginator
43
aria-hidden="true"
@@ -22,7 +21,6 @@
2221
</div>
2322
</div>
2423

25-
<!-- TODO: this also had `mat-elevation-z4`. Figure out what we should do with it. -->
2624
<button class="mat-mdc-tab-header-pagination mat-mdc-tab-header-pagination-after"
2725
#nextPaginator
2826
aria-hidden="true"

0 commit comments

Comments
 (0)