@descope/web-components-ui 1.0.187 → 1.0.189
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.cjs.js +62 -0
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +62 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/descope-button-selection-group-index-js.js +1 -1
- package/package.json +1 -1
- package/src/components/descope-button-selection-group/ButtonSelectionGroupClass.js +63 -1
package/dist/index.esm.js
CHANGED
@@ -6945,6 +6945,64 @@ const componentName$2 = getComponentName('button-selection-group');
|
|
6945
6945
|
|
6946
6946
|
const customMixin = (superclass) =>
|
6947
6947
|
class ButtonSelectionGroupMixinClass extends superclass {
|
6948
|
+
// eslint-disable-next-line class-methods-use-this
|
6949
|
+
#renderItem = ({ value, label }) =>
|
6950
|
+
`<descope-button-selection-group-item value="${value}">${label}</descope-button-selection-group-item>`;
|
6951
|
+
|
6952
|
+
#data;
|
6953
|
+
|
6954
|
+
get renderItem() {
|
6955
|
+
return this.#renderItem;
|
6956
|
+
}
|
6957
|
+
|
6958
|
+
set renderItem(renderFn) {
|
6959
|
+
this.#renderItem = renderFn;
|
6960
|
+
this.renderItems();
|
6961
|
+
}
|
6962
|
+
|
6963
|
+
get data() {
|
6964
|
+
if (this.#data) return this.#data;
|
6965
|
+
|
6966
|
+
try {
|
6967
|
+
const data = JSON.parse(this.getAttribute('data'));
|
6968
|
+
if (this.isValidDataType(data)) {
|
6969
|
+
return data;
|
6970
|
+
}
|
6971
|
+
} catch (e) {
|
6972
|
+
// eslint-disable-next-line no-console
|
6973
|
+
console.error('could not parse data string from attribute "data" - ', e.message);
|
6974
|
+
}
|
6975
|
+
|
6976
|
+
return [];
|
6977
|
+
}
|
6978
|
+
|
6979
|
+
set data(data) {
|
6980
|
+
if (this.isValidDataType(data)) {
|
6981
|
+
this.#data = data;
|
6982
|
+
this.renderItems();
|
6983
|
+
}
|
6984
|
+
}
|
6985
|
+
|
6986
|
+
// eslint-disable-next-line class-methods-use-this
|
6987
|
+
isValidDataType(data) {
|
6988
|
+
const isValid = Array.isArray(data);
|
6989
|
+
if (!isValid) {
|
6990
|
+
// eslint-disable-next-line no-console
|
6991
|
+
console.error('data must be an array, received:', data);
|
6992
|
+
}
|
6993
|
+
|
6994
|
+
return isValid;
|
6995
|
+
}
|
6996
|
+
|
6997
|
+
getItemsTemplate() {
|
6998
|
+
return this.data?.reduce?.((acc, item) => acc + (this.renderItem?.(item || {}) || ''), '');
|
6999
|
+
}
|
7000
|
+
|
7001
|
+
renderItems() {
|
7002
|
+
const template = this.getItemsTemplate();
|
7003
|
+
if (template) this.innerHTML = this.getItemsTemplate();
|
7004
|
+
}
|
7005
|
+
|
6948
7006
|
init() {
|
6949
7007
|
super.init?.();
|
6950
7008
|
const template = document.createElement('template');
|
@@ -6964,6 +7022,10 @@ const customMixin = (superclass) =>
|
|
6964
7022
|
this.inputElement = this.shadowRoot.querySelector(componentName$3);
|
6965
7023
|
|
6966
7024
|
forwardAttrs(this, this.inputElement, { includeAttrs: ['size', 'default-value'] });
|
7025
|
+
|
7026
|
+
this.renderItems();
|
7027
|
+
|
7028
|
+
observeAttributes(this, this.renderItems.bind(this), { includeAttrs: ['data'] });
|
6967
7029
|
}
|
6968
7030
|
};
|
6969
7031
|
|