mapcomplete/UI/Base/VariableUIElement.ts

35 lines
940 B
TypeScript
Raw Normal View History

import {UIEventSource} from "../../Logic/UIEventSource";
2021-06-10 01:36:20 +02:00
import BaseUIElement from "../BaseUIElement";
2021-06-10 01:36:20 +02:00
export class VariableUiElement extends BaseUIElement {
2021-06-10 01:36:20 +02:00
private _element : HTMLElement;
constructor(contents: UIEventSource<string | BaseUIElement>) {
super();
this._element = document.createElement("span")
const el = this._element
contents.addCallbackAndRun(contents => {
while(el.firstChild){
el.removeChild(
el.lastChild
)
}
if(contents === undefined){
return
}
if(typeof contents === "string"){
el.innerHTML = contents
}else{
el.appendChild(contents.ConstructElement())
}
})
}
2021-06-10 01:36:20 +02:00
protected InnerConstructElement(): HTMLElement {
return this._element;
}
}