Skip to content

Commit 3f99af4

Browse files
Merge pull request #1834 from material-components:elevation-overlay
PiperOrigin-RevId: 333620911
2 parents 7a55533 + b6980dc commit 3f99af4

File tree

17 files changed

+563
-9
lines changed

17 files changed

+563
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
- `button`
1212
- Sass theming mixins added
13-
- `menu`
14-
- `--mdc-menu-max-height` to set max height on menu
15-
- `fab`
16-
- `reducedTouchTarget` reduces the touch target on mini fab
1713
- `base-element`
1814
- BaseElement.click() forwards focus to BaseElement.mdcRoot
15+
- `elevation-overlay`
16+
- implemented elevation overlay styles
17+
- `fab`
18+
- `reducedTouchTarget` reduces the touch target on mini fab
1919
- `form-element`
2020
- FormElement.click() forwards focus to FormElement.formElement
21-
- `tab`
22-
- export for `TabInteractionEventDetail`
2321
- `list`
2422
- export for `ActionDetail`
2523
- export for `SelectedDetail`
24+
- `menu`
25+
- `--mdc-menu-max-height` to set max height on menu
26+
- `tab`
27+
- export for `TabInteractionEventDetail`
2628

2729
### Changed
2830

demos/elevation-overlay/index.html

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright 2020 Google Inc. All Rights Reserved.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<html lang="en">
19+
<head>
20+
<title>MWC Dialog Demo</title>
21+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
22+
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
23+
<link rel="preload" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" as="style" type="text/css">
24+
<link rel="preload" href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" as="style" type="text/css">
25+
<script type="module" src="index.js"></script>
26+
<script nomodule src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
27+
<style>
28+
.unresolved main {
29+
opacity: 0;
30+
}
31+
</style>
32+
<link href="../shared/shared.css" rel="stylesheet">
33+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
34+
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet">
35+
<style>
36+
body {
37+
min-height: calc(100vh - 4em);
38+
}
39+
</style>
40+
</head>
41+
<body class="unresolved">
42+
<demo-header component="Elevation Overlay" package="elevation-overlay"></demo-header>
43+
44+
<main>
45+
<my-element></my-element>
46+
<script nomodule src="index.es5.js"></script>
47+
</main>
48+
</body>
49+
</html>

