UNPKG

@kitten-science/kitten-scientists

Version:

Add-on for the wonderful incremental browser game: https://kittensgame.com/web/

48 lines 1.56 kB
import { isNil } from "@oliversalzburg/js-utils/data/nil.js"; import { redirectErrorsToConsole } from "@oliversalzburg/js-utils/errors/console.js"; import stylesButton from "./Button.module.css"; import styles from "./TextButton.module.css"; import { UiComponent } from "./UiComponent.js"; export class TextButton extends UiComponent { readOnly; constructor(parent, label, options) { super(parent, { ...options, onRefresh: () => { if (this.readOnly) { this.element.addClass(stylesButton.readonly); } else { this.element.removeClass(stylesButton.readonly); } options?.onRefresh?.call(this); }, }); this.element = $("<div/>").addClass(styles.textButton); if (label !== undefined) { this.element.text(label); } const title = options?.title; if (!isNil(title)) { this.element.prop("title", title); } this.readOnly = false; this.element.on("click", () => { if (this.readOnly) { return; } this.click().catch(redirectErrorsToConsole(console)); }); } toString() { return `[${TextButton.name}#${this.componentId}]`; } async click() { if (this.readOnly) { return; } await this.options?.onClick?.call(this); this.requestRefresh(); } } //# sourceMappingURL=TextButton.js.map