@neovici/cosmoz-bottom-bar 7.4.0 → 7.5.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.
- package/cosmoz-bottom-bar.js +43 -11
- package/package.json +2 -2
package/cosmoz-bottom-bar.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
1
|
import {
|
|
3
2
|
PolymerElement,
|
|
4
3
|
html as polymerHtml,
|
|
@@ -7,6 +6,8 @@ import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nod
|
|
|
7
6
|
import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
|
|
8
7
|
import { timeOut } from '@polymer/polymer/lib/utils/async';
|
|
9
8
|
import { html } from 'lit-html';
|
|
9
|
+
import { hauntedPolymer } from '@neovici/cosmoz-utils';
|
|
10
|
+
import { useActivity } from '@neovici/cosmoz-utils/keybindings/use-activity';
|
|
10
11
|
import { defaultPlacement } from '@neovici/cosmoz-dropdown';
|
|
11
12
|
import template from './cosmoz-bottom-bar.html.js';
|
|
12
13
|
|
|
@@ -14,6 +15,31 @@ const BOTTOM_BAR_TOOLBAR_SLOT = 'bottom-bar-toolbar',
|
|
|
14
15
|
BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu',
|
|
15
16
|
rendered = Symbol('rendered');
|
|
16
17
|
|
|
18
|
+
export const openMenu = Symbol('openMenu');
|
|
19
|
+
|
|
20
|
+
const openActionsMenu = (host) => {
|
|
21
|
+
const dropdown = host.$.dropdown;
|
|
22
|
+
|
|
23
|
+
if (dropdown.hasAttribute('hidden')) return;
|
|
24
|
+
|
|
25
|
+
//TODO: Clean up when open function is implemented for cosmoz-dropdown-menu
|
|
26
|
+
dropdown.shadowRoot
|
|
27
|
+
.querySelector('cosmoz-dropdown')
|
|
28
|
+
.shadowRoot.getElementById('dropdownButton')
|
|
29
|
+
.click();
|
|
30
|
+
},
|
|
31
|
+
useBottomBar = (host) => {
|
|
32
|
+
useActivity(
|
|
33
|
+
{
|
|
34
|
+
activity: openMenu,
|
|
35
|
+
callback: () => openActionsMenu(host),
|
|
36
|
+
check: () => host.active && !host.hasAttribute('hide-actions'),
|
|
37
|
+
element: () => host.$.dropdown,
|
|
38
|
+
},
|
|
39
|
+
[host.active],
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
17
43
|
/**
|
|
18
44
|
* `<cosmoz-bottom-bar>` is a horizontal responsive bottom toolbar containing items that
|
|
19
45
|
* can be used for actions.
|
|
@@ -34,13 +60,11 @@ const BOTTOM_BAR_TOOLBAR_SLOT = 'bottom-bar-toolbar',
|
|
|
34
60
|
* @demo demo/bottom-bar.html Basic Demo
|
|
35
61
|
* @demo demo/bottom-bar-match-parent.html match parent Demo
|
|
36
62
|
*/
|
|
37
|
-
class CosmozBottomBar extends PolymerElement {
|
|
63
|
+
class CosmozBottomBar extends hauntedPolymer(useBottomBar)(PolymerElement) {
|
|
38
64
|
static get template() {
|
|
39
|
-
// eslint-disable-line max-lines-per-function
|
|
40
65
|
return template;
|
|
41
66
|
}
|
|
42
67
|
|
|
43
|
-
// eslint-disable-next-line max-lines-per-function
|
|
44
68
|
static get properties() {
|
|
45
69
|
return {
|
|
46
70
|
/**
|
|
@@ -214,7 +238,7 @@ class CosmozBottomBar extends PolymerElement {
|
|
|
214
238
|
[...this._nodeObservers, this._hiddenMutationObserver].forEach((e) =>
|
|
215
239
|
e.disconnect(e),
|
|
216
240
|
);
|
|
217
|
-
this._layoutDebouncer?.cancel();
|
|
241
|
+
this._layoutDebouncer?.cancel();
|
|
218
242
|
this._resizeObserver.unobserve(this);
|
|
219
243
|
}
|
|
220
244
|
|
|
@@ -309,6 +333,18 @@ class CosmozBottomBar extends PolymerElement {
|
|
|
309
333
|
...elements.filter((e) => e !== topPriorityAction),
|
|
310
334
|
];
|
|
311
335
|
}
|
|
336
|
+
|
|
337
|
+
_distribute(hostWidth) {
|
|
338
|
+
const elements = this._getElements();
|
|
339
|
+
|
|
340
|
+
const tooNarrow = hostWidth <= 480,
|
|
341
|
+
toolbarElements = elements.slice(0, tooNarrow ? 0 : this.maxToolbarItems),
|
|
342
|
+
menuElements = elements.slice(toolbarElements.length);
|
|
343
|
+
toolbarElements.forEach((el) => this._moveElement(el, true));
|
|
344
|
+
menuElements.forEach((el) => this._moveElement(el));
|
|
345
|
+
this._setHasMenuItems(menuElements.length > 0);
|
|
346
|
+
}
|
|
347
|
+
|
|
312
348
|
/**
|
|
313
349
|
* Layout the actions available as buttons or menu items
|
|
314
350
|
*
|
|
@@ -330,7 +366,6 @@ class CosmozBottomBar extends PolymerElement {
|
|
|
330
366
|
* @returns {void}
|
|
331
367
|
*/
|
|
332
368
|
_layoutActions() {
|
|
333
|
-
// eslint-disable-line max-statements
|
|
334
369
|
const elements = this._getElements(),
|
|
335
370
|
hasActions = elements.length > 0 || this.hasExtraItems;
|
|
336
371
|
this._setHasActions(hasActions);
|
|
@@ -340,11 +375,7 @@ class CosmozBottomBar extends PolymerElement {
|
|
|
340
375
|
return this._setHasMenuItems(false);
|
|
341
376
|
}
|
|
342
377
|
|
|
343
|
-
|
|
344
|
-
menuElements = elements.slice(toolbarElements.length);
|
|
345
|
-
toolbarElements.forEach((el) => this._moveElement(el, true));
|
|
346
|
-
menuElements.forEach((el) => this._moveElement(el));
|
|
347
|
-
this._setHasMenuItems(menuElements.length > 0);
|
|
378
|
+
this._distribute(this.getBoundingClientRect().width);
|
|
348
379
|
}
|
|
349
380
|
|
|
350
381
|
_moveElement(element, toToolbar) {
|
|
@@ -368,6 +399,7 @@ class CosmozBottomBar extends PolymerElement {
|
|
|
368
399
|
this._matchHeightElement,
|
|
369
400
|
this.barHeight,
|
|
370
401
|
);
|
|
402
|
+
this._distribute(entry.contentRect?.width);
|
|
371
403
|
}
|
|
372
404
|
|
|
373
405
|
_showHideBottomBar(visible) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-bottom-bar",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.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",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@neovici/cosmoz-collapse": "^1.5.0",
|
|
63
63
|
"@neovici/cosmoz-dropdown": "^4.0.0",
|
|
64
|
-
"@neovici/cosmoz-utils": "^6.
|
|
64
|
+
"@neovici/cosmoz-utils": "^6.13.1",
|
|
65
65
|
"@pionjs/pion": "^2.5.2",
|
|
66
66
|
"@polymer/polymer": "^3.3.0",
|
|
67
67
|
"lit-html": "^2.0.0 || ^3.0.0"
|