2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2021-06-10 01:36:20 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement";
|
2020-06-25 03:39:31 +02:00
|
|
|
|
2021-06-10 01:36:20 +02:00
|
|
|
export class VariableUiElement extends BaseUIElement {
|
2020-06-25 03:39:31 +02:00
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
})
|
2020-06-25 03:39:31 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 01:36:20 +02:00
|
|
|
protected InnerConstructElement(): HTMLElement {
|
|
|
|
return this._element;
|
2020-06-25 03:39:31 +02:00
|
|
|
}
|
2020-08-22 18:57:27 +02:00
|
|
|
|
2020-06-25 03:39:31 +02:00
|
|
|
}
|