import {UIEventSource} from "../UIEventSource"; import {UIElement} from "../UIElement"; export class DropDownUI extends UIElement { selectedElement: UIEventSource private _label: string; private _values: { value: string; shown: string }[]; constructor(label: string, values: { value: string, shown: string }[]) { super(undefined); this._label = label; this._values = values; this.selectedElement = new UIEventSource(values[0].value); } protected InnerRender(): string { let options = ""; for (const value of this._values) { options += "" } return "
" + "" + "" + "
"; } InnerUpdate(htmlElement: HTMLElement) { super.InnerUpdate(htmlElement); const self = this; const e = document.getElementById("dropdown-" + this.id); e.onchange = function () { // @ts-ignore const selectedValue = e.options[e.selectedIndex].value; self.selectedElement.setData(selectedValue); } } }