mapcomplete/UI/Base/Button.ts

38 lines
1,023 B
TypeScript
Raw Normal View History

2020-06-29 01:12:44 +00:00
import {UIElement} from "../UIElement";
import Locale from "../i18n/Locale";
2020-07-25 16:00:08 +00:00
import Translations from "../i18n/Translations";
2020-06-29 01:12:44 +00:00
export class Button extends UIElement {
private _text: UIElement;
private _onclick: () => void;
private _clss: string;
2020-07-25 16:00:08 +00:00
constructor(text: string | UIElement, onclick: (() => void), clss: string = "") {
super(Locale.language);
2020-07-25 16:00:08 +00:00
this._text = Translations.W(text);
2020-06-29 01:12:44 +00:00
this._onclick = onclick;
if (clss !== "") {
this._clss = "class='" + clss + "'";
}else{
this._clss = "";
}
}
2020-07-20 16:24:00 +00:00
InnerRender(): string {
2020-06-29 01:12:44 +00: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();
}
}
}