mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Simplify custom icon set, return only 1 icon per call (#5822)
This commit is contained in:
parent
d10be4ef2d
commit
29ed1144d5
@ -10,7 +10,7 @@ import {
|
|||||||
CSSResult,
|
CSSResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
import { customIconsets, CustomIcons } from "../data/custom_iconsets";
|
import { customIconsets, CustomIcon } from "../data/custom_iconsets";
|
||||||
import {
|
import {
|
||||||
Chunks,
|
Chunks,
|
||||||
MDI_PREFIXES,
|
MDI_PREFIXES,
|
||||||
@ -64,11 +64,16 @@ export class HaIcon extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [iconPrefix, iconName] = this.icon.split(":", 2);
|
const [iconPrefix, iconName] = this.icon.split(":", 2);
|
||||||
|
|
||||||
|
if (!iconPrefix || !iconName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!MDI_PREFIXES.includes(iconPrefix)) {
|
if (!MDI_PREFIXES.includes(iconPrefix)) {
|
||||||
if (iconPrefix in customIconsets) {
|
if (iconPrefix in customIconsets) {
|
||||||
const customIconset = customIconsets[iconPrefix];
|
const customIconset = customIconsets[iconPrefix];
|
||||||
if (customIconset) {
|
if (customIconset) {
|
||||||
this._setCustomPath(customIconset(iconName), iconName);
|
this._setCustomPath(customIconset(iconName));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -97,13 +102,10 @@ export class HaIcon extends LitElement {
|
|||||||
debouncedWriteCache();
|
debouncedWriteCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _setCustomPath(
|
private async _setCustomPath(promise: Promise<CustomIcon>) {
|
||||||
promise: Promise<CustomIcons>,
|
const icon = await promise;
|
||||||
iconName: string
|
this._path = icon.path;
|
||||||
) {
|
this._viewBox = icon.viewBox;
|
||||||
const iconPack = await promise;
|
|
||||||
this._path = iconPack[iconName].path;
|
|
||||||
this._viewBox = iconPack[iconName].viewBox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _setPath(promise: Promise<Icons>, iconName: string) {
|
private async _setPath(promise: Promise<Icons>, iconName: string) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
export interface CustomIcons {
|
export interface CustomIcon {
|
||||||
[key: string]: { path: string; viewBox?: string };
|
path: string;
|
||||||
|
viewBox?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomIconsetsWindow {
|
export interface CustomIconsetsWindow {
|
||||||
customIconsets?: { [key: string]: (name: string) => Promise<CustomIcons> };
|
customIconsets?: { [key: string]: (name: string) => Promise<CustomIcon> };
|
||||||
}
|
}
|
||||||
|
|
||||||
const customIconsetsWindow = window as CustomIconsetsWindow;
|
const customIconsetsWindow = window as CustomIconsetsWindow;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user