diff --git a/gallery/src/demos/demo-ha-svg-icon.ts b/gallery/src/demos/demo-ha-svg-icon.ts new file mode 100644 index 0000000000..da420aadaa --- /dev/null +++ b/gallery/src/demos/demo-ha-svg-icon.ts @@ -0,0 +1,68 @@ +import { + mdiRocketLaunch, + mdiHomeAssistant, + mdiDocker, + mdiExclamationThick, + mdiFlask, +} from "@mdi/js"; +import { css, html, LitElement, TemplateResult } from "lit"; +import { customElement } from "lit/decorators"; +import "../../../src/components/ha-card"; +import "../../../src/components/ha-svg-icon"; + +@customElement("demo-ha-svg-icon") +export class DemoHaSvgIcon extends LitElement { + protected render(): TemplateResult { + return html` + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ `; + } + + static get styles() { + return css` + ha-card { + max-width: 600px; + margin: 24px auto; + } + ha-svg-icon { + margin: 4px; + } + ha-svg-icon[background] { + color: var(--card-background-color); + } + .icon { + display: flex; + align-items: center; + } + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "demo-ha-svg-icon": DemoHaSvgIcon; + } +} diff --git a/src/components/ha-svg-icon.ts b/src/components/ha-svg-icon.ts index b8f6a3b5c7..3ee79971fd 100644 --- a/src/components/ha-svg-icon.ts +++ b/src/components/ha-svg-icon.ts @@ -1,5 +1,6 @@ import { css, CSSResultGroup, LitElement, svg, SVGTemplateResult } from "lit"; import { customElement, property } from "lit/decorators"; +import { getColorByIndex } from "../common/color/colors"; @customElement("ha-svg-icon") export class HaSvgIcon extends LitElement { @@ -7,9 +8,15 @@ export class HaSvgIcon extends LitElement { @property() public viewBox?: string; + @property({ type: Boolean }) public background = false; + protected render(): SVGTemplateResult { return svg` @@ -28,12 +35,14 @@ export class HaSvgIcon extends LitElement { position: relative; vertical-align: middle; fill: currentcolor; - width: var(--mdc-icon-size, 24px); - height: var(--mdc-icon-size, 24px); + } + .background { + padding: 8px; + border-radius: 50%; } svg { - width: 100%; - height: 100%; + width: var(--mdc-icon-size, 24px); + height: var(--mdc-icon-size, 24px); pointer-events: none; display: block; }