@descope/web-components-ui 1.0.187 → 1.0.189

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.
@@ -7478,6 +7478,64 @@ const componentName$1 = getComponentName('button-selection-group');
7478
7478
 
7479
7479
  const customMixin = (superclass) =>
7480
7480
  class ButtonSelectionGroupMixinClass extends superclass {
7481
+ // eslint-disable-next-line class-methods-use-this
7482
+ #renderItem = ({ value, label }) =>
7483
+ `<descope-button-selection-group-item value="${value}">${label}</descope-button-selection-group-item>`;
7484
+
7485
+ #data;
7486
+
7487
+ get renderItem() {
7488
+ return this.#renderItem;
7489
+ }
7490
+
7491
+ set renderItem(renderFn) {
7492
+ this.#renderItem = renderFn;
7493
+ this.renderItems();
7494
+ }
7495
+
7496
+ get data() {
7497
+ if (this.#data) return this.#data;
7498
+
7499
+ try {
7500
+ const data = JSON.parse(this.getAttribute('data'));
7501
+ if (this.isValidDataType(data)) {
7502
+ return data;
7503
+ }
7504
+ } catch (e) {
7505
+ // eslint-disable-next-line no-console
7506
+ console.error('could not parse data string from attribute "data" - ', e.message);
7507
+ }
7508
+
7509
+ return [];
7510
+ }
7511
+
7512
+ set data(data) {
7513
+ if (this.isValidDataType(data)) {
7514
+ this.#data = data;
7515
+ this.renderItems();
7516
+ }
7517
+ }
7518
+
7519
+ // eslint-disable-next-line class-methods-use-this
7520
+ isValidDataType(data) {
7521
+ const isValid = Array.isArray(data);
7522
+ if (!isValid) {
7523
+ // eslint-disable-next-line no-console
7524
+ console.error('data must be an array, received:', data);
7525
+ }
7526
+
7527
+ return isValid;
7528
+ }
7529
+
7530
+ getItemsTemplate() {
7531
+ return this.data?.reduce?.((acc, item) => acc + (this.renderItem?.(item || {}) || ''), '');
7532
+ }
7533
+
7534
+ renderItems() {
7535
+ const template = this.getItemsTemplate();
7536
+ if (template) this.innerHTML = this.getItemsTemplate();
7537
+ }
7538
+
7481
7539
  init() {
7482
7540
  super.init?.();
7483
7541
  const template = document.createElement('template');
@@ -7497,6 +7555,10 @@ const customMixin = (superclass) =>
7497
7555
  this.inputElement = this.shadowRoot.querySelector(componentName$2);
7498
7556
 
7499
7557
  forwardAttrs(this, this.inputElement, { includeAttrs: ['size', 'default-value'] });
7558
+
7559
+ this.renderItems();
7560
+
7561
+ observeAttributes(this, this.renderItems.bind(this), { includeAttrs: ['data'] });
7500
7562
  }
7501
7563
  };
7502
7564