UNPKG

@kitten-science/kitten-scientists

Version:

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

54 lines 1.66 kB
import stylesButton from "./Button.module.css"; import { UiComponent } from "./UiComponent.js"; /** * A button that is visually represented through an SVG element. */ export class IconButton extends UiComponent { element; readOnly; inactive; /** * Constructs an `IconButton`. * * @param host A reference to the host. * @param pathData The SVG path data of the icon. * @param title The `title` of the element. * @param options Options for the icon button. */ constructor(host, pathData, title, options) { super(host, options); const element = $("<div/>", { html: `<svg style="width: 18px; height: 18px;" viewBox="0 -960 960 960" fill="currentColor"><path d="${pathData}"/></svg>`, title, }).addClass(stylesButton.iconButton); this.element = element; this.addChildren(options?.children); this.readOnly = options?.readOnly ?? false; this.inactive = options?.inactive ?? false; this.element.on("click", () => { this.click(); }); } click() { if (this.readOnly) { return; } super.click(); } refreshUi() { super.refreshUi(); if (this.readOnly) { this.element.addClass(stylesButton.readonly); } else { this.element.removeClass(stylesButton.readonly); } if (this.inactive) { this.element.addClass(stylesButton.inactive); } else { this.element.removeClass(stylesButton.inactive); } } } //# sourceMappingURL=IconButton.js.map