Skip to content

Commit

Permalink
chore(elevation)!: remove surface for tonal surface update
Browse files Browse the repository at this point in the history
Changes:
- Elevation is now `inset:0;position:absolute;` by default
- Separated surface styles into a temporary `<md-elevation-surface>` element (this will be removed after tonal surface update)
PiperOrigin-RevId: 521934300
  • Loading branch information
asyncLiz authored and copybara-github committed Apr 5, 2023
1 parent 988ad97 commit d12ed3e
Show file tree
Hide file tree
Showing 28 changed files with 187 additions and 144 deletions.
5 changes: 0 additions & 5 deletions button/lib/_elevation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
// go/keep-sorted end

@mixin styles() {
md-elevation {
inset: 0;
position: absolute;
}

.md3-button {
@include elevation.theme(
(
Expand Down
1 change: 1 addition & 0 deletions button/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
.md3-button::after,
.md3-button::before,
md-elevation,
md-elevation-surface,
.md3-button__ripple {
z-index: -1; // Place behind content
}
Expand Down
4 changes: 2 additions & 2 deletions button/lib/elevated-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import '../../elevation/elevation.js';
import '../../elevation/elevation-surface.js';

import {html, TemplateResult} from 'lit';
import {ClassInfo} from 'lit/directives/class-map.js';
Expand All @@ -23,6 +23,6 @@ export class ElevatedButton extends Button {
}

protected override renderElevation(): TemplateResult {
return html`<md-elevation shadow surface></md-elevation>`;
return html`<md-elevation-surface shadow></md-elevation-surface>`;
}
}
4 changes: 2 additions & 2 deletions button/lib/filled-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import '../../elevation/elevation.js';
import '../../elevation/elevation-surface.js';

import {html, TemplateResult} from 'lit';
import {ClassInfo} from 'lit/directives/class-map.js';
Expand All @@ -23,6 +23,6 @@ export class FilledButton extends Button {
}

protected override renderElevation(): TemplateResult {
return html`<md-elevation shadow surface></md-elevation>`;
return html`<md-elevation-surface shadow></md-elevation-surface>`;
}
}
2 changes: 1 addition & 1 deletion button/lib/tonal-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export class TonalButton extends Button {
}

protected override renderElevation(): TemplateResult {
return html`<md-elevation shadow></md-elevation>`;
return html`<md-elevation></md-elevation>`;
}
}
5 changes: 0 additions & 5 deletions chips/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@
opacity: var(--_elevated-disabled-container-opacity);
}

md-elevation {
inset: 0;
position: absolute;
}

