@neovici/cosmoz-bottom-bar 5.1.1 → 6.0.0-beta.1

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.
Files changed (2) hide show
  1. package/cosmoz-bottom-bar.js +80 -52
  2. package/package.json +9 -10
@@ -1,17 +1,18 @@
1
1
  /* eslint-disable max-lines */
2
2
  import {
3
- PolymerElement, html as polymerHtml
3
+ PolymerElement,
4
+ html as polymerHtml,
4
5
  } from '@polymer/polymer/polymer-element.js';
5
6
  import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer';
6
7
  import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
7
8
  import { timeOut } from '@polymer/polymer/lib/utils/async';
8
- import template from './cosmoz-bottom-bar.html.js';
9
- import { html } from 'haunted';
9
+ import { html } from 'lit-html';
10
10
  import { defaultPlacement } from '@neovici/cosmoz-dropdown';
11
+ import template from './cosmoz-bottom-bar.html.js';
11
12
 
12
- const
13
- BOTTOM_BAR_TOOLBAR_SLOT = 'bottom-bar-toolbar',
14
- BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu';
13
+ const BOTTOM_BAR_TOOLBAR_SLOT = 'bottom-bar-toolbar',
14
+ BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu',
15
+ rendered = Symbol('rendered');
15
16
 
16
17
  /**
17
18
  * `<cosmoz-bottom-bar>` is a horizontal responsive bottom toolbar containing items that
@@ -32,9 +33,10 @@ const
32
33
  * @element cosmoz-bottom-bar
33
34
  * @demo demo/bottom-bar.html Basic Demo
34
35
  * @demo demo/bottom-bar-match-parent.html match parent Demo
35
- */
36
+ */
36
37
  class CosmozBottomBar extends PolymerElement {
37
- static get template() { // eslint-disable-line max-lines-per-function
38
+ static get template() {
39
+ // eslint-disable-line max-lines-per-function
38
40
  return template;
39
41
  }
40
42
 
@@ -48,7 +50,7 @@ class CosmozBottomBar extends PolymerElement {
48
50
  type: Boolean,
49
51
  value: false,
50
52
  notify: true,
51
- reflectToAttribute: true
53
+ reflectToAttribute: true,
52
54
  },
53
55
 
54
56
  /**
@@ -56,7 +58,7 @@ class CosmozBottomBar extends PolymerElement {
56
58
  */
57
59
  barHeight: {
58
60
  type: Number,
59
- value: 64
61
+ value: 64,
60
62
  },
61
63
 
62
64
  /**
@@ -64,7 +66,7 @@ class CosmozBottomBar extends PolymerElement {
64
66
  */
65
67
  matchParent: {
66
68
  type: Boolean,
67
- value: false
69
+ value: false,
68
70
  },
69
71
 
70
72
  /**
@@ -74,12 +76,12 @@ class CosmozBottomBar extends PolymerElement {
74
76
  type: Boolean,
75
77
  value: false,
76
78
  readOnly: true,
77
- notify: true
79
+ notify: true,
78
80
  },
79
81
 
80
82
  hasExtraItems: {
81
83
  type: Boolean,
82
- value: false
84
+ value: false,
83
85
  },
84
86
 
85
87
  /**
@@ -87,7 +89,7 @@ class CosmozBottomBar extends PolymerElement {
87
89
  */
88
90
  selectedClass: {
89
91
  type: String,
90
- value: 'cosmoz-bottom-bar-selected-item'
92
+ value: 'cosmoz-bottom-bar-selected-item',
91
93
  },
92
94
 
93
95
  /**
@@ -95,7 +97,7 @@ class CosmozBottomBar extends PolymerElement {
95
97
  */
96
98
  toolbarClass: {
97
99
  type: String,
98
- value: 'cosmoz-bottom-bar-toolbar'
100
+ value: 'cosmoz-bottom-bar-toolbar',
99
101
  },
100
102
 
101
103
  /**
@@ -103,7 +105,7 @@ class CosmozBottomBar extends PolymerElement {
103
105
  */
104
106
  menuClass: {
105
107
  type: String,
106
- value: 'cosmoz-bottom-bar-menu'
108
+ value: 'cosmoz-bottom-bar-menu',
107
109
  },
108
110
 
109
111
  /**
@@ -111,7 +113,7 @@ class CosmozBottomBar extends PolymerElement {
111
113
  */
112
114
  maxToolbarItems: {
113
115
  type: Number,
114
- value: 1
116
+ value: 1,
115
117
  },
116
118
 
117
119
  /**
@@ -119,20 +121,26 @@ class CosmozBottomBar extends PolymerElement {
119
121
  */
120
122
  computedBarHeight: {
121
123
  type: Number,
122
- computed: '_computeComputedBarHeight(_matchHeightElement, barHeight, _computedBarHeightKicker)',
123
- notify: true
124
+ computed:
125
+ '_computeComputedBarHeight(_matchHeightElement, barHeight, _computedBarHeightKicker)',
126
+ notify: true,
124
127
  },
125
128
 
126
129
  /**
127
130
  * Kicker to make `computedBarHeight` recalculate
128
131
  */
129
132
  _computedBarHeightKicker: {
130
- type: Number
133
+ type: Number,
134
+ },
135
+
136
+ renderOpen: {
137
+ type: Boolean,
138
+ value: false,
131
139
  },
132
140
 
133
141
  forceOpen: {
134
142
  type: Boolean,
135
- value: false
143
+ value: false,
136
144
  },
137
145
 
138
146
  /**
@@ -142,7 +150,8 @@ class CosmozBottomBar extends PolymerElement {
142
150
  type: Boolean,
143
151
  notify: true,
144
152
  readOnly: true,
145
- computed: '_computeVisible(hasActions, active, hasExtraItems, forceOpen)'
153
+ computed:
154
+ '_computeVisible(hasActions, active, hasExtraItems, forceOpen)',
146
155
  },
147
156
 
148
157
  /**
@@ -152,7 +161,7 @@ class CosmozBottomBar extends PolymerElement {
152
161
  type: Boolean,
153
162
  value: false,
154
163
  readOnly: true,
155
- notify: true
164
+ notify: true,
156
165
  },
157
166
 
158
167
  /**
@@ -160,19 +169,17 @@ class CosmozBottomBar extends PolymerElement {
160
169
  */
161
170
  _matchHeightElement: {
162
171
  type: Object,
163
- computed: '_getHeightMatchingElement(matchParent)'
172
+ computed: '_getHeightMatchingElement(matchParent)',
164
173
  },
165
174
 
166
175
  topPlacement: {
167
- value: ['top-right', ...defaultPlacement]
168
- }
176
+ value: ['top-right', ...defaultPlacement],
177
+ },
169
178
  };
