Beta UI by pythongosssss (#70)

* PR1

* PR2

* pr3

* Fix

* Revert 3909

* Ignore/fix type errors
This commit is contained in:
Chenlei Hu
2024-07-01 12:55:16 -04:00
committed by GitHub
parent 3799100811
commit 0d084e2cb0
37 changed files with 4135 additions and 470 deletions

View File

@@ -1,23 +1,28 @@
import { $el } from "../ui";
export class ComfyDialog<T extends HTMLElement = HTMLElement> {
export class ComfyDialog<T extends HTMLElement = HTMLElement> extends EventTarget {
element: T;
textElement: HTMLElement;
#buttons: HTMLButtonElement[] | null;
constructor() {
this.element = $el("div.comfy-modal", { parent: document.body }, [
constructor(type = "div", buttons = null) {
super();
this.#buttons = buttons;
this.element = $el(type + ".comfy-modal", { parent: document.body }, [
$el("div.comfy-modal-content", [$el("p", { $: (p) => (this.textElement = p) }), ...this.createButtons()]),
]) as T;
}
createButtons() {
return [
$el("button", {
type: "button",
textContent: "Close",
onclick: () => this.close(),
}),
];
return (
this.#buttons ?? [
$el("button", {
type: "button",
textContent: "Close",
onclick: () => this.close(),
}),
]
);
}
close() {
@@ -28,7 +33,7 @@ export class ComfyDialog<T extends HTMLElement = HTMLElement> {
if (typeof html === "string") {
this.textElement.innerHTML = html;
} else {
this.textElement.replaceChildren(html);
this.textElement.replaceChildren(...(html instanceof Array ? html : [html]));
}
this.element.style.display = "flex";
}