import {UIElement} from "../UIElement"; import {UIEventSource} from "../UIEventSource"; import {UIInputElement} from "./UIInputElement"; export class TextField extends UIInputElement { public value: UIEventSource = new UIEventSource(""); /** * Pings and has the value data */ public enterPressed = new UIEventSource(undefined); private _placeholder: UIEventSource; private _mapping: (string) => T; constructor(placeholder: UIEventSource, mapping: ((string) => T)) { super(placeholder); this._placeholder = placeholder; this._mapping = mapping; } GetValue(): UIEventSource { return this.value.map(this._mapping); } protected InnerRender(): string { return "
" + "" + "
"; } InnerUpdate(htmlElement: HTMLElement) { super.InnerUpdate(htmlElement); const field = document.getElementById('text-' + this.id); const self = this; field.oninput = () => { // @ts-ignore self.value.setData(field.value); }; field.addEventListener("keyup", function (event) { if (event.key === "Enter") { // @ts-ignore self.enterPressed.setData(field.value); } }); } Clear() { const field = document.getElementById('text-' + this.id); if (field !== undefined) { // @ts-ignore field.value = ""; } } }