Skip to content

Commit

Permalink
chore(elevation): move private custom properties off of host
Browse files Browse the repository at this point in the history
Elevation doesn't have variant styles, but it still uses shorter private custom properties to reduce its CSS size. I added a comment explaining why and moved the custom properties into the inner shadow dom so they can't be set on the host.

No size changes.

PiperOrigin-RevId: 601128500
  • Loading branch information
asyncLiz authored and copybara-github committed Jan 24, 2024
1 parent 044ee51 commit 901a5cb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions elevation/internal/_elevation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@

@mixin styles() {
$tokens: tokens.md-comp-elevation-values();
@each $token, $value in $tokens {
$tokens: map.set($tokens, $token, var(--md-elevation-#{$token}, #{$value}));
}

:host {
@each $token, $value in $tokens {
--_#{$token}: var(--md-elevation-#{$token}, #{$value});
}

display: flex;
pointer-events: none;
}
Expand All @@ -53,6 +52,13 @@
.shadow::after {
content: '';
transition-property: box-shadow, opacity;

// Elevation doesn't share styles with multiple variants, so we normally
// would not use private custom properties. However, these variables are
// repeated several times in the styles below, and a shorter custom property
// reduces the CSS size, minified and gzip.
--_level: #{map.get($tokens, 'level')};
--_shadow-color: #{map.get($tokens, 'shadow-color')};
}

// Key box shadow
Expand Down

0 comments on commit 901a5cb

Please sign in to comment.