demos/elevation-overlay/index.js

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/**
2+
@license
3+
Copyright 2020 Google Inc. All Rights Reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
import {style as elevationStyle} from '@material/mwc-elevation-overlay/mwc-elevation-overlay-css';
18+
import {LitElement, css, html} from 'lit-element';
19+
import {styleMap} from 'lit-html/directives/style-map';
20+
21+
import '../shared/demo-header';
22+
23+
addEventListener('load', function() {
24+
document.body.classList.remove('unresolved');
25+
});
26+
27+
class MyElement extends LitElement {
28+
static get styles() {
29+
return [
30+
elevationStyle,
31+
css`
32+
:host([elevation='0']) .overlay-wrapper {
33+
--mdc-elevation-overlay-opacity: 0;
34+
}
35+
:host([elevation='1']) .overlay-wrapper {
36+
--mdc-elevation-overlay-opacity: 5%;
37+
}
38+
:host([elevation='2']) .overlay-wrapper {
39+
--mdc-elevation-overlay-opacity: 7%;
40+
}
41+
:host([elevation='3']) .overlay-wrapper {
42+
--mdc-elevation-overlay-opacity: 8%;
43+
}
44+
:host([elevation='4']) .overlay-wrapper {
45+
--mdc-elevation-overlay-opacity: 9%;
46+
}
47+
:host([elevation='6']) .overlay-wrapper {
48+
--mdc-elevation-overlay-opacity: 11%;
49+
}
50+
:host([elevation='8']) .overlay-wrapper {
51+
--mdc-elevation-overlay-opacity: 12%;
52+
}
53+
:host([elevation='12']) .overlay-wrapper {
54+
--mdc-elevation-overlay-opacity: 14%;
55+
}
56+
:host([elevation='16']) .overlay-wrapper {
57+
--mdc-elevation-overlay-opacity: 15%;
58+
}
59+
:host([elevation='24']) .overlay-wrapper {
60+
--mdc-elevation-overlay-opacity: 16%;
61+
}
62+
63+
:host {
64+
background-color: #212121;
65+
display: inline-flex;
66+
padding: 8px;
67+
min-width: 200px;
68+
min-height: 200px;
69+
align-items: center;
70+
justify-content: center;
71+
color: #eeeeee;
72+
flex-direction: column;
73+
box-sizing: border-box;
74+
}
75+
76+
.controls {
77+
margin-top: 8px;
78+
}
79+
80+
.overlay-wrapper{
81+
width: 150px;
82+
height: 150px;
83+
position: relative;
84+
border-radius: 8px;
85+
padding: 8px;
86+
box-sizing: border-box;
87+
border: 1px solid rgba(255, 255, 255, .24);
88+
}
89+
`,
90+
];
91+
}
92+
93+
static get properties() {
94+
return {
95+
elevation: {
96+
type: Number,
97+
reflect: true,
98+
},
99+
color: {
100+
type: String,
101+
},
102+
width: {
103+
type: String,
104+
},
105+
height: {
106+
type: String,
107+
},
108+
};
109+
}
110+
111+
constructor() {
112+
super();
113+
this.elevation = 0;
114+
this.color = '#FFFFFF';
115+
this.width = '100%';
116+
this.height = '100%';
117+
}
118+
119+
render() {
120+
const styles = {
121+
'--mdc-elevation-overlay-fill-color': this.color ?? '',
122+
'--mdc-elevation-overlay-width': this.width,
123+
'--mdc-elevation-overlay-height': this.height,
124+
};
125+
return html`
126+
<div class="overlay-wrapper" style=${styleMap(styles)}>
127+
This surface is in dark mode at elevation ${this.elevation}.
128+
<div class="mdc-elevation-overlay"></div>
129+
</div>
130+
<div class="controls">
131+
<div>
132+
<span>elevation:</span>
133+
<select @change=${this.onChange}>
134+
<option value="0" selected>0</option>
135+
<option value="1">1</option>
136+
<option value="2">2</option>
137+
<option value="3">3</option>
138+
<option value="4">4</option>
139+
<option value="6">6</option>
140+
<option value="8">8</option>
141+
<option value="12">12</option>
142+
<option value="16">16</option>
143+
<option value="24">24</option>
144+
</select>
145+
</div>
146+
<div>
147+
<span>color:</span>
148+
<input @input=${this.onColorInput} value=${this.color} type="color">
149+
</div>
150+
<div>
151+
<span>width:</span>
152+
<input @input=${this.onWidthInput} value=${this.width}>
153+
</div>
154+
<div>
155+
<span>height:</span>
156+
<input @input=${this.onHeightInput} value=${this.height}>
157+
</div>
158+
</div>
159+
`;
160+
}
161+
162+
onChange(e) {
163+
const elevationSelect = e.target;
164+
const value = Number(elevationSelect.value);
165+
this.elevation = Number(value);
166+
}
167+
168+
onColorInput(e) {
169+
const input = e.target;
170+
this.color = input.value;
171+
}
172+
173+
onWidthInput(e) {
174+
const input = e.target;
175+
this.width = input.value;
176+
}
177+
178+
onHeightInput(e) {
179+
const input = e.target;
180+
this.height = input.value;
181+
}
182+
}
183+
184+
customElements.define('my-element', MyElement);

demos/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ class DemoView extends LitElement {
9494
};
9595

9696
this.listItems = [
97+
{
98+
name: 'Elevation Overlay',
99+
secondary: 'Element overlays for dark mode elevation and emphasis',
100+
href: 'elevation-overlay/',
101+
img: 'https://fonts.gstatic.com/s/i/materialicons/flip_to_front/v6/24px.svg',
102+
},
97103
{
98104
name: 'Button',
99105
secondary: 'Raised and flat buttons',
@@ -164,13 +170,13 @@ class DemoView extends LitElement {
164170
name: 'List',
165171
secondary: 'Continuous, vertical indexes of text or images.',
166172
href: 'list/',
167-
img: 'https://material.io/develop/images/component_icons/list.svg',
173+
img: 'https://fonts.gstatic.com/s/i/materialicons/view_list/v6/24px.svg',
168174
},
169175
{
170176
name: 'Menu',
171177
secondary: 'Displays a list of choices on a temporary surface.',
172178
href: 'menu/',
173-
img: 'https://material.io/develop/images/component_icons/menu.svg',
179+
img: 'https://fonts.gstatic.com/s/i/materialicons/picture_in_picture/v6/24px.svg',
174180
},
175181
{
176182
name: 'Radio buttons',
@@ -188,7 +194,7 @@ class DemoView extends LitElement {
188194
name: 'Select',
189195
secondary: 'Single option dropdown select menus',
190196
href: 'select/',
191-
img: 'https://material.io/develop/images/component_icons/menu.svg',
197+
img: 'https://fonts.gstatic.com/s/i/materialicons/list_alt/v6/24px.svg',
192198
},
193199
{
194200
name: 'Slider',

demos/shared/demo-header.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DemoHeader extends LitElement {
3535
}
3636
.white {
3737
--mdc-theme-primary: white;
38+
--mdc-button-outline-color: white;
3839
color: white;
3940
}`,
4041
];

0 commit comments

Comments
 (0)