Skip to content

Commit f27f777

Browse files
committed
Split icon managers into their own files
Also, add a TODO to have ActionIconManager manage feather icon replacement in renderDialog
1 parent 23724b7 commit f27f777

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import { AssetManager } from "./manager/asset";
3333
import { formatTilesetName } from "./util/format";
3434
import * as marked from "marked";
3535
import { FullscreenManager } from "./manager/fullscreen";
36-
import { ActionIconManager, AppIconManager } from "./manager/icon";
36+
import { ActionIconManager } from "./manager/action-icon";
37+
import { AppIconManager } from "./manager/app-icon";
3738

3839
import "./styles/global.css";
3940

src/manager/action-icon.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import feather from "feather-icons";
2+
3+
export class ActionIconManager {
4+
private iconsLoaded: boolean = false;
5+
6+
constructor() {
7+
this.iconsLoaded = false;
8+
}
9+
10+
public loadIcons() {
11+
feather.replace();
12+
this.iconsLoaded = true;
13+
}
14+
15+
public changeIcon(parentElement: HTMLElement, newIcon: string) {
16+
let childElement = parentElement.querySelector("svg") as HTMLOrSVGElement;
17+
if (childElement) {
18+
(childElement as SVGElement).remove();
19+
childElement = document.createElement("i");
20+
} else {
21+
childElement = parentElement.querySelector("i") as HTMLElement;
22+
}
23+
(childElement as HTMLElement).setAttribute("data-feather", newIcon);
24+
parentElement.appendChild(childElement as HTMLElement);
25+
if (this.iconsLoaded) {
26+
feather.replace();
27+
}
28+
}
29+
}

src/manager/icon.ts src/manager/app-icon.ts

-30
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
import feather from "feather-icons";
2-
3-
export class ActionIconManager {
4-
private iconsLoaded: boolean = false;
5-
6-
constructor() {
7-
this.iconsLoaded = false;
8-
}
9-
10-
public loadIcons() {
11-
feather.replace();
12-
this.iconsLoaded = true;
13-
}
14-
15-
public changeIcon(parentElement: HTMLElement, newIcon: string) {
16-
let childElement = parentElement.querySelector("svg") as HTMLOrSVGElement;
17-
if (childElement) {
18-
(childElement as SVGElement).remove();
19-
childElement = document.createElement("i");
20-
} else {
21-
childElement = parentElement.querySelector("i") as HTMLElement;
22-
}
23-
(childElement as HTMLElement).setAttribute("data-feather", newIcon);
24-
parentElement.appendChild(childElement as HTMLElement);
25-
if (this.iconsLoaded) {
26-
feather.replace();
27-
}
28-
}
29-
}
30-
311
export class AppIconManager {
322
constructor() {}
333

src/render.ts

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export const renderDialog = (content: HTMLElement, options?: DialogOptions) => {
222222
overlayBackElem.style.display = "block";
223223

224224
(document.querySelector(".dialog [data-feather='x']") as HTMLElement).innerText = "X";
225+
// TODO: ActionIconManager should handle feather.replace()
225226
feather.replace();
226227

227228
dialog.show();

0 commit comments

Comments
 (0)