@haiilo/catalyst 6.5.0 → 6.5.2

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.
@@ -1,6 +1,8 @@
1
1
  // -- Reset
2
2
  @import 'sanitize.css/sanitize.css';
3
- @import 'sanitize.css/reduce-motion.css';
3
+ // had to be removed because transition events are not firing any more
4
+ // could be re-introduce with a transition-duration of 1ms
5
+ // @import 'sanitize.css/reduce-motion.css';
4
6
 
5
7
  // -- Vendor
6
8
  @import 'toastify-js/src/toastify.css';
@@ -7819,21 +7819,22 @@ const CatRadioGroup = class {
7819
7819
  this.updateTabIndex();
7820
7820
  }
7821
7821
  onDisabledChanged(disabled) {
7822
- this.catRadioGroup.forEach(catRadio => (catRadio.disabled = disabled));
7822
+ this.catRadioGroup.forEach(catRadio => (catRadio.disabled = catRadio.disabled || disabled));
7823
7823
  }
7824
7824
  onLabelLeftChanged(labelLeft) {
7825
- this.catRadioGroup.forEach(catRadio => {
7826
- if (labelLeft) {
7827
- catRadio.labelLeft = labelLeft;
7828
- }
7829
- });
7825
+ this.catRadioGroup.forEach(catRadio => (catRadio.labelLeft = catRadio.labelLeft || labelLeft));
7830
7826
  }
7831
7827
  componentDidLoad() {
7832
- this.catRadioGroup = Array.from(this.hostElement.querySelectorAll(`cat-radio`));
7833
- this.onNameChanged(this.name);
7834
- this.onValueChanged(this.value);
7835
- this.onDisabledChanged(this.disabled);
7836
- this.onLabelLeftChanged(this.labelLeft);
7828
+ this.init();
7829
+ this.mutationObserver = new MutationObserver(mutations => mutations.some(value => value.target.nodeName === 'CAT-RADIO') && this.init());
7830
+ this.mutationObserver?.observe(this.hostElement, {
7831
+ childList: true,
7832
+ attributes: true,
7833
+ subtree: true
7834
+ });
7835
+ }
7836
+ disconnectedCallback() {
7837
+ this.mutationObserver?.disconnect();
7837
7838
  }
