phantasmal-world/src/core/gui/Button.ts

21 lines
594 B
TypeScript
Raw Normal View History

2019-08-20 04:56:40 +08:00
import { create_el } from "./dom";
import { View } from "./View";
import "./Button.css";
2019-08-20 21:02:58 +08:00
import { Observable } from "../observable/Observable";
import { emitter } from "../observable";
2019-08-20 04:56:40 +08:00
export class Button extends View {
readonly element: HTMLButtonElement = create_el("button", "core_Button");
private readonly _click = emitter<MouseEvent>();
readonly click: Observable<MouseEvent> = this._click;
2019-08-20 04:56:40 +08:00
constructor(text: string) {
super();
this.element.textContent = text;
this.element.onclick = (e: MouseEvent) => this._click.emit(e, undefined);
2019-08-20 04:56:40 +08:00
}
}