Skip to content

feat(material-experimental/mdc-core): set up MDC-based elevation #22397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/material-experimental/_index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Structural
@forward './mdc-helpers/focus-indicators' as mdc-* show mdc-strong-focus-indicators;
@forward './mdc-core/elevation' show elevation, overridable-elevation;

// Theme bundles
@forward './mdc-theming/all-theme' show all-mdc-component-themes;
Expand Down
15 changes: 15 additions & 0 deletions src/material-experimental/mdc-core/_core-theme.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
@use '../../material/core/theming/theming';
@use './option/option-theme';
@use './option/optgroup-theme';
@use './elevation';

// Mixin that renders all of the core styles that depend on the theme.
@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);

// Wrap the sub-theme includes in the duplicate theme styles mixin. This ensures that
// there won't be multiple warnings. e.g. if `mat-mdc-core-theme` reports a warning, then
// the imported themes (such as `mat-ripple-theme`) should not report again.
@include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-core') {
$color: theming.get-color-config($theme);

@include option-theme.theme($theme);
@include optgroup-theme.theme($theme);

@if $color != null {
// Provides external CSS classes for each elevation value. Each CSS class is formatted as
// `mat-mdc-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the
// element is elevated.
@for $zValue from 0 through 24 {
.#{elevation.$prefix}#{$zValue} {
@include elevation.private-theme-elevation($zValue, $color);
}
}
}
}
}
39 changes: 39 additions & 0 deletions src/material-experimental/mdc-core/_elevation.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@use 'sass:map';
@use '@material/elevation/elevation-theme' as mdc-elevation;

// Prefix for elevation-related selectors.
$prefix: 'mat-mdc-elevation-z';

// The default color for elevation shadows.
$color: black !default;

// Applies the correct css rules to an element to give it the elevation specified by $zValue.
// The $zValue must be between 0 and 24.
@mixin elevation($zValue, $color: $color) {
@include mdc-elevation.elevation($zValue, $color);
}

// Applies the elevation to an element in a manner that allows
// consumers to override it via the Material elevation classes.
@mixin overridable-elevation($zValue, $color: $color) {
&:not([class*='#{$prefix}']) {
@include elevation($zValue, $color);
}
}

@mixin private-theme-elevation($zValue, $config) {
@debug $config;
$foreground: map.get($config, foreground);
$elevation-color: map.get($foreground, elevation);
$elevation-color-or-default: if($elevation-color == null, $color, $elevation-color);

@include elevation($zValue, $elevation-color-or-default);
}

@mixin private-theme-overridable-elevation($zValue, $config) {
$foreground: map.get($config, foreground);
$elevation-color: map.get($foreground, elevation);
$elevation-color-or-default: if($elevation-color == null, $color, $elevation-color);

@include overridable-elevation($zValue, $elevation-color-or-default);
}