mapcomplete/UI/Base/Button.ts

38 lines
1,023 B
TypeScript
Raw Normal View History

2020-06-29 03:12:44 +02:00
import {UIElement} from "../UIElement";
import Locale from "../i18n/Locale";
2020-07-25 18:00:08 +02:00
import Translations from "../i18n/Translations";
2020-06-29 03:12:44 +02:00
export class Button extends UIElement {
private _text: UIElement;
private _onclick: () => void;
private _clss: string;
2020-07-25 18:00:08 +02:00
constructor(text: string | UIElement, onclick: (() => void), clss: string = "") {
super(Locale.language);
2020-07-25 18:00:08 +02:00
this._text = Translations.W(text);
2020-06-29 03:12:44 +02:00
this._onclick = onclick;
if (clss !== "") {
this._clss = "class='" + clss + "'";
}else{
this._clss = "";
}
}
2020-07-20 18:24:00 +02:00
InnerRender(): string {
2020-06-29 03:12:44 +02:00
return "<form>" +
"<button id='button-"+this.id+"' type='button' "+this._clss+">" + this._text.Render() + "</button>" +
"</form>";
}
InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
const self = this;
document.getElementById("button-"+this.id).onclick = function(){
self._onclick();
}
}
}