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

23 lines
741 B
TypeScript
Raw Normal View History

import { create_element } from "./dom";
2019-08-20 04:56:40 +08:00
import "./Button.css";
2019-08-20 21:02:58 +08:00
import { Observable } from "../observable/Observable";
import { emitter } from "../observable";
import { Control } from "./Control";
export class Button extends Control {
readonly element: HTMLButtonElement = create_element("button", { class: "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.append(create_element("span", { class: "core_Button_inner", text }));
this.enabled.observe(enabled => (this.element.disabled = !enabled));
this.element.onclick = (e: MouseEvent) => this._click.emit(e);
2019-08-20 04:56:40 +08:00
}
}