mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +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,
|
||||
} 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) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user