|
| 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); |
0 commit comments