UNPKG

@kitten-science/kitten-scientists

Version:

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

47 lines 1.67 kB
import { Fieldset } from "./Fieldset.js"; import { RadioItem } from "./RadioItem.js"; import { UiComponent } from "./UiComponent.js"; export class OptionsListItem extends UiComponent { fieldset; setting; _items; /** * Construct a new options setting element. * This is a list of options, where the selected option will be put into the setting. * * @param host The userscript instance. * @param label The label on the setting element. * @param setting The setting this element is linked to. * @param options Options for the list item. */ constructor(parent, label, setting, options) { super(parent, { ...options, onRefresh: () => { for (const option of this._items) { if (option.option.value === this.setting.selected) { option.input.prop("checked", true); break; } } options?.onRefresh?.(); }, }); this.element = $("<li/>"); this.fieldset = new Fieldset(parent, label); this.addChild(this.fieldset); this._items = new Array(); for (const option of setting.options) { this._items.push(new RadioItem(parent, setting, option, label, { onCheck: options?.onCheck, readOnly: options?.readOnly, })); } this.fieldset.addChildren(this._items); this.setting = setting; } toString() { return `[${OptionsListItem.name}#${this.componentId}]`; } } //# sourceMappingURL=OptionsListItem.js.map