@limetech/lime-elements 37.1.0-next.2 → 37.1.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{checkbox.template-5603ad4a.js → checkbox.template-df6fc114.js} +4 -4
- package/dist/cjs/checkbox.template-df6fc114.js.map +1 -0
- package/dist/cjs/limel-checkbox.cjs.entry.js +3 -2
- package/dist/cjs/limel-checkbox.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-form.cjs.entry.js +13 -1
- package/dist/cjs/limel-form.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-list_2.cjs.entry.js +1 -1
- package/dist/collection/components/checkbox/checkbox.js +2 -1
- package/dist/collection/components/checkbox/checkbox.js.map +1 -1
- package/dist/collection/components/checkbox/checkbox.template.js +3 -3
- package/dist/collection/components/checkbox/checkbox.template.js.map +1 -1
- package/dist/collection/components/form/fields/schema-field.js +13 -1
- package/dist/collection/components/form/fields/schema-field.js.map +1 -1
- package/dist/esm/{checkbox.template-a5d8a2bc.js → checkbox.template-c2d0fa10.js} +4 -4
- package/dist/esm/checkbox.template-c2d0fa10.js.map +1 -0
- package/dist/esm/limel-checkbox.entry.js +3 -2
- package/dist/esm/limel-checkbox.entry.js.map +1 -1
- package/dist/esm/limel-form.entry.js +13 -1
- package/dist/esm/limel-form.entry.js.map +1 -1
- package/dist/esm/limel-list_2.entry.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-be492c93.entry.js → p-378bb196.entry.js} +2 -2
- package/dist/lime-elements/{p-be492c93.entry.js.map → p-378bb196.entry.js.map} +1 -1
- package/dist/lime-elements/{p-71210c65.entry.js → p-55dcbc35.entry.js} +2 -2
- package/dist/lime-elements/p-7cfc8998.js +2 -0
- package/dist/lime-elements/p-7cfc8998.js.map +1 -0
- package/dist/lime-elements/{p-0f1a9472.entry.js → p-c6f8ea40.entry.js} +6 -6
- package/dist/lime-elements/p-c6f8ea40.entry.js.map +1 -0
- package/dist/types/components/checkbox/checkbox.d.ts +1 -0
- package/dist/types/components/checkbox/checkbox.template.d.ts +1 -0
- package/package.json +4 -4
- package/dist/cjs/checkbox.template-5603ad4a.js.map +0 -1
- package/dist/esm/checkbox.template-a5d8a2bc.js.map +0 -1
- package/dist/lime-elements/p-0f1a9472.entry.js.map +0 -1
- package/dist/lime-elements/p-b2d4f3f0.js +0 -2
- package/dist/lime-elements/p-b2d4f3f0.js.map +0 -1
- /package/dist/lime-elements/{p-71210c65.entry.js.map → p-55dcbc35.entry.js.map} +0 -0
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-38eb64b5.js');
|
|
6
6
|
const component = require('./component-66df95e7.js');
|
|
7
|
-
const checkbox_template = require('./checkbox.template-
|
|
7
|
+
const checkbox_template = require('./checkbox.template-df6fc114.js');
|
|
8
8
|
const dom = require('./dom-eb080f70.js');
|
|
9
9
|
const keycodes = require('./keycodes-3949f425.js');
|
|
10
10
|
require('./component-67144c1c.js');
|
|
@@ -10,6 +10,7 @@ import { CheckboxTemplate } from './checkbox.template';
|
|
|
10
10
|
export class Checkbox {
|
|
11
11
|
constructor() {
|
|
12
12
|
this.id = createRandomString();
|
|
13
|
+
this.helperTextId = createRandomString();
|
|
13
14
|
this.initialize = () => {
|
|
14
15
|
const element = this.limelCheckbox.shadowRoot.querySelector('.mdc-form-field');
|
|
15
16
|
if (!element) {
|
|
@@ -59,7 +60,7 @@ export class Checkbox {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
render() {
|
|
62
|
-
return (h(CheckboxTemplate, { disabled: this.disabled || this.readonly, label: this.label, helperText: this.helperText, checked: this.checked || this.indeterminate, indeterminate: this.indeterminate, required: this.required, readonly: this.readonly, invalid: this.required && this.modified && !this.checked, onChange: this.onChange, id: this.id }));
|
|
63
|
+
return (h(CheckboxTemplate, { disabled: this.disabled || this.readonly, label: this.label, helperText: this.helperText, helperTextId: this.helperTextId, checked: this.checked || this.indeterminate, indeterminate: this.indeterminate, required: this.required, readonly: this.readonly, invalid: this.required && this.modified && !this.checked, onChange: this.onChange, id: this.id }));
|
|
63
64
|
}
|
|
64
65
|
static get is() { return "limel-checkbox"; }
|
|
65
66
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../../src/components/checkbox/checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,KAAK,EACL,KAAK,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;GAGG;AAMH,MAAM,OAAO,QAAQ;;IA4DT,OAAE,GAAW,kBAAkB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../../src/components/checkbox/checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,KAAK,EACL,KAAK,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;GAGG;AAMH,MAAM,OAAO,QAAQ;;IA4DT,OAAE,GAAW,kBAAkB,EAAE,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;;;;;;;;;;;;;;;;;;;;;;;;;CAuBJ","sourcesContent":["import { MDCCheckbox, cssClasses } from '@material/checkbox';\nimport { MDCFormField } from '@material/form-field';\nimport {\n Component,\n Element,\n Event,\n EventEmitter,\n h,\n Prop,\n State,\n Watch,\n} from '@stencil/core';\nimport { createRandomString } from '../../util/random-string';\nimport { CheckboxTemplate } from './checkbox.template';\n\n/**\n * @exampleComponent limel-example-checkbox\n * @exampleComponent limel-example-checkbox-helper-text\n */\n@Component({\n tag: 'limel-checkbox',\n shadow: true,\n styleUrl: 'checkbox.scss',\n})\nexport class Checkbox {\n /**\n * Disables the checkbox when `true`. Works exactly the same as `readonly`.\n * If either property is `true`, the checkbox will be disabled.\n */\n @Prop({ reflect: true })\n public disabled = false;\n\n /**\n * Disables the checkbox when `true`. This visualizes the checkbox slightly differently.\n * But shows no visual sign indicating that the checkbox is disabled\n * or can ever become interactable.\n */\n @Prop({ reflect: true })\n public readonly = false;\n\n /**\n * The checkbox label.\n */\n @Prop({ reflect: true })\n public label: string;\n\n /**\n * Optional helper text to display below the checkbox\n */\n @Prop({ reflect: true })\n public helperText: string;\n\n /**\n * The value of the checkbox. Set to `true` to make the checkbox checked.\n */\n @Prop({ reflect: true })\n public checked = false;\n\n /**\n * Enables indeterminate state. Set to `true` to signal indeterminate check.\n */\n @Prop({ reflect: true })\n public indeterminate = false;\n\n /**\n * Set to `true` to indicate that the checkbox must be checked.\n */\n @Prop({ reflect: true })\n public required: boolean = false;\n\n @State()\n private modified = false;\n\n /**\n * Emitted when the input value is changed.\n */\n @Event()\n private change: EventEmitter<boolean>;\n\n @Element()\n private limelCheckbox: HTMLLimelCheckboxElement;\n\n private formField: MDCFormField;\n private mdcCheckbox: MDCCheckbox;\n private id: string = createRandomString();\n private helperTextId: string = createRandomString();\n\n @Watch('checked')\n protected handleCheckedChange(newValue: boolean) {\n this.mdcCheckbox.checked = newValue;\n }\n\n @Watch('indeterminate')\n protected handleIndeterminateChange(newValue: boolean) {\n this.mdcCheckbox.checked = this.checked;\n this.mdcCheckbox.indeterminate = newValue;\n }\n\n public connectedCallback() {\n this.initialize();\n }\n\n public componentDidLoad() {\n this.initialize();\n }\n\n public disconnectedCallback() {\n this.mdcCheckbox?.destroy();\n this.formField?.destroy();\n\n const checkboxElement = this.getCheckboxElement();\n if (checkboxElement) {\n checkboxElement.classList.remove(\n cssClasses.ANIM_CHECKED_INDETERMINATE,\n cssClasses.ANIM_CHECKED_UNCHECKED,\n cssClasses.ANIM_INDETERMINATE_CHECKED,\n cssClasses.ANIM_INDETERMINATE_UNCHECKED,\n cssClasses.ANIM_UNCHECKED_CHECKED,\n cssClasses.ANIM_UNCHECKED_INDETERMINATE\n );\n }\n }\n\n public render() {\n return (\n <CheckboxTemplate\n disabled={this.disabled || this.readonly}\n label={this.label}\n helperText={this.helperText}\n helperTextId={this.helperTextId}\n checked={this.checked || this.indeterminate}\n indeterminate={this.indeterminate}\n required={this.required}\n readonly={this.readonly}\n invalid={this.required && this.modified && !this.checked}\n onChange={this.onChange}\n id={this.id}\n />\n );\n }\n\n private initialize = () => {\n const element =\n this.limelCheckbox.shadowRoot.querySelector('.mdc-form-field');\n if (!element) {\n return;\n }\n\n this.formField = new MDCFormField(element);\n this.mdcCheckbox = new MDCCheckbox(this.getCheckboxElement());\n this.formField.input = this.mdcCheckbox;\n };\n\n private getCheckboxElement = () => {\n return this.limelCheckbox.shadowRoot.querySelector('.mdc-checkbox');\n };\n\n private onChange = (event: Event) => {\n event.stopPropagation();\n this.change.emit(this.mdcCheckbox.checked);\n this.modified = true;\n };\n}\n"]}
|
|
@@ -12,20 +12,20 @@ export const CheckboxTemplate = (props) => {
|
|
|
12
12
|
'mdc-checkbox--required': props.required,
|
|
13
13
|
'mdc-checkbox--indeterminate': props.indeterminate,
|
|
14
14
|
'lime-checkbox--readonly': props.readonly,
|
|
15
|
-
} }, h("input", Object.assign({ type: "checkbox", class: "mdc-checkbox__native-control", id: props.id, checked: props.checked, disabled: props.disabled || props.readonly, required: props.required, onChange: props.onChange }, inputProps)), h("div", { class: "mdc-checkbox__background" }, h("svg", { class: "mdc-checkbox__checkmark", viewBox: "0 0 24 24" }, h("path", { class: "mdc-checkbox__checkmark-path", fill: "none", d: "M1.73,12.91 8.1,19.28 22.79,4.59" })), h("div", { class: "mdc-checkbox__mixedmark" }))), h("label", { class: {
|
|
15
|
+
} }, h("input", Object.assign({ type: "checkbox", class: "mdc-checkbox__native-control", id: props.id, checked: props.checked, disabled: props.disabled || props.readonly, required: props.required, onChange: props.onChange, "aria-controls": props.helperTextId, "aria-describedby": props.helperTextId }, inputProps)), h("div", { class: "mdc-checkbox__background" }, h("svg", { class: "mdc-checkbox__checkmark", viewBox: "0 0 24 24" }, h("path", { class: "mdc-checkbox__checkmark-path", fill: "none", d: "M1.73,12.91 8.1,19.28 22.79,4.59" })), h("div", { class: "mdc-checkbox__mixedmark" }))), h("label", { class: {
|
|
16
16
|
'mdc-checkbox--invalid': props.invalid,
|
|
17
17
|
'mdc-checkbox--disabled': props.disabled,
|
|
18
18
|
'mdc-checkbox--required': props.required,
|
|
19
19
|
'mdc-checkbox--indeterminate': props.indeterminate,
|
|
20
20
|
'lime-checkbox--readonly': props.readonly,
|
|
21
21
|
}, htmlFor: props.id }, props.label)),
|
|
22
|
-
h(HelperText, { text: props.helperText }),
|
|
22
|
+
h(HelperText, { text: props.helperText, helperTextId: props.helperTextId }),
|
|
23
23
|
];
|
|
24
24
|
};
|
|
25
25
|
const HelperText = (props) => {
|
|
26
26
|
if (typeof props.text !== 'string') {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
return h("limel-helper-line", { helperText: props.text.trim() });
|
|
29
|
+
return (h("limel-helper-line", { helperText: props.text.trim(), helperTextId: props.helperTextId }));
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=checkbox.template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.template.js","sourceRoot":"","sources":["../../../src/components/checkbox/checkbox.template.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,CAAC,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"checkbox.template.js","sourceRoot":"","sources":["../../../src/components/checkbox/checkbox.template.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,CAAC,EAAE,MAAM,eAAe,CAAC;AAgBvD,MAAM,CAAC,MAAM,gBAAgB,GAA+C,CACxE,KAAK,EACP,EAAE;EACA,MAAM,UAAU,GAAG,EAAE,CAAC;EACtB,IAAI,KAAK,CAAC,aAAa,EAAE;IACrB,UAAU,CAAC,oBAAoB,CAAC,GAAG,MAAM,CAAC;GAC7C;EAED,OAAO;IACH,WAAK,KAAK,EAAC,iBAAiB;MACxB,WACI,KAAK,EAAE;UACH,cAAc,EAAE,IAAI;UACpB,uBAAuB,EAAE,KAAK,CAAC,OAAO;UACtC,wBAAwB,EAAE,KAAK,CAAC,QAAQ;UACxC,wBAAwB,EAAE,KAAK,CAAC,QAAQ;UACxC,6BAA6B,EAAE,KAAK,CAAC,aAAa;UAClD,yBAAyB,EAAE,KAAK,CAAC,QAAQ;SAC5C;QAED,2BACI,IAAI,EAAC,UAAU,EACf,KAAK,EAAC,8BAA8B,EACpC,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,EAC1C,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ,mBACT,KAAK,CAAC,YAAY,sBACf,KAAK,CAAC,YAAY,IAChC,UAAU,EAChB;QACF,WAAK,KAAK,EAAC,0BAA0B;UACjC,WAAK,KAAK,EAAC,yBAAyB,EAAC,OAAO,EAAC,WAAW;YACpD,YACI,KAAK,EAAC,8BAA8B,EACpC,IAAI,EAAC,MAAM,EACX,CAAC,EAAC,kCAAkC,GACtC,CACA;UACN,WAAK,KAAK,EAAC,yBAAyB,GAAG,CACrC,CACJ;MACN,aACI,KAAK,EAAE;UACH,uBAAuB,EAAE,KAAK,CAAC,OAAO;UACtC,wBAAwB,EAAE,KAAK,CAAC,QAAQ;UACxC,wBAAwB,EAAE,KAAK,CAAC,QAAQ;UACxC,6BAA6B,EAAE,KAAK,CAAC,aAAa;UAClD,yBAAyB,EAAE,KAAK,CAAC,QAAQ;SAC5C,EACD,OAAO,EAAE,KAAK,CAAC,EAAE,IAEhB,KAAK,CAAC,KAAK,CACR,CACN;IACN,EAAC,UAAU,IACP,IAAI,EAAE,KAAK,CAAC,UAAU,EACtB,YAAY,EAAE,KAAK,CAAC,YAAY,GAClC;GACL,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,UAAU,GAGX,CAAC,KAAK,EAAE,EAAE;EACX,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;IAChC,OAAO;GACV;EAED,OAAO,CACH,yBACI,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAC7B,YAAY,EAAE,KAAK,CAAC,YAAY,GAClC,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { FunctionalComponent, h } from '@stencil/core';\n\ninterface CheckboxTemplateProps {\n disabled?: boolean;\n id: string;\n checked?: boolean;\n readonly?: boolean;\n indeterminate?: boolean;\n required?: boolean;\n invalid?: boolean;\n onChange?: (event: Event) => void;\n label?: string;\n helperText?: string;\n helperTextId?: string;\n}\n\nexport const CheckboxTemplate: FunctionalComponent<CheckboxTemplateProps> = (\n props\n) => {\n const inputProps = {};\n if (props.indeterminate) {\n inputProps['data-indeterminate'] = 'true';\n }\n\n return [\n <div class=\"mdc-form-field \">\n <div\n class={{\n 'mdc-checkbox': true,\n 'mdc-checkbox--invalid': props.invalid,\n 'mdc-checkbox--disabled': props.disabled,\n 'mdc-checkbox--required': props.required,\n 'mdc-checkbox--indeterminate': props.indeterminate,\n 'lime-checkbox--readonly': props.readonly,\n }}\n >\n <input\n type=\"checkbox\"\n class=\"mdc-checkbox__native-control\"\n id={props.id}\n checked={props.checked}\n disabled={props.disabled || props.readonly}\n required={props.required}\n onChange={props.onChange}\n aria-controls={props.helperTextId}\n aria-describedby={props.helperTextId}\n {...inputProps}\n />\n <div class=\"mdc-checkbox__background\">\n <svg class=\"mdc-checkbox__checkmark\" viewBox=\"0 0 24 24\">\n <path\n class=\"mdc-checkbox__checkmark-path\"\n fill=\"none\"\n d=\"M1.73,12.91 8.1,19.28 22.79,4.59\"\n />\n </svg>\n <div class=\"mdc-checkbox__mixedmark\" />\n </div>\n </div>\n <label\n class={{\n 'mdc-checkbox--invalid': props.invalid,\n 'mdc-checkbox--disabled': props.disabled,\n 'mdc-checkbox--required': props.required,\n 'mdc-checkbox--indeterminate': props.indeterminate,\n 'lime-checkbox--readonly': props.readonly,\n }}\n htmlFor={props.id}\n >\n {props.label}\n </label>\n </div>,\n <HelperText\n text={props.helperText}\n helperTextId={props.helperTextId}\n />,\n ];\n};\n\nconst HelperText: FunctionalComponent<{\n helperTextId: string;\n text: string;\n}> = (props) => {\n if (typeof props.text !== 'string') {\n return;\n }\n\n return (\n <limel-helper-line\n helperText={props.text.trim()}\n helperTextId={props.helperTextId}\n />\n );\n};\n"]}
|
|
@@ -32,7 +32,19 @@ const shouldChangeToUndefined = (value, schema) => {
|
|
|
32
32
|
};
|
|
33
33
|
const hasCustomComponent = (schema) => {
|
|
34
34
|
var _a, _b;
|
|
35
|
-
|
|
35
|
+
const name = (_b = (_a = schema.lime) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.name;
|
|
36
|
+
if (!name) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
verifyCustomComponentIsDefined(name);
|
|
41
|
+
}
|
|
42
|
+
catch (_c) {
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.warn(`Custom component ${name} not defined`);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
36
48
|
};
|
|
37
49
|
const verifyCustomComponentIsDefined = (elementName) => {
|
|
38
50
|
const supportsCustomElements = 'customElements' in window;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-field.js","sourceRoot":"","sources":["../../../../src/components/form/fields/schema-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,eAAe,MAAM,8CAA8C,CAAC;AAC3E,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAW,EAAE;EACvD,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAW,EAAE;;EAC3C,OAAO,OAAO,CAAC,MAAA,MAAA,MAAM,CAAC,IAAI,0CAAE,SAAS,0CAAE,IAAI,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CAAC,WAAW,EAAQ,EAAE;EACzD,MAAM,sBAAsB,GAAG,gBAAgB,IAAI,MAAM,CAAC;EAE1D,IAAI,CAAC,sBAAsB,EAAE;IACzB,MAAM,IAAI,KAAK,CACX,yDAAyD,CAC5D,CAAC;GACL;EAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;IAClC,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,mBAAmB,CAAC,CAAC;GAC3E;AACL,CAAC,CAAC;AAEF,MAAM,kBAAkB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CAAC,CAAC;KACjD;IAED,MAAM,UAAU,mCACT,IAAI,CAAC,KAAK,KACb,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC9B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;EAC5D,CAAC;EAED;;;;;;;;KAQG;EACK,aAAa,CAAC,QAAgB;IAClC,IAAI,QAAQ,KAAK,SAAS,EAAE;MACxB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EACpD,CAAC;CACJ","sourcesContent":["import { LimeElementsAdapter } from '../adapters';\nimport JSONSchemaField from '@rjsf/core/lib/components/fields/SchemaField';\nimport React from 'react';\nimport { FieldProps } from './types';\nimport { isEmpty, capitalize } from 'lodash-es';\nimport { resetDependentFields } from './field-helpers';\nimport { FieldTemplate } from '../templates';\n\n/**\n * If given a value and schema, check if the value should be translated\n * from null to undefined to avoid issues with validation\n *\n * This function needs to be used for several reasons:\n * 1. CustomEvent does not allow `detail` to equal `undefined`, but we can call onChange with `undefined` in React\n * 2. `null` is treated as a valid value in a jsonschema and with marshmallow and it has its own type (null)\n * 3. Without changing `null` to `undefined` there would be no way to remove a field from\n * from the submitted form data once it had any data. (when POSTing, undefined is not posted since its not valid json)\n * 4. The only applies to custom web components since widgets handle transforming null/'' to undefined depending on the widget\n * and its purpose.\n *\n * Example:\n * If I have an object { name?: string, email?: string } that I am using a custom web component for `name`,\n * then initially, the formData will be {} which is fine because neither name or email are required. Then if i input a\n * value for name the formData will be { name: 'some_value' } which is also fine. But then if I want to remove name\n * from the form data I would delete all the text from the name input field. Web components would emit this empty value\n * as '' or null. If the web component tries to emit `undefined`, null would be emitted instead because CustomEvent has\n * a default `detail` value of null\n * @param {any} value the value associated with the schema\n * @param {any} schema the schema for the value\n * @returns {boolean} whether or not null should be changed to undefined\n */\nconst shouldChangeToUndefined = (value, schema): boolean => {\n return value === null && !schema.type.includes('null');\n};\n\nconst hasCustomComponent = (schema): boolean => {\n return Boolean(schema.lime?.component?.name);\n};\n\nconst verifyCustomComponentIsDefined = (elementName): void => {\n const supportsCustomElements = 'customElements' in window;\n\n if (!supportsCustomElements) {\n throw new Error(\n 'Custom form elements are not supported by this browser!'\n );\n }\n\n if (!customElements.get(elementName)) {\n throw new Error(`Custom form element '${elementName}' is not defined!`);\n }\n};\n\nconst getCustomComponent = (\n schema\n): { name: string; props: { [key: string]: any } } => {\n const name = schema.lime?.component?.name;\n const props = schema.lime?.component?.props || {};\n\n return { name: name, props: props };\n};\n\n/**\n * Create properties from the factory that is set on `limel-form`\n * @param {*} formContext the form context\n * @param {*} schema the schema for the current field\n * @returns {object} the properties created by the factory\n */\nexport function getFactoryProps(\n formContext: any,\n schema: any\n): Record<string, any> {\n const factory: (schema: any) => Record<string, any> =\n formContext.propsFactory;\n if (typeof factory !== 'function') {\n return {};\n }\n\n const props = factory(schema);\n if (!props) {\n return {};\n }\n\n return props;\n}\n\nexport class SchemaField extends React.Component<FieldProps> {\n state = {\n modified: false,\n };\n\n constructor(props) {\n super(props);\n this.handleChange = this.handleChange.bind(this);\n this.handleCustomComponentChange =\n this.handleCustomComponentChange.bind(this);\n this.initState();\n }\n\n private initState() {\n if (this.hasValue()) {\n this.state.modified = true;\n }\n }\n\n private hasValue() {\n const value = this.getValue();\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return !!value.length;\n }\n\n if (typeof value === 'object') {\n return !isEmpty(value);\n }\n\n return true;\n }\n\n private getLabel() {\n const { schema } = this.props;\n\n return schema.title;\n }\n\n private isInvalid() {\n const { modified } = this.state;\n const { errorSchema } = this.props;\n\n if (!modified) {\n return false;\n }\n\n return !isEmpty(errorSchema);\n }\n\n private isRequired() {\n const { required, schema } = this.props;\n\n return required || schema.minItems > 0;\n }\n\n private getHelperText() {\n const { errorSchema, schema } = this.props;\n\n if (!this.isInvalid()) {\n const helperText = schema.lime?.component?.props?.helperText;\n\n return helperText || schema.description;\n }\n\n if (!isEmpty(errorSchema) && '__errors' in errorSchema) {\n return capitalize(errorSchema.__errors[0]); // eslint-disable-line no-underscore-dangle\n }\n\n return schema.description;\n }\n\n private getValue() {\n const { formData } = this.props;\n\n return formData;\n }\n\n private handleCustomComponentChange(event) {\n const { schema } = this.props;\n event.stopPropagation();\n\n let value = event.detail;\n\n if (shouldChangeToUndefined(value, schema)) {\n value = undefined;\n }\n\n this.handleChange(value);\n }\n\n private handleChange(data) {\n const { formData, schema } = this.props;\n const { rootSchema } = this.props.registry;\n\n this.setState({ modified: true });\n\n const newData = resetDependentFields(\n formData,\n data,\n schema,\n rootSchema\n );\n\n this.props.onChange(newData);\n }\n\n private buildCustomComponentProps() {\n const {\n disabled,\n readonly,\n name,\n registry,\n schema,\n errorSchema,\n idSchema,\n } = this.props;\n const factoryProps = getFactoryProps(registry.formContext, schema);\n\n return {\n ...factoryProps,\n value: this.getValue(),\n required: this.isRequired(),\n readonly: readonly || schema.readOnly,\n disabled: disabled,\n invalid: this.isInvalid(),\n label: this.getLabel(),\n helperText: this.getHelperText(),\n formInfo: {\n schema: schema,\n rootSchema: registry.formContext.schema,\n errorSchema: errorSchema,\n rootValue: registry.formContext.rootValue,\n name: name,\n schemaPath: this.getSchemaPath(idSchema?.$id),\n },\n };\n }\n\n private renderCustomComponent(props: FieldProps) {\n const { name, props: userDefinedComponentProps } = getCustomComponent(\n props.schema\n );\n\n verifyCustomComponentIsDefined(name);\n\n const component = React.createElement(LimeElementsAdapter, {\n name: name,\n elementProps: {\n ...userDefinedComponentProps,\n ...this.buildCustomComponentProps(),\n },\n events: {\n change: this.handleCustomComponentChange,\n },\n });\n\n return React.createElement(\n FieldTemplate,\n {\n ...this.props,\n classNames: 'form-group field field-custom',\n },\n component\n );\n }\n\n render() {\n if (hasCustomComponent(this.props.schema)) {\n return this.renderCustomComponent(this.props);\n }\n\n const fieldProps = {\n ...this.props,\n onChange: this.handleChange,\n };\n\n return React.createElement(JSONSchemaField, fieldProps);\n }\n\n /**\n * Gets the path to the current property within the schema\n * @param {string} schemaId the id of the schema\n * @returns {string[]} an array with the schema path for the current property\n * @example\n * const schemaId = 'root_sections_0_controls_0_name';\n * const schemaPath = getSchemaPath(schemaId);\n * // => ['sections', '0', 'controls', '0', 'name']\n */\n private getSchemaPath(schemaId: string): string[] {\n if (schemaId === undefined) {\n return undefined;\n }\n\n return schemaId.replace('root_', '').split('_');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schema-field.js","sourceRoot":"","sources":["../../../../src/components/form/fields/schema-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,eAAe,MAAM,8CAA8C,CAAC;AAC3E,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAW,EAAE;EACvD,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAW,EAAE;;EAC3C,MAAM,IAAI,GAAG,MAAA,MAAA,MAAM,CAAC,IAAI,0CAAE,SAAS,0CAAE,IAAI,CAAC;EAC1C,IAAI,CAAC,IAAI,EAAE;IACP,OAAO,KAAK,CAAC;GAChB;EAED,IAAI;IACA,8BAA8B,CAAC,IAAI,CAAC,CAAC;GACxC;EAAC,WAAM;IACJ,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,oBAAoB,IAAI,cAAc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BAAmB,EAAE;MACvD,IAAI,EAAE,IAAI;MACV,YAAY,kCACL,yBAAyB,GACzB,IAAI,CAAC,yBAAyB,EAAE,CACtC;MACD,MAAM,EAAE;QACJ,MAAM,EAAE,IAAI,CAAC,2BAA2B;OAC3C;KACJ,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,aAAa,CACtB,aAAa,kCAEN,IAAI,CAAC,KAAK,KACb,UAAU,EAAE,+BAA+B,KAE/C,SAAS,CACZ,CAAC;EACN,CAAC;EAED,MAAM;IACF,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;MACvC,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACjD;IAED,MAAM,UAAU,mCACT,IAAI,CAAC,KAAK,KACb,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC9B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;EAC5D,CAAC;EAED;;;;;;;;KAQG;EACK,aAAa,CAAC,QAAgB;IAClC,IAAI,QAAQ,KAAK,SAAS,EAAE;MACxB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EACpD,CAAC;CACJ","sourcesContent":["import { LimeElementsAdapter } from '../adapters';\nimport JSONSchemaField from '@rjsf/core/lib/components/fields/SchemaField';\nimport React from 'react';\nimport { FieldProps } from './types';\nimport { isEmpty, capitalize } from 'lodash-es';\nimport { resetDependentFields } from './field-helpers';\nimport { FieldTemplate } from '../templates';\n\n/**\n * If given a value and schema, check if the value should be translated\n * from null to undefined to avoid issues with validation\n *\n * This function needs to be used for several reasons:\n * 1. CustomEvent does not allow `detail` to equal `undefined`, but we can call onChange with `undefined` in React\n * 2. `null` is treated as a valid value in a jsonschema and with marshmallow and it has its own type (null)\n * 3. Without changing `null` to `undefined` there would be no way to remove a field from\n * from the submitted form data once it had any data. (when POSTing, undefined is not posted since its not valid json)\n * 4. The only applies to custom web components since widgets handle transforming null/'' to undefined depending on the widget\n * and its purpose.\n *\n * Example:\n * If I have an object { name?: string, email?: string } that I am using a custom web component for `name`,\n * then initially, the formData will be {} which is fine because neither name or email are required. Then if i input a\n * value for name the formData will be { name: 'some_value' } which is also fine. But then if I want to remove name\n * from the form data I would delete all the text from the name input field. Web components would emit this empty value\n * as '' or null. If the web component tries to emit `undefined`, null would be emitted instead because CustomEvent has\n * a default `detail` value of null\n * @param {any} value the value associated with the schema\n * @param {any} schema the schema for the value\n * @returns {boolean} whether or not null should be changed to undefined\n */\nconst shouldChangeToUndefined = (value, schema): boolean => {\n return value === null && !schema.type.includes('null');\n};\n\nconst hasCustomComponent = (schema): boolean => {\n const name = schema.lime?.component?.name;\n if (!name) {\n return false;\n }\n\n try {\n verifyCustomComponentIsDefined(name);\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Custom component ${name} not defined`);\n\n return false;\n }\n\n return true;\n};\n\nconst verifyCustomComponentIsDefined = (elementName): void => {\n const supportsCustomElements = 'customElements' in window;\n\n if (!supportsCustomElements) {\n throw new Error(\n 'Custom form elements are not supported by this browser!'\n );\n }\n\n if (!customElements.get(elementName)) {\n throw new Error(`Custom form element '${elementName}' is not defined!`);\n }\n};\n\nconst getCustomComponent = (\n schema\n): { name: string; props: { [key: string]: any } } => {\n const name = schema.lime?.component?.name;\n const props = schema.lime?.component?.props || {};\n\n return { name: name, props: props };\n};\n\n/**\n * Create properties from the factory that is set on `limel-form`\n * @param {*} formContext the form context\n * @param {*} schema the schema for the current field\n * @returns {object} the properties created by the factory\n */\nexport function getFactoryProps(\n formContext: any,\n schema: any\n): Record<string, any> {\n const factory: (schema: any) => Record<string, any> =\n formContext.propsFactory;\n if (typeof factory !== 'function') {\n return {};\n }\n\n const props = factory(schema);\n if (!props) {\n return {};\n }\n\n return props;\n}\n\nexport class SchemaField extends React.Component<FieldProps> {\n state = {\n modified: false,\n };\n\n constructor(props) {\n super(props);\n this.handleChange = this.handleChange.bind(this);\n this.handleCustomComponentChange =\n this.handleCustomComponentChange.bind(this);\n this.initState();\n }\n\n private initState() {\n if (this.hasValue()) {\n this.state.modified = true;\n }\n }\n\n private hasValue() {\n const value = this.getValue();\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return !!value.length;\n }\n\n if (typeof value === 'object') {\n return !isEmpty(value);\n }\n\n return true;\n }\n\n private getLabel() {\n const { schema } = this.props;\n\n return schema.title;\n }\n\n private isInvalid() {\n const { modified } = this.state;\n const { errorSchema } = this.props;\n\n if (!modified) {\n return false;\n }\n\n return !isEmpty(errorSchema);\n }\n\n private isRequired() {\n const { required, schema } = this.props;\n\n return required || schema.minItems > 0;\n }\n\n private getHelperText() {\n const { errorSchema, schema } = this.props;\n\n if (!this.isInvalid()) {\n const helperText = schema.lime?.component?.props?.helperText;\n\n return helperText || schema.description;\n }\n\n if (!isEmpty(errorSchema) && '__errors' in errorSchema) {\n return capitalize(errorSchema.__errors[0]); // eslint-disable-line no-underscore-dangle\n }\n\n return schema.description;\n }\n\n private getValue() {\n const { formData } = this.props;\n\n return formData;\n }\n\n private handleCustomComponentChange(event) {\n const { schema } = this.props;\n event.stopPropagation();\n\n let value = event.detail;\n\n if (shouldChangeToUndefined(value, schema)) {\n value = undefined;\n }\n\n this.handleChange(value);\n }\n\n private handleChange(data) {\n const { formData, schema } = this.props;\n const { rootSchema } = this.props.registry;\n\n this.setState({ modified: true });\n\n const newData = resetDependentFields(\n formData,\n data,\n schema,\n rootSchema\n );\n\n this.props.onChange(newData);\n }\n\n private buildCustomComponentProps() {\n const {\n disabled,\n readonly,\n name,\n registry,\n schema,\n errorSchema,\n idSchema,\n } = this.props;\n const factoryProps = getFactoryProps(registry.formContext, schema);\n\n return {\n ...factoryProps,\n value: this.getValue(),\n required: this.isRequired(),\n readonly: readonly || schema.readOnly,\n disabled: disabled,\n invalid: this.isInvalid(),\n label: this.getLabel(),\n helperText: this.getHelperText(),\n formInfo: {\n schema: schema,\n rootSchema: registry.formContext.schema,\n errorSchema: errorSchema,\n rootValue: registry.formContext.rootValue,\n name: name,\n schemaPath: this.getSchemaPath(idSchema?.$id),\n },\n };\n }\n\n private renderCustomComponent(props: FieldProps) {\n const { name, props: userDefinedComponentProps } = getCustomComponent(\n props.schema\n );\n\n verifyCustomComponentIsDefined(name);\n\n const component = React.createElement(LimeElementsAdapter, {\n name: name,\n elementProps: {\n ...userDefinedComponentProps,\n ...this.buildCustomComponentProps(),\n },\n events: {\n change: this.handleCustomComponentChange,\n },\n });\n\n return React.createElement(\n FieldTemplate,\n {\n ...this.props,\n classNames: 'form-group field field-custom',\n },\n component\n );\n }\n\n render() {\n if (hasCustomComponent(this.props.schema)) {\n return this.renderCustomComponent(this.props);\n }\n\n const fieldProps = {\n ...this.props,\n onChange: this.handleChange,\n };\n\n return React.createElement(JSONSchemaField, fieldProps);\n }\n\n /**\n * Gets the path to the current property within the schema\n * @param {string} schemaId the id of the schema\n * @returns {string[]} an array with the schema path for the current property\n * @example\n * const schemaId = 'root_sections_0_controls_0_name';\n * const schemaPath = getSchemaPath(schemaId);\n * // => ['sections', '0', 'controls', '0', 'name']\n */\n private getSchemaPath(schemaId: string): string[] {\n if (schemaId === undefined) {\n return undefined;\n }\n\n return schemaId.replace('root_', '').split('_');\n }\n}\n"]}
|
|
@@ -15,7 +15,7 @@ const CheckboxTemplate = (props) => {
|
|
|
15
15
|
'mdc-checkbox--indeterminate': props.indeterminate,
|
|
16
16
|
'lime-checkbox--readonly': props.readonly,
|
|
17
17
|
} },
|
|
18
|
-
h("input", Object.assign({ type: "checkbox", class: "mdc-checkbox__native-control", id: props.id, checked: props.checked, disabled: props.disabled || props.readonly, required: props.required, onChange: props.onChange }, inputProps)),
|
|
18
|
+
h("input", Object.assign({ type: "checkbox", class: "mdc-checkbox__native-control", id: props.id, checked: props.checked, disabled: props.disabled || props.readonly, required: props.required, onChange: props.onChange, "aria-controls": props.helperTextId, "aria-describedby": props.helperTextId }, inputProps)),
|
|
19
19
|
h("div", { class: "mdc-checkbox__background" },
|
|
20
20
|
h("svg", { class: "mdc-checkbox__checkmark", viewBox: "0 0 24 24" },
|
|
21
21
|
h("path", { class: "mdc-checkbox__checkmark-path", fill: "none", d: "M1.73,12.91 8.1,19.28 22.79,4.59" })),
|
|
@@ -27,16 +27,16 @@ const CheckboxTemplate = (props) => {
|
|
|
27
27
|
'mdc-checkbox--indeterminate': props.indeterminate,
|
|
28
28
|
'lime-checkbox--readonly': props.readonly,
|
|
29
29
|
}, htmlFor: props.id }, props.label)),
|
|
30
|
-
h(HelperText, { text: props.helperText }),
|
|
30
|
+
h(HelperText, { text: props.helperText, helperTextId: props.helperTextId }),
|
|
31
31
|
];
|
|
32
32
|
};
|
|
33
33
|
const HelperText = (props) => {
|
|
34
34
|
if (typeof props.text !== 'string') {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
return h("limel-helper-line", { helperText: props.text.trim() });
|
|
37
|
+
return (h("limel-helper-line", { helperText: props.text.trim(), helperTextId: props.helperTextId }));
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
export { CheckboxTemplate as C };
|
|
41
41
|
|
|
42
|
-
//# sourceMappingURL=checkbox.template-
|
|
42
|
+
//# sourceMappingURL=checkbox.template-c2d0fa10.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"checkbox.template-c2d0fa10.js","mappings":";;MAgBa,gBAAgB,GAA+C,CACxE,KAAK;EAEL,MAAM,UAAU,GAAG,EAAE,CAAC;EACtB,IAAI,KAAK,CAAC,aAAa,EAAE;IACrB,UAAU,CAAC,oBAAoB,CAAC,GAAG,MAAM,CAAC;GAC7C;EAED,OAAO;IACH,WAAK,KAAK,EAAC,iBAAiB;MACxB,WACI,KAAK,EAAE;UACH,cAAc,EAAE,IAAI;UACpB,uBAAuB,EAAE,KAAK,CAAC,OAAO;UACtC,wBAAwB,EAA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ACI,yBACI,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAC7B,YAAY,EAAE,KAAK,CAAC,YAAY,GAClC,EACJ;AACN,CAAC;;;;","names":[],"sources":["./src/components/checkbox/checkbox.template.tsx"],"sourcesContent":["import { FunctionalComponent, h } from '@stencil/core';\n\ninterface CheckboxTemplateProps {\n disabled?: boolean;\n id: string;\n checked?: boolean;\n readonly?: boolean;\n indeterminate?: boolean;\n required?: boolean;\n invalid?: boolean;\n onChange?: (event: Event) => void;\n label?: string;\n helperText?: string;\n helperTextId?: string;\n}\n\nexport const CheckboxTemplate: FunctionalComponent<CheckboxTemplateProps> = (\n props\n) => {\n const inputProps = {};\n if (props.indeterminate) {\n inputProps['data-indeterminate'] = 'true';\n }\n\n return [\n <div class=\"mdc-form-field \">\n <div\n class={{\n 'mdc-checkbox': true,\n 'mdc-checkbox--invalid': props.invalid,\n 'mdc-checkbox--disabled': props.disabled,\n 'mdc-checkbox--required': props.required,\n 'mdc-checkbox--indeterminate': props.indeterminate,\n 'lime-checkbox--readonly': props.readonly,\n }}\n >\n <input\n type=\"checkbox\"\n class=\"mdc-checkbox__native-control\"\n id={props.id}\n checked={props.checked}\n disabled={props.disabled || props.readonly}\n required={props.required}\n onChange={props.onChange}\n aria-controls={props.helperTextId}\n aria-describedby={props.helperTextId}\n {...inputProps}\n />\n <div class=\"mdc-checkbox__background\">\n <svg class=\"mdc-checkbox__checkmark\" viewBox=\"0 0 24 24\">\n <path\n class=\"mdc-checkbox__checkmark-path\"\n fill=\"none\"\n d=\"M1.73,12.91 8.1,19.28 22.79,4.59\"\n />\n </svg>\n <div class=\"mdc-checkbox__mixedmark\" />\n </div>\n </div>\n <label\n class={{\n 'mdc-checkbox--invalid': props.invalid,\n 'mdc-checkbox--disabled': props.disabled,\n 'mdc-checkbox--required': props.required,\n 'mdc-checkbox--indeterminate': props.indeterminate,\n 'lime-checkbox--readonly': props.readonly,\n }}\n htmlFor={props.id}\n >\n {props.label}\n </label>\n </div>,\n <HelperText\n text={props.helperText}\n helperTextId={props.helperTextId}\n />,\n ];\n};\n\nconst HelperText: FunctionalComponent<{\n helperTextId: string;\n text: string;\n}> = (props) => {\n if (typeof props.text !== 'string') {\n return;\n }\n\n return (\n <limel-helper-line\n helperText={props.text.trim()}\n helperTextId={props.helperTextId}\n />\n );\n};\n"],"version":3}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-232e9616.js';
|
|
2
2
|
import { c as createRandomString } from './random-string-812b1c35.js';
|
|
3
|
-
import { C as CheckboxTemplate } from './checkbox.template-
|
|
3
|
+
import { C as CheckboxTemplate } from './checkbox.template-c2d0fa10.js';
|
|
4
4
|
import { M as MDCFoundation, a as MDCComponent } from './component-410aad5a.js';
|
|
5
5
|
import { a as getCorrectEventName } from './util-f1bde91c.js';
|
|
6
6
|
import { M as MDCRipple, a as applyPassive, b as MDCRippleFoundation } from './component-5b4ac85a.js';
|
|
@@ -736,6 +736,7 @@ const Checkbox = class {
|
|
|
736
736
|
registerInstance(this, hostRef);
|
|
737
737
|
this.change = createEvent(this, "change", 7);
|
|
738
738
|
this.id = createRandomString();
|
|
739
|
+
this.helperTextId = createRandomString();
|
|
739
740
|
this.initialize = () => {
|
|
740
741
|
const element = this.limelCheckbox.shadowRoot.querySelector('.mdc-form-field');
|
|
741
742
|
if (!element) {
|
|
@@ -785,7 +786,7 @@ const Checkbox = class {
|
|
|
785
786
|
}
|
|
786
787
|
}
|
|
787
788
|
render() {
|
|
788
|
-
return (h(CheckboxTemplate, { disabled: this.disabled || this.readonly, label: this.label, helperText: this.helperText, checked: this.checked || this.indeterminate, indeterminate: this.indeterminate, required: this.required, readonly: this.readonly, invalid: this.required && this.modified && !this.checked, onChange: this.onChange, id: this.id }));
|
|
789
|
+
return (h(CheckboxTemplate, { disabled: this.disabled || this.readonly, label: this.label, helperText: this.helperText, helperTextId: this.helperTextId, checked: this.checked || this.indeterminate, indeterminate: this.indeterminate, required: this.required, readonly: this.readonly, invalid: this.required && this.modified && !this.checked, onChange: this.onChange, id: this.id }));
|
|
789
790
|
}
|
|
790
791
|
get limelCheckbox() { return getElement(this); }
|
|
791
792
|
static get watchers() { return {
|