md-focus-ring {
@include focus-ring.theme(
(
Expand Down
4 changes: 2 additions & 2 deletions chips/lib/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import '../../elevation/elevation.js';
import '../../elevation/elevation-surface.js';
import '../../focus/focus-ring.js';
import '../../ripple/ripple.js';

Expand Down Expand Up @@ -49,7 +49,7 @@ export class Chip extends LitElement {
@focus=${this.handleFocus}
@pointerdown=${this.handlePointerDown}
${ripple(this.getRipple)}>
<md-elevation shadow=${this.elevated} surface></md-elevation>
<md-elevation-surface shadow=${this.elevated}></md-elevation-surface>
${when(this.showRipple, this.renderRipple)}
<md-focus-ring .visible=${this.showFocusRing}></md-focus-ring>
<span class="icon leading">
Expand Down
6 changes: 1 addition & 5 deletions dialog/lib/_dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@
padding-block-end: var(--_container-block-padding);
}

md-elevation {
position: absolute;
inset: 0;
border-radius: inherit;

md-elevation-surface {
@include elevation.theme(
(
level: var(--_container-elevation),
Expand Down
4 changes: 2 additions & 2 deletions dialog/lib/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import '../../elevation/elevation.js';
import '../../elevation/elevation-surface.js';

import {html, LitElement, PropertyValues} from 'lit';
import {property, query, state} from 'lit/decorators.js';
Expand Down Expand Up @@ -275,7 +275,7 @@ export class Dialog extends LitElement {
@pointermove=${this.handlePointerMove}
@pointerup=${this.handleDragEnd}
>
<md-elevation surface></md-elevation>
<md-elevation-surface></md-elevation-surface>
<header class="header">
<slot name="header">
<slot name="headline-prefix"></slot>
Expand Down
26 changes: 26 additions & 0 deletions elevation/elevation-surface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {customElement} from 'lit/decorators.js';

import {styles} from './lib/elevation-styles.css.js';
import {ElevationSurface} from './lib/elevation-surface.js';
import {styles as surfaceStyles} from './lib/surface-styles.css.js';

declare global {
interface HTMLElementTagNameMap {
'md-elevation-surface': MdElevationSurface;
}
}

/**
* @deprecated An elevation component with a surface-tint. Will be removed
* once components are updated.
*/
@customElement('md-elevation-surface')
export class MdElevationSurface extends ElevationSurface {
static override styles = [styles, surfaceStyles];
}
70 changes: 22 additions & 48 deletions elevation/lib/_elevation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,54 @@
// go/keep-sorted start
@use '../../sass/theme';
@use '../../sass/var';
@use './md-comp-elevation';
@use '../../tokens';
// go/keep-sorted end

@mixin theme($tokens) {
$tokens: theme.validate-theme(md-comp-elevation.values(), $tokens);
$tokens: theme.validate-theme(
map.merge(
tokens.md-comp-elevation-values(),
(
// TODO(b/272526637): remove after surface is removed
'surface-tint': null
)
),
$tokens
);
$tokens: theme.create-theme-vars($tokens, 'elevation');
@include theme.emit-theme-vars($tokens);
}

@mixin styles() {
$tokens: md-comp-elevation.values();
$tokens: tokens.md-comp-elevation-values();
$tokens: theme.create-theme-vars($tokens, 'elevation');

:host {
@each $token, $value in $tokens {
--_#{$token}: #{$value};
}

border-radius: inherit;
display: flex;
pointer-events: none;
position: relative;
}

:host(:not([surface])) .surface,
:host(:not([shadow])) .shadow {
display: none;
transition-duration: var(--_duration);
transition-timing-function: var(--_easing);
}

.surface,
:host,
.shadow,
.shadow::before,
.shadow::after {
border-radius: inherit;
content: '';
inset: 0;
position: absolute;
}

.shadow::before,
.shadow::after {
content: '';
transition-duration: inherit;
transition-property: box-shadow, opacity;
transition-duration: var(--_duration);
transition-timing-function: var(--_easing);
transition-timing-function: inherit;
}

// Key box shadows
Expand Down Expand Up @@ -165,38 +173,4 @@
opacity: 0.15;
box-shadow: 0px $y $blur $spread var(--_shadow-color);
}

.surface {
// Surface tint opacities:
// level0: opacity: 0;
// level1: opacity: 0.05;
// level2: opacity: 0.08;
// level3: opacity: 0.11;
// level4: opacity: 0.12;
// level5: opacity: 0.14;

// Add a clamped value for each level to build the correct values.
// Sass will simplify nested calc()s.

// 0 + 0 = 0
// $level0-opacity: 0; // +0 is a no-op
// 0 + 0.05 = 0.05
$level1-opacity: clamp(0, var(--_level), 0.05);
// 0.05 + 0.03 = 0.08
$level2-opacity: clamp(0, var(--_level) - 1, 0.03);
// 0.08 + 0.03 = 0.11
$level3-opacity: clamp(0, var(--_level) - 2, 0.03);
// (can't simplify levels 2-3 since the value is < 1)
// 0.11 + 0.01 = 0.12
$level4-opacity: clamp(0, var(--_level) - 3, 0.01);
// 0.12 + 0.02 = 0.14
$level5-opacity: clamp(0, var(--_level) - 4, 0.02);
$opacity: calc(
$level1-opacity + $level2-opacity + $level3-opacity + $level4-opacity +
$level5-opacity
);

background: var(--_surface-tint);
opacity: $opacity;
}
}
27 changes: 0 additions & 27 deletions elevation/lib/_md-comp-elevation.scss

This file was deleted.

47 changes: 47 additions & 0 deletions elevation/lib/_surface.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

/// @deprecated Remove once components are updated for tonal surfaces
@mixin styles() {
.surface {
// Surface tint opacities:
// level0: opacity: 0;
// level1: opacity: 0.05;
// level2: opacity: 0.08;
// level3: opacity: 0.11;
// level4: opacity: 0.12;
// level5: opacity: 0.14;

// Add a clamped value for each level to build the correct values.
// Sass will simplify nested calc()s.

// 0 + 0 = 0
// $level0-opacity: 0; // +0 is a no-op
// 0 + 0.05 = 0.05
$level1-opacity: clamp(0, var(--_level), 0.05);
// 0.05 + 0.03 = 0.08
$level2-opacity: clamp(0, var(--_level) - 1, 0.03);
// 0.08 + 0.03 = 0.11
$level3-opacity: clamp(0, var(--_level) - 2, 0.03);
// (can't simplify levels 2-3 since the value is < 1)
// 0.11 + 0.01 = 0.12
$level4-opacity: clamp(0, var(--_level) - 3, 0.01);
// 0.12 + 0.02 = 0.14
$level5-opacity: clamp(0, var(--_level) - 4, 0.02);
$opacity: calc(
$level1-opacity + $level2-opacity + $level3-opacity + $level4-opacity +
$level5-opacity
);

background: var(
--md-elevation-surface-tint,
var(--md-sys-color-surface-tint, #6750a4)
);
border-radius: inherit;
inset: 0;
opacity: $opacity;
position: absolute;
}
}
28 changes: 28 additions & 0 deletions elevation/lib/elevation-surface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {html, nothing} from 'lit';
import {property} from 'lit/decorators.js';

import {Elevation} from './elevation.js';

/**
* @deprecated An elevation component with a surface-tint. Will be removed
* once components are updated.
*/
export class ElevationSurface extends Elevation {
/**
* Whether or not the elevation level should display a shadow.
*/
@property({type: Boolean}) shadow = false;

override render() {
return html`
<span class="surface"></span>
${this.shadow ? super.render() : nothing}
`;
}
}
15 changes: 1 addition & 14 deletions elevation/lib/elevation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,12 @@
*/

import {html, LitElement} from 'lit';
import {property} from 'lit/decorators.js';

/**
* A component for elevation.
*/
export class Elevation extends LitElement {
/**
* Whether or not the elevation level should display a shadow.
*/
@property({type: Boolean, reflect: true}) shadow = false;
/**
* Whether or not the elevation level should display a surface tint color.
*/
@property({type: Boolean, reflect: true}) surface = false;

override render() {
return html`
<span class="surface"></span>
<span class="shadow"></span>
`;
return html`<span class="shadow"></span>`;
}
}
Loading

0 comments on commit d12ed3e

Please sign in to comment.