UNPKG

@kitten-science/kitten-scientists

Version:

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

58 lines 2.19 kB
import { isNil } from "@oliversalzburg/js-utils/data/nil.js"; import stylesDelimiter from "./Delimiter.module.css"; import stylesLabel from "./LabelListItem.module.css"; import stylesSettingListItem from "./SettingListItem.module.css"; import { UiComponent } from "./UiComponent.js"; export class RadioItem extends UiComponent { setting; option; elementLabel; input; readOnly; /** * Construct a new radio setting element. * This is a radio input that is expected to be hosted in a `Fieldset`. * * @param host The userscript instance. * @param setting The setting this element is linked to. * @param option The specific option out of the setting that this radio item represents. * @param groupKey A unique name for the group of radio items this one belongs to. * @param options Options for this radio item. */ constructor(parent, setting, option, groupKey, options) { super(parent, { ...options, onRefresh: () => { this.input.prop("disabled", this.readOnly); }, }); this.element = $("<div/>"); this.element.addClass(stylesSettingListItem.setting); if (options?.delimiter === true) { this.element.addClass(stylesDelimiter.delimiter); } this.elementLabel = $("<label/>", { text: `${options?.upgradeIndicator ? "⮤ " : ""}${option.label}`, }).addClass(stylesLabel.label); const input = $("<input/>", { name: groupKey, type: "radio", }).addClass("ks-radio"); this.readOnly = options?.readOnly ?? false; input.on("change", () => { this.setting.selected = option.value; if (!isNil(options?.onCheck)) { options.onCheck(); } }); this.elementLabel.prepend(input); this.element.append(this.elementLabel); this.input = input; this.setting = setting; this.option = option; } toString() { return `[${RadioItem.name}#${this.componentId}]: '${this.elementLabel.text()}'`; } } //# sourceMappingURL=RadioItem.js.map