UNPKG

@blinkk/selective-edit

Version:
56 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CheckboxField = void 0; const option_1 = require("../../mixins/option"); const field_1 = require("../field"); const lit_html_1 = require("lit-html"); class CheckboxField extends (0, option_1.OptionMixin)(field_1.Field) { constructor(types, config, globalConfig, fieldType = 'checkbox') { super(types, config, globalConfig, fieldType); this.config = config; } get isChecked() { const value = this.currentValue !== undefined ? this.currentValue : false; // If there is no value defined, treat the value as a boolean. if (this.config.value === undefined) { return value === true; } // TODO: This works for simple data types, but may fail on complex // values like objects or arrays. return value === this.config.value; } handleInput() { if (this.isChecked) { this.currentValue = this.config.valueUnchecked !== undefined ? this.config.valueUnchecked : false; } else { this.currentValue = this.config.value !== undefined ? this.config.value : true; } this.render(); } templateInput(editor, data) { return (0, lit_html_1.html) `${this.templateOptions(editor, data, { handleBlur: this.handleBlur.bind(this), handleInput: this.handleInput.bind(this), isMulti: true, isOptionSelected: () => this.isChecked, }, [this.config])} ${this.templateHelp(editor, data)} ${this.templateErrors(editor, data)}`; } /** * Label on the checkbox field is shown with the checkbox. * * @param editor Selective editor used to render the template. * @param data Data provided to render the template. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars templateLabel(editor, data) { return (0, lit_html_1.html) ``; } } exports.CheckboxField = CheckboxField; //# sourceMappingURL=checkbox.js.map