Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-path icon support and path attributes #18189

Merged
merged 8 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/components/ha-icon.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
css,
html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
import { debounce } from "../common/util/debounce";
import { CustomIcon, customIcons } from "../data/custom_icons";
import {
checkCacheVersion,
Chunks,
findIconChunk,
getIcon,
Icons,
MDI_PREFIXES,
checkCacheVersion,
findIconChunk,
getIcon,
writeCache,
} from "../data/iconsets";
import "./ha-svg-icon";
Expand Down Expand Up @@ -47,6 +47,8 @@ export class HaIcon extends LitElement {

@state() private _path?: string;

@state() private _secondaryPath?: string;

@state() private _viewBox?: string;

@state() private _legacy = false;
Expand All @@ -55,6 +57,7 @@ export class HaIcon extends LitElement {
super.willUpdate(changedProps);
if (changedProps.has("icon")) {
this._path = undefined;
this._secondaryPath = undefined;
this._viewBox = undefined;
this._loadIcon();
}
Expand All @@ -70,6 +73,7 @@ export class HaIcon extends LitElement {
}
return html`<ha-svg-icon
.path=${this._path}
.secondaryPath=${this._secondaryPath}
.viewBox=${this._viewBox}
></ha-svg-icon>`;
}
Expand Down Expand Up @@ -175,6 +179,7 @@ export class HaIcon extends LitElement {
return;
}
this._path = icon.path;
this._secondaryPath = icon.secondaryPath;
this._viewBox = icon.viewBox;
}

Expand Down
31 changes: 27 additions & 4 deletions src/components/ha-svg-icon.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { css, CSSResultGroup, LitElement, svg, SVGTemplateResult } from "lit";
import {
css,
CSSResultGroup,
LitElement,
nothing,
svg,
SVGTemplateResult,
} from "lit";
import { customElement, property } from "lit/decorators";

@customElement("ha-svg-icon")
export class HaSvgIcon extends LitElement {
@property() public path?: string;

@property() public secondaryPath?: string;

@property() public viewBox?: string;

protected render(): SVGTemplateResult {
Expand All @@ -13,11 +22,20 @@ export class HaSvgIcon extends LitElement {
viewBox=${this.viewBox || "0 0 24 24"}
preserveAspectRatio="xMidYMid meet"
focusable="false"
role="img"
role="img"
aria-hidden="true"
>
<g>
${this.path ? svg`<path d=${this.path}></path>` : ""}
${
this.path
? svg`<path class="primary-path" d=${this.path}></path>`
: nothing
}
${
this.secondaryPath
? svg`<path class="secondary-path" d=${this.secondaryPath}></path>`
: nothing
}
</g>
</svg>`;
}
Expand All @@ -30,7 +48,8 @@ export class HaSvgIcon extends LitElement {
justify-content: center;
position: relative;
vertical-align: middle;
fill: currentcolor;
fill: var(--icon-primary-color, currentcolor);
opacity: var(--icon-primary-opactity, 1);
width: var(--mdc-icon-size, 24px);
sisimomo marked this conversation as resolved.
Show resolved Hide resolved
height: var(--mdc-icon-size, 24px);
}
Expand All @@ -40,6 +59,10 @@ export class HaSvgIcon extends LitElement {
pointer-events: none;
display: block;
}
path.secondary-path {
fill: var(--icon-secondary-color, currentcolor);
opacity: var(--icon-secondary-opactity, 0.5);
}
`;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/data/custom_icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { customIconsets } from "./custom_iconsets";

export interface CustomIcon {
path: string;
secondaryPath?: string;
viewBox?: string;
}

Expand Down
Loading