avm99963 | 874d3f6 | 2022-06-04 00:32:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Written by the Home Assistant frontend authors, and copied here under the |
| 3 | * Apache 2.0 license |
| 4 | * (https://github.com/home-assistant/frontend/blob/dev/LICENSE.md). |
| 5 | * |
| 6 | * Slightly adapted. |
| 7 | * |
| 8 | * Original file: |
| 9 | * https://github.com/home-assistant/frontend/blob/4922e575f822c65d81fcde1225cfee5e338ac997/src/components/ha-svg-icon.ts |
| 10 | **/ |
| 11 | import {css, CSSResultGroup, LitElement, svg, SVGTemplateResult} from 'lit'; |
| 12 | import {customElement, property} from 'lit/decorators.js'; |
| 13 | |
| 14 | @customElement('ha-svg-icon') |
| 15 | export class HaSvgIcon extends LitElement { |
| 16 | @property() public path?: string; |
| 17 | |
| 18 | @property() public viewBox?: string; |
| 19 | |
| 20 | protected render(): SVGTemplateResult { |
| 21 | return svg` |
| 22 | <svg |
| 23 | viewBox=${this.viewBox || '0 0 24 24'} |
| 24 | preserveAspectRatio="xMidYMid meet" |
| 25 | focusable="false" |
| 26 | role="img" |
| 27 | aria-hidden="true" |
| 28 | > |
| 29 | <g> |
| 30 | ${this.path ? svg`<path d=${this.path}></path>` : ''} |
| 31 | </g> |
| 32 | </svg>`; |
| 33 | } |
| 34 | |
| 35 | static get styles(): CSSResultGroup { |
| 36 | return css` |
| 37 | :host { |
| 38 | display: var(--ha-icon-display, inline-flex); |
| 39 | align-items: center; |
| 40 | justify-content: center; |
| 41 | position: relative; |
| 42 | vertical-align: middle; |
| 43 | fill: currentcolor; |
| 44 | width: var(--mdc-icon-size, 24px); |
| 45 | height: var(--mdc-icon-size, 24px); |
| 46 | } |
| 47 | svg { |
| 48 | width: 100%; |
| 49 | height: 100%; |
| 50 | pointer-events: none; |
| 51 | display: block; |
| 52 | } |
| 53 | `; |
| 54 | } |
| 55 | } |
| 56 | declare global { |
| 57 | interface HTMLElementTagNameMap { |
| 58 | 'ha-svg-icon': HaSvgIcon; |
| 59 | } |
| 60 | } |