Simplify custom icon set, return only 1 icon per call (#5822)

This commit is contained in:
Bram Kragten 2020-05-09 20:59:02 +02:00 committed by GitHub
parent d10be4ef2d
commit 29ed1144d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import {
CSSResult,
} from "lit-element";
import "./ha-svg-icon";
import { customIconsets, CustomIcons } from "../data/custom_iconsets";
import { customIconsets, CustomIcon } from "../data/custom_iconsets";
import {
Chunks,
MDI_PREFIXES,
@ -64,11 +64,16 @@ export class HaIcon extends LitElement {
return;
}
const [iconPrefix, iconName] = this.icon.split(":", 2);
if (!iconPrefix || !iconName) {
return;
}
if (!MDI_PREFIXES.includes(iconPrefix)) {
if (iconPrefix in customIconsets) {
const customIconset = customIconsets[iconPrefix];
if (customIconset) {
this._setCustomPath(customIconset(iconName), iconName);
this._setCustomPath(customIconset(iconName));
}
return;
}
@ -97,13 +102,10 @@ export class HaIcon extends LitElement {
debouncedWriteCache();
}
private async _setCustomPath(
promise: Promise<CustomIcons>,
iconName: string
) {
const iconPack = await promise;
this._path = iconPack[iconName].path;
this._viewBox = iconPack[iconName].viewBox;
private async _setCustomPath(promise: Promise<CustomIcon>) {
const icon = await promise;
this._path = icon.path;
this._viewBox = icon.viewBox;
}
private async _setPath(promise: Promise<Icons>, iconName: string) {

View File

@ -1,9 +1,10 @@
export interface CustomIcons {
[key: string]: { path: string; viewBox?: string };
export interface CustomIcon {
path: string;
viewBox?: string;
}
export interface CustomIconsetsWindow {
customIconsets?: { [key: string]: (name: string) => Promise<CustomIcons> };
customIconsets?: { [key: string]: (name: string) => Promise<CustomIcon> };
}
const customIconsetsWindow = window as CustomIconsetsWindow;