170
179
  }
171
180
 
172
181
  static get observers() {
173
- return [
174
- '_showHideBottomBar(visible)'
175
- ];
182
+ return ['_showHideBottomBar(visible, renderOpen)'];
176
183
  }
177
184
 
178
185
  constructor() {
@@ -188,23 +195,31 @@ class CosmozBottomBar extends PolymerElement {
188
195
  connectedCallback() {
189
196
  super.connectedCallback();
190
197
 
191
-
192
- const layoutOnRemove = info => info.removedNodes.filter(this._isActionNode) && this._debounceLayoutActions();
198
+ const layoutOnRemove = (info) =>
199
+ info.removedNodes.filter(this._isActionNode) &&
200
+ this._debounceLayoutActions();
193
201
  this._nodeObservers = [
194
202
  new FlattenedNodesObserver(this.$.content, this._boundChildrenUpdated),
195
- new FlattenedNodesObserver(this.$.extraSlot, info => this.set('hasExtraItems', info.addedNodes.length > 0)),
203
+ new FlattenedNodesObserver(this.$.extraSlot, (info) =>
204
+ this.set('hasExtraItems', info.addedNodes.length > 0)
205
+ ),
196
206
  new FlattenedNodesObserver(this.$.bottomBarToolbar, layoutOnRemove),
197
- new FlattenedNodesObserver(this.$.bottomBarMenu, layoutOnRemove)
207
+ new FlattenedNodesObserver(this.$.bottomBarMenu, layoutOnRemove),
198
208
  ];
199
- this._hiddenMutationObserver = new MutationObserver(() => this._debounceLayoutActions());
209
+ this._hiddenMutationObserver = new MutationObserver(() =>
210
+ this._debounceLayoutActions()
211
+ );
200
212
  this._resizeObserver.observe(this);
201
213
  this._computedBarHeightKicker = 0;
202
214
  }
203
215
 
204
216
  disconnectedCallback() {
205
217
  super.disconnectedCallback();
218
+ this[rendered] = false;
206
219
 
207
- [...this._nodeObservers, this._hiddenMutationObserver].forEach(e => e.disconnect(e));
220
+ [...this._nodeObservers, this._hiddenMutationObserver].forEach((e) =>
221
+ e.disconnect(e)
222
+ );
208
223
  this._layoutDebouncer?.cancel(); /* eslint-disable-line no-unused-expressions */
209
224
  this._resizeObserver.unobserve(this);
210
225
  }
@@ -212,15 +227,18 @@ class CosmozBottomBar extends PolymerElement {
212
227
  _childrenUpdated(info) {
213
228
  const addedNodes = info.addedNodes.filter(this._isActionNode),
214
229
  removedNodes = info.removedNodes.filter(this._isActionNode),
215
- newNodes = addedNodes.filter(node => !removedNodes.includes(node));
230
+ newNodes = addedNodes.filter((node) => !removedNodes.includes(node));
216
231
 
217
- if (addedNodes.length === 0 && removedNodes.length === 0 || newNodes.length === 0) {
232
+ if (
233
+ (addedNodes.length === 0 && removedNodes.length === 0) ||
234
+ newNodes.length === 0
235
+ ) {
218
236
  return;
219
237
  }
220
- newNodes.forEach(node => {
238
+ newNodes.forEach((node) => {
221
239
  this._hiddenMutationObserver.observe(node, {
222
240
  attributes: true,
223
- attributeFilter: ['hidden']
241
+ attributeFilter: ['hidden'],
224
242
  });
225
243
  this._moveElement(node, false);
226
244
  });
@@ -260,20 +278,22 @@ class CosmozBottomBar extends PolymerElement {
260
278
  }
261
279
 
262
280
  _isActionNode(node) {
263
- return node.nodeType === Node.ELEMENT_NODE &&
281
+ return (
282
+ node.nodeType === Node.ELEMENT_NODE &&
264
283
  node.getAttribute('slot') !== 'info' &&
265
284
  node.tagName !== 'TEMPLATE' &&
266
285
  node.tagName !== 'STYLE' &&
267
286
  node.tagName !== 'DOM-REPEAT' &&
268
287
  node.tagName !== 'DOM-IF' &&
269
- node.getAttribute('slot') !== 'extra';
288
+ node.getAttribute('slot') !== 'extra'
289
+ );
270
290
  }
271
291
 
272
292
  _getElements() {
273
293
  return FlattenedNodesObserver.getFlattenedNodes(this)
274
294
  .filter(this._isActionNode)
275
- .filter(element => !element.hidden)
276
- .sort((a, b) => (a.dataset.index ?? 0) - (b.dataset.index ?? 0 ));
295
+ .filter((element) => !element.hidden)
296
+ .sort((a, b) => (a.dataset.index ?? 0) - (b.dataset.index ?? 0));
277
297
  }
278
298
  /**
279
299
  * Layout the actions available as buttons or menu items
@@ -295,7 +315,8 @@ class CosmozBottomBar extends PolymerElement {
295
315
  *
296
316
  * @returns {void}
297
317
  */
298
- _layoutActions() { // eslint-disable-line max-statements
318
+ _layoutActions() {
319
+ // eslint-disable-line max-statements
299
320
  const elements = this._getElements(),
300
321
  hasActions = elements.length > 0 || this.hasExtraItems;
301
322
  this._setHasActions(hasActions);
@@ -307,8 +328,8 @@ class CosmozBottomBar extends PolymerElement {
307
328
 
308
329
  const toolbarElements = elements.slice(0, this.maxToolbarItems),
309
330
  menuElements = elements.slice(toolbarElements.length);
310
- toolbarElements.forEach(el => this._moveElement(el, true));
311
- menuElements.forEach(el => this._moveElement(el));
331
+ toolbarElements.forEach((el) => this._moveElement(el, true));
332
+ menuElements.forEach((el) => this._moveElement(el));
312
333
  this._setHasMenuItems(menuElements.length > 0);
313
334
  }
314
335
 
@@ -323,22 +344,30 @@ class CosmozBottomBar extends PolymerElement {
323
344
  }
324
345
 
325
346
  _onResize([entry]) {
326
- const hidden = entry.borderBoxSize?.[0]?.inlineSize === 0 || entry.contentRect?.width === 0;
347
+ const hidden =
348
+ entry.borderBoxSize?.[0]?.inlineSize === 0 ||
349
+ entry.contentRect?.width === 0;
327
350
  if (hidden) {
328
351
  return;
329
352
  }
330
353
  this._computedBarHeightKicker += 1;
331
354
  }
332
355
 
333
- _showHideBottomBar(visible) {
356
+ _showHideBottomBar(visible, renderOpen) {
334
357
  this.style.transitionDuration = 0;
335
358
  this.style.display = '';
336
359
  this.style.maxHeight = '';
337
360
 
338
361
  const height = this.computedBarHeight,
339
- from = visible ? '0px' : height + 'px',
340
362
  to = !visible ? '0px' : height + 'px';
341
363
 
364
+ let from = visible ? '0px' : height + 'px';
365
+
366
+ if (visible && renderOpen && !this[rendered]) {
367
+ from = to;
368
+ this[rendered] = true;
369
+ }
370
+
342
371
  this.style.maxHeight = from;
343
372
 
344
373
  const onEnd = () => {
@@ -362,6 +391,5 @@ const tmplt = `
362
391
  <slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
363
392
  `;
364
393
 
365
- export const
366
- bottomBarSlots = html([tmplt]),
367
- bottomBarSlotsPolymer = polymerHtml([tmplt]);
394
+ export const bottomBarSlots = html(Object.assign([tmplt], { raw: [tmplt] })),
395
+ bottomBarSlotsPolymer = polymerHtml(Object.assign([tmplt], { raw: [tmplt] }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-bottom-bar",
3
- "version": "5.1.1",
3
+ "version": "6.0.0-beta.1",
4
4
  "description": "A responsive bottom-bar that can house buttons/actions and a menu for the buttons that won't fit the available width.",
5
5
  "keywords": [
6
6
  "polymer",
@@ -51,16 +51,15 @@
51
51
  ]
52
52
  },
53
53
  "dependencies": {
54
- "@neovici/cosmoz-dropdown": "^1.1.0",
55
- "@polymer/polymer": "^3.3.1",
56
- "haunted": "^4.8.0",
57
- "lit-html": "^1.4.0"
54
+ "@neovici/cosmoz-dropdown": "^2.0.0-beta.1",
55
+ "@polymer/polymer": "^3.3.0",
56
+ "lit-html": "^2.0.0"
58
57
  },
59
58
  "devDependencies": {
60
- "@commitlint/cli": "^16.0.0",
61
- "@commitlint/config-conventional": "^16.0.0",
59
+ "@commitlint/cli": "^17.0.0",
60
+ "@commitlint/config-conventional": "^17.0.0",
62
61
  "@neovici/cfg": "^1.13.0",
63
- "@open-wc/testing": "^2.5.0",
62
+ "@open-wc/testing": "^3.0.0",
64
63
  "@polymer/iron-icon": "^3.0.1",
65
64
  "@polymer/iron-icons": "^3.0.1",
66
65
  "@polymer/paper-button": "^3.0.0",
@@ -70,8 +69,8 @@
70
69
  "@web/dev-server": "^0.1.0",
71
70
  "@web/test-runner": "^0.13.0",
72
71
  "@webcomponents/webcomponentsjs": "^2.5.0",
73
- "husky": "^7.0.0",
72
+ "husky": "^8.0.0",
74
73
  "semantic-release": "^19.0.0",
75
- "sinon": "^13.0.0"
74
+ "sinon": "^14.0.0"
76
75
  }
77
76
  }