7838
7839
  onKeydown(event) {
7839
7840
  if (['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft'].includes(event.key) && this.catRadioGroup.length) {
@@ -7868,6 +7869,13 @@ const CatRadioGroup = class {
7868
7869
  render() {
7869
7870
  return (index.h("div", { role: "radiogroup", "aria-label": this.a11yLabel }, index.h("slot", null)));
7870
7871
  }
7872
+ init() {
7873
+ this.catRadioGroup = Array.from(this.hostElement.querySelectorAll(`cat-radio`));
7874
+ this.onNameChanged(this.name);
7875
+ this.onValueChanged(this.value);
7876
+ this.onDisabledChanged(this.disabled);
7877
+ this.onLabelLeftChanged(this.labelLeft);
7878
+ }
7871
7879
  updateTabIndex() {
7872
7880
  if (this.catRadioGroup.length) {
7873
7881
  this.catRadioGroup.forEach(value => value.shadowRoot?.querySelector('input')?.setAttribute('tabindex', '-1'));
@@ -10209,21 +10217,13 @@ const catTabsCss = ":host{display:flex;flex-direction:row;box-shadow:inset 0 -1p
10209
10217
  const CatTabs = class {
10210
10218
  constructor(hostRef) {
10211
10219
  index.registerInstance(this, hostRef);
10212
- this.buttons = [];
10220
+ this.catChange = index.createEvent(this, "catChange", 7);
10213
10221
  this.tabs = [];
10214
- this.activeTabId = undefined;
10215
10222
  this.activeTab = '';
10216
10223
  this.tabsAlign = 'left';
10217
10224
  }
10218
- onActiveTabIdChanged(newActiveTab) {
10219
- const activeTab = this.tabs.find(value => value.id === newActiveTab);
10220
- activeTab?.click();
10221
- }
10222
10225
  componentWillLoad() {
10223
10226
  this.syncTabs();
10224
- if (this.tabs.length) {
10225
- this.activeTabId = this.activeTab;
10226
- }
10227
10227
  }
10228
10228
  componentDidLoad() {
10229
10229
  this.mutationObserver = new MutationObserver(mutations => mutations.some(value => value.target.nodeName === 'CAT-TAB') && this.syncTabs());
@@ -10236,9 +10236,14 @@ const CatTabs = class {
10236
10236
  disconnectedCallback() {
10237
10237
  this.mutationObserver?.disconnect();
10238
10238
  }
10239
+ onActiveTabChange(id) {
10240
+ const index = this.tabs.findIndex(tab => tab.id === id);
10241
+ this.catChange.emit({ id, index });
10242
+ }
10239
10243
  onKeydown(event) {
10240
10244
  if (['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft'].includes(event.key)) {
10241
- const targetElements = this.buttons.filter(button => !button.disabled);
10245
+ const elements = this.hostElement.shadowRoot?.querySelectorAll('cat-button[role="tab"]');
10246
+ const targetElements = Array.from(elements || []).filter(button => !button.disabled);
10242
10247
  const activeElement = this.hostElement.shadowRoot?.activeElement;
10243
10248
  const activeIdx = activeElement ? targetElements.indexOf(activeElement) : -1;
10244
10249
  const activeOff = ['ArrowDown', 'ArrowRight'].includes(event.key) ? 1 : -1;
@@ -10247,29 +10252,45 @@ const CatTabs = class {
10247
10252
  event.preventDefault();
10248
10253
  }
10249
10254
  }
10255
+ /**
10256
+ * Activates the tab with the given id.
10257
+ *
10258
+ * @param id The tab id.
10259
+ */
10260
+ async setActive(id) {
10261
+ this.activate(this.tabs.find(tab => tab.id === id));
10262
+ }
10263
+ /**
10264
+ * Activates the tab with the given index.
10265
+ *
10266
+ * @param index The tab index.
10267
+ */
10268
+ async setActiveIndex(index) {
10269
+ this.activate(this.tabs[index]);
10270
+ }
10250
10271
  render() {
10251
10272
  return (index.h(index.Host, null, this.tabs.map((tab) => {
10252
- return (index.h("cat-button", { ref: el => el && this.updateButtonsRef(el), buttonId: tab.id, role: "tab", part: "tab", class: {
10273
+ return (index.h("cat-button", { buttonId: tab.id, role: "tab", part: "tab", class: {
10253
10274
  'cat-tab': true,
10254
- 'cat-tab-active': Boolean(this.activeTabId && tab.id === this.activeTabId)
10255
- }, active: Boolean(this.activeTabId && tab.id === this.activeTabId), color: this.activeTabId && tab.id === this.activeTabId ? 'primary' : 'secondary', variant: "text", icon: tab.icon, iconOnly: tab.iconOnly, iconRight: tab.iconRight, url: tab.url, disabled: tab.deactivated, urlTarget: tab.urlTarget, onCatClick: () => (this.activeTabId = tab.id), nativeAttributes: { ...tab.nativeAttributes }, nativeContentAttributes: { 'data-text': tab.label }, "data-dropdown-no-close": true }, tab.label));
10275
+ 'cat-tab-active': tab.id === this.activeTab
10276
+ }, active: tab.id === this.activeTab, color: tab.id === this.activeTab ? 'primary' : 'secondary', variant: "text", icon: tab.icon, iconOnly: tab.iconOnly, iconRight: tab.iconRight, url: tab.url, disabled: tab.deactivated, urlTarget: tab.urlTarget, onCatClick: () => this.activate(tab), nativeAttributes: { ...tab.nativeAttributes }, nativeContentAttributes: { 'data-text': tab.label }, "data-dropdown-no-close": true }, tab.label));
10256
10277
  })));
10257
10278
  }
10258
- updateButtonsRef(button) {
10259
- const indexOf = this.buttons.indexOf(button);
10260
- if (indexOf >= 0) {
10261
- this.buttons[indexOf] = button;
10262
- }
10263
- else {
10264
- this.buttons.push(button);
10265
- }
10266
- }
10267
10279
  syncTabs() {
10268
10280
  this.tabs = Array.from(this.hostElement.querySelectorAll('cat-tab'));
10281
+ this.activeTab = this.activeTab || this.tabs.filter(tab => this.canActivate(tab))[0]?.id;
10282
+ }
10283
+ canActivate(tab) {
10284
+ return !!tab && !tab.deactivated && !tab.url && tab.id !== this.activeTab;
10285
+ }
10286
+ activate(tab) {
10287
+ if (this.canActivate(tab)) {
10288
+ this.activeTab = tab.id;
10289
+ }
10269
10290
  }
10270
10291
  get hostElement() { return index.getElement(this); }
10271
10292
  static get watchers() { return {
10272
- "activeTabId": ["onActiveTabIdChanged"]
10293
+ "activeTab": ["onActiveTabChange"]
10273
10294
  }; }
10274
10295
  };
10275
10296
  CatTabs.style = catTabsCss;