Skip to content

Commit 6408731

Browse files
authored
feat(material-experimental/mdc-core): set up MDC-based elevation (#22397)
Sets up elevation utilities based on top of MDC, similar to the ones we currently have.
1 parent 2f177b6 commit 6408731

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/material-experimental/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Structural
22
@forward './mdc-helpers/focus-indicators' as mdc-* show mdc-strong-focus-indicators;
3+
@forward './mdc-core/elevation' show elevation, overridable-elevation;
34

45
// Theme bundles
56
@forward './mdc-theming/all-theme' show all-mdc-component-themes;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
@use '../../material/core/theming/theming';
22
@use './option/option-theme';
33
@use './option/optgroup-theme';
4+
@use './elevation';
45

56
// Mixin that renders all of the core styles that depend on the theme.
67
@mixin theme($theme-or-color-config) {
78
$theme: theming.private-legacy-get-theme($theme-or-color-config);
9+
810
// Wrap the sub-theme includes in the duplicate theme styles mixin. This ensures that
911
// there won't be multiple warnings. e.g. if `mat-mdc-core-theme` reports a warning, then
1012
// the imported themes (such as `mat-ripple-theme`) should not report again.
1113
@include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-core') {
14+
$color: theming.get-color-config($theme);
15+
1216
@include option-theme.theme($theme);
1317
@include optgroup-theme.theme($theme);
18+
19+
@if $color != null {
20+
// Provides external CSS classes for each elevation value. Each CSS class is formatted as
21+
// `mat-mdc-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the
22+
// element is elevated.
23+
@for $zValue from 0 through 24 {
24+
.#{elevation.$prefix}#{$zValue} {
25+
@include elevation.private-theme-elevation($zValue, $color);
26+
}
27+
}
28+
}
1429
}
1530
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@use 'sass:map';
2+
@use '@material/elevation/elevation-theme' as mdc-elevation;
3+
4+
// Prefix for elevation-related selectors.
5+
$prefix: 'mat-mdc-elevation-z';
6+
7+
// The default color for elevation shadows.
8+
$color: black !default;
9+
10+
// Applies the correct css rules to an element to give it the elevation specified by $zValue.
11+
// The $zValue must be between 0 and 24.
12+
@mixin elevation($zValue, $color: $color) {
13+
@include mdc-elevation.elevation($zValue, $color);
14+
}
15+
16+
// Applies the elevation to an element in a manner that allows
17+
// consumers to override it via the Material elevation classes.
18+
@mixin overridable-elevation($zValue, $color: $color) {
19+
&:not([class*='#{$prefix}']) {
20+
@include elevation($zValue, $color);
21+
}
22+
}
23+
24+
@mixin private-theme-elevation($zValue, $config) {
25+
@debug $config;
26+
$foreground: map.get($config, foreground);
27+
$elevation-color: map.get($foreground, elevation);
28+
$elevation-color-or-default: if($elevation-color == null, $color, $elevation-color);
29+
30+
@include elevation($zValue, $elevation-color-or-default);
31+
}
32+
33+
@mixin private-theme-overridable-elevation($zValue, $config) {
34+
$foreground: map.get($config, foreground);
35+
$elevation-color: map.get($foreground, elevation);
36+
$elevation-color-or-default: if($elevation-color == null, $color, $elevation-color);
37+
38+
@include overridable-elevation($zValue, $elevation-color-or-default);
39+
}

0 commit comments

Comments
 (0)