@kubex/zinc 1.0.112 → 1.0.113

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.0.112",
3
+ "version": "1.0.113",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -45,6 +45,7 @@ function commonOption(props: BuilderProps): EChartsOption {
45
45
  textStyle: { color: textColor },
46
46
  tooltip: {
47
47
  trigger: 'axis',
48
+ appendTo: 'body',
48
49
  valueFormatter: props.yAxisAppend
49
50
  ? (v: number | string) => `${v}${props.yAxisAppend}`
50
51
  : undefined,
@@ -201,7 +202,7 @@ export function buildSankeyOption(props: BuilderProps): EChartsOption {
201
202
  animationEasing: 'cubicOut',
202
203
  ...(props.colors ? { color: props.colors } : {}),
203
204
  textStyle: { color: textColor },
204
- tooltip: { trigger: 'item' },
205
+ tooltip: { trigger: 'item', appendTo: 'body' },
205
206
  series: [{
206
207
  type: 'sankey',
207
208
  name: first.name,
@@ -69,12 +69,12 @@ export default class ZnNavbar extends ZincElement {
69
69
  private _navItemsGap: number = 0;
70
70
  private _expandableMargin: number = 0;
71
71
  private _totalItemWidth: number = 0;
72
+ private _itemsObserver: MutationObserver | null = null;
72
73
 
73
74
  protected _store: Store;
74
75
 
75
76
  appendItem(item: Element) {
76
- this._appended = this._appended || [];
77
- this._appended.push(item);
77
+ this._appended = [...(this._appended || []), item];
78
78
  }
79
79
 
80
80
  connectedCallback() {
@@ -97,6 +97,27 @@ export default class ZnNavbar extends ZincElement {
97
97
  this._store = new Store(this.localStorage ? window.localStorage : window.sessionStorage, "znnav:", this.storeTtl);
98
98
  }
99
99
 
100
+ disconnectedCallback() {
101
+ super.disconnectedCallback();
102
+ this._itemsObserver?.disconnect();
103
+ this._itemsObserver = null;
104
+ this.resizeObserver?.disconnect();
105
+ this.resizeObserver = null;
106
+ }
107
+
108
+ private _updateVisibility = () => {
109
+ if (this._expanding.length > 0) {
110
+ this.style.display = '';
111
+ return;
112
+ }
113
+ const items = this._navItems?.querySelectorAll(':scope > li:not(.more):not(#dropdown-item)') || [];
114
+ const itemCount = items.length;
115
+ if (itemCount === 0 || (itemCount < 2 && this.hideOne)) {
116
+ this.style.display = 'none';
117
+ } else {
118
+ this.style.display = '';
119
+ }
120
+ };
100
121
 
101
122
  handleResize = () => {
102
123
  if (this._totalItemWidth === 0 || this._extendedMenu === null || this.iconBar || this.stacked) {
@@ -204,6 +225,12 @@ export default class ZnNavbar extends ZincElement {
204
225
  // Load persisted tabs before calculating widths
205
226
  this._loadStoredTabs();
206
227
 
228
+ if (this._navItems) {
229
+ this._itemsObserver = new MutationObserver(this._updateVisibility);
230
+ this._itemsObserver.observe(this._navItems, {childList: true});
231
+ }
232
+ this._updateVisibility();
233
+
207
234
  setTimeout(() => {
208
235
  const items = this._navItems?.querySelectorAll('li') || [];
209
236
  for (const item of items) {
@@ -297,16 +324,17 @@ export default class ZnNavbar extends ZincElement {
297
324
  }
298
325
  };
299
326
 
327
+ protected updated(_changedProperties: PropertyValues) {
328
+ super.updated(_changedProperties);
329
+ if (_changedProperties.has('hideOne') || _changedProperties.has('navigation') || _changedProperties.has('_appended')) {
330
+ this._updateVisibility();
331
+ }
332
+ }
333
+
300
334
  render() {
301
335
  if (!this.navigation) {
302
336
  this.navigation = [];
303
337
  }
304
- const itemCount = this.navigation?.length + this._preItems?.length + this._postItems?.length;
305
- if (this._expanding.length === 0) {
306
- if (itemCount === 0 || (itemCount < 2 && this.hideOne)) {
307
- this.style.display = 'none';
308
- }
309
- }
310
338
 
311
339
  return html`
312
340
  <div class="${classMap({
@@ -1,5 +1,6 @@
1
1
  import '../../../dist/zn.min.js';
2
- import { expect, fixture, html } from '@open-wc/testing';
2
+ import {aTimeout, expect, fixture, html} from '@open-wc/testing';
3
+ import type ZnNavbar from './navbar.component';
3
4
 
4
5
  describe('<zn-navbar>', () => {
5
6
  it('should render a component', async () => {
@@ -7,4 +8,54 @@ describe('<zn-navbar>', () => {
7
8
 
8
9
  expect(el).to.exist;
9
10
  });
11
+
12
+ describe('hide-one', () => {
13
+ it('hides when only one item is present', async () => {
14
+ const el = await fixture<ZnNavbar>(html`
15
+ <zn-navbar hide-one>
16
+ <li>Only</li>
17
+ </zn-navbar>
18
+ `);
19
+ await aTimeout(0);
20
+
21
+ expect(getComputedStyle(el).display).to.equal('none');
22
+ });
23
+
24
+ it('reveals when a second item is added dynamically', async () => {
25
+ const el = await fixture<ZnNavbar>(html`
26
+ <zn-navbar hide-one>
27
+ <li>First</li>
28
+ </zn-navbar>
29
+ `);
30
+ await aTimeout(0);
31
+ expect(getComputedStyle(el).display).to.equal('none');
32
+
33
+ const li = document.createElement('li');
34
+ li.setAttribute('tab-uri', '/two');
35
+ li.textContent = 'Second';
36
+ el.addItem(li, false);
37
+ await aTimeout(0);
38
+
39
+ expect(getComputedStyle(el).display).to.not.equal('none');
40
+ });
41
+
42
+ it('hides again when items drop back to one', async () => {
43
+ const el = await fixture<ZnNavbar>(html`
44
+ <zn-navbar hide-one>
45
+ <li>First</li>
46
+ </zn-navbar>
47
+ `);
48
+ const second = document.createElement('li');
49
+ second.setAttribute('tab-uri', '/two');
50
+ second.textContent = 'Second';
51
+ el.addItem(second, false);
52
+ await aTimeout(0);
53
+ expect(getComputedStyle(el).display).to.not.equal('none');
54
+
55
+ second.remove();
56
+ await aTimeout(0);
57
+
58
+ expect(getComputedStyle(el).display).to.equal('none');
59
+ });
60
+ });
10
61
  });
@@ -56,6 +56,7 @@ export default class ZnSimpleChart extends ZincElement {
56
56
  animationEasing: 'cubicOut',
57
57
  tooltip: {
58
58
  trigger: 'axis',
59
+ appendTo: 'body',
59
60
  backgroundColor: 'rgba(0,0,0,0.7)',
60
61
  borderWidth: 0,
61
62
  textStyle: { color: '#fff' },