@neovici/cosmoz-bottom-bar 4.0.5 → 4.2.0

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,12 +1,8 @@
1
1
  import { component } from 'haunted';
2
2
  import { html } from 'lit-html';
3
3
  import { ifDefined } from 'lit-html/directives/if-defined';
4
- import { ref } from '@neovici/cosmoz-utils/lib/directives/ref';
5
- import { useBottomBarView } from './lib/use-bottom-bar-view';
6
4
  import { bottomBarSlots } from './cosmoz-bottom-bar';
7
5
 
8
-
9
-
10
6
  /**
11
7
  * `cosmoz-bottom-bar-view` contains a content section and a bottom bar with actions.
12
8
  *
@@ -18,49 +14,41 @@ import { bottomBarSlots } from './cosmoz-bottom-bar';
18
14
  */
19
15
 
20
16
  const CosmozBottomBarView = ({
21
- barHeight,
22
- ...pass
23
- }) => { /*eslint-disable no-return-assign */
24
- const {
25
- active,
26
- info
27
- } = useBottomBarView(pass);
28
-
29
- return html`
30
- <style>
31
- :host {
32
- position: relative;
33
- display: flex;
34
- flex-direction: column;
35
- flex: var(--cosmoz-bottom-bar-view-flex, auto);
36
- overflow: hidden;
37
- }
38
-
39
- #content {
40
- display: flex;
41
- flex-direction: column;
42
- flex: auto;
43
- -webkit-overflow-scrolling: touch;
44
- overflow-y: auto;
45
- }
46
-
47
- #bar {
48
- background-color: var(--cosmoz-bottom-bar-view-bar-color, rgba(230, 230, 230, 0.8));
49
- box-shadow: var(--cosmoz-bottom-bar-view-bar-shadow, none);
50
- position: static;
51
- flex: none;
52
- }
53
- </style>
54
- <div id="content" part="content">
55
- ${ ref(info) }
56
- <slot name="content"></slot>
57
- <slot name="scroller-content"></slot>
58
- </div>
59
- <cosmoz-bottom-bar id="bar" ?active=${ active } bar-height=${ ifDefined(barHeight) } part="bar">
60
- <slot></slot>
61
- ${ bottomBarSlots }
62
- </cosmoz-bottom-bar>
63
- `;
64
- };
17
+ active = true,
18
+ barHeight
19
+ }) => html`
20
+ <style>
21
+ :host {
22
+ position: relative;
23
+ display: flex;
24
+ flex-direction: column;
25
+ flex: var(--cosmoz-bottom-bar-view-flex, auto);
26
+ overflow: hidden;
27
+ }
28
+
29
+ #content {
30
+ display: flex;
31
+ flex-direction: column;
32
+ flex: auto;
33
+ -webkit-overflow-scrolling: touch;
34
+ overflow-y: auto;
35
+ }
36
+
37
+ #bar {
38
+ background-color: var(--cosmoz-bottom-bar-view-bar-color, rgba(230, 230, 230, 0.8));
39
+ box-shadow: var(--cosmoz-bottom-bar-view-bar-shadow, none);
40
+ position: static;
41
+ flex: none;
42
+ }
43
+ </style>
44
+ <div id="content" part="content">
45
+ <slot name="content"></slot>
46
+ <slot name="scroller-content"></slot>
47
+ </div>
48
+ <cosmoz-bottom-bar id="bar" ?active=${ active } bar-height=${ ifDefined(barHeight) } part="bar">
49
+ <slot></slot>
50
+ ${ bottomBarSlots }
51
+ </cosmoz-bottom-bar>
52
+ `;
65
53
  customElements.define('cosmoz-bottom-bar-view', component(CosmozBottomBarView));
66
54
 
@@ -82,6 +82,9 @@ export default html`
82
82
 
83
83
  #dropdown {
84
84
  padding: 0;
85
+ --paper-menu-button-content: {
86
+ max-width: 300px !important;
87
+ };
85
88
  }
86
89
 
87
90
  /** Seems like a shady dom scoping/slotting issue */
@@ -92,11 +95,15 @@ export default html`
92
95
 
93
96
  #dropdown ::slotted(:not(slot)) {
94
97
  position: relative;
98
+ cursor: pointer;
95
99
  @apply --cosmoz-bottom-bar-menu-item;
96
100
  }
101
+ #dropdown ::slotted(:not(slot):hover) {
102
+ background: #eee;
103
+ }
97
104
  </style>
98
105
 
99
- <div id="bar" style$="[[ _getHeightStyle(computedBarHeight) ]]">
106
+ <div id="bar" style$="[[ _getHeightStyle(computedBarHeight) ]]" part="bar">
100
107
  <div id="info">
101
108
  <slot name="info"></slot>
102
109
  </div>
@@ -10,9 +10,7 @@ import { html } from 'haunted';
10
10
 
11
11
  const
12
12
  BOTTOM_BAR_TOOLBAR_SLOT = 'bottom-bar-toolbar',
13
- BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu',
14
-
15
- slotEq = slot => element => element.getAttribute('slot') === slot;
13
+ BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu';
16
14
 
17
15
  /**
18
16
  * `<cosmoz-bottom-bar>` is a horizontal responsive bottom toolbar containing items that
@@ -183,14 +181,14 @@ class CosmozBottomBar extends PolymerElement {
183
181
 
184
182
  this.addEventListener('iron-closed-overlay', this._boundDropdownClosed);
185
183
 
186
- this._hiddenMutationObserver = new MutationObserver(() => {
187
- this._overflowWidth = undefined;
188
- this._debounceLayoutActions();
189
- });
190
- this._nodeObserver = new FlattenedNodesObserver(this.$.content, this._boundChildrenUpdated);
191
- this._nodeObserverExtra = new FlattenedNodesObserver(this.$.extraSlot, info =>
192
- this.set('hasExtraItems', info.addedNodes.length > 0)
193
- );
184
+ const layoutOnRemove = info => info.removedNodes.filter(this._isActionNode) && this._debounceLayoutActions();
185
+ this._nodeObservers = [
186
+ new FlattenedNodesObserver(this.$.content, this._boundChildrenUpdated),
187
+ new FlattenedNodesObserver(this.$.extraSlot, info => this.set('hasExtraItems', info.addedNodes.length > 0)),
188
+ new FlattenedNodesObserver(this.$.bottomBarToolbar, layoutOnRemove),
189
+ new FlattenedNodesObserver(this.$.bottomBarMenu, layoutOnRemove)
190
+ ];
191
+ this._hiddenMutationObserver = new MutationObserver(() => this._debounceLayoutActions());
194
192
  this._resizeObserver.observe(this);
195
193
  this._computedBarHeightKicker = 0;
196
194
  }
@@ -199,34 +197,19 @@ class CosmozBottomBar extends PolymerElement {
199
197
  super.disconnectedCallback();
200
198
 
201
199
  this.removeEventListener('iron-closed-overlay', this._boundDropdownClosed);
202
-
203
- this._nodeObserver.disconnect();
204
- this._nodeObserverExtra.disconnect();
205
- this._hiddenMutationObserver.disconnect();
200
+ [...this._nodeObservers, this._hiddenMutationObserver].forEach(e => e.disconnect(e));
206
201
  this._layoutDebouncer?.cancel(); /* eslint-disable-line no-unused-expressions */
207
202
  this._resizeObserver.unobserve(this);
208
203
  }
209
204
 
210
- _canAddMoreButtonToBar(width, bottomBarElements, menuElements) {
211
- const hasSpace = width > this._overflowWidth || this._overflowWidth === undefined,
212
- hasPlace = bottomBarElements.length < this.maxToolbarItems,
213
- hasCandidates = menuElements.length > 0;
214
-
215
- return hasSpace && hasPlace && hasCandidates;
216
- }
217
-
218
205
  _childrenUpdated(info) {
219
206
  const addedNodes = info.addedNodes.filter(this._isActionNode),
220
207
  removedNodes = info.removedNodes.filter(this._isActionNode),
221
208
  newNodes = addedNodes.filter(node => !removedNodes.includes(node));
222
209
 
223
- if (addedNodes.length === 0 && removedNodes.length === 0) {
210
+ if (addedNodes.length === 0 && removedNodes.length === 0 || newNodes.length === 0) {
224
211
  return;
225
212
  }
226
- if (newNodes.length === 0) {
227
- return;
228
- }
229
-
230
213
  newNodes.forEach(node => {
231
214
  this._hiddenMutationObserver.observe(node, {
232
215
  attributes: true,
@@ -235,20 +218,10 @@ class CosmozBottomBar extends PolymerElement {
235
218
  this._moveElement(node, false);
236
219
  });
237
220
 
238
- const toolbarElements = this._getElements().filter(slotEq(BOTTOM_BAR_TOOLBAR_SLOT)),
239
- toolbarCount = this.maxToolbarItems - toolbarElements.length;
240
-
241
- if (toolbarCount > 0) {
242
- newNodes
243
- .filter(node => !node.hidden).slice(0, toolbarCount)
244
- .forEach(node => this._moveElement(node, true));
245
- }
246
-
247
221
  this._debounceLayoutActions();
248
222
  }
249
223
 
250
- // eslint-disable-next-line no-unused-vars
251
- _computeComputedBarHeight(matchElementHeight, barHeight, kicker) {
224
+ _computeComputedBarHeight(matchElementHeight, barHeight) {
252
225
  if (matchElementHeight) {
253
226
  return matchElementHeight.offsetHeight;
254
227
  }
@@ -272,12 +245,7 @@ class CosmozBottomBar extends PolymerElement {
272
245
  }
273
246
 
274
247
  _fireAction(item) {
275
-
276
- if (!item || !item.dispatchEvent) {
277
- return;
278
- }
279
-
280
- item.dispatchEvent(new window.CustomEvent('action', {
248
+ item?.dispatchEvent?.(new window.CustomEvent('action', {
281
249
  bubbles: true,
282
250
  cancelable: true,
283
251
  detail: {
@@ -311,7 +279,8 @@ class CosmozBottomBar extends PolymerElement {
311
279
  _getElements() {
312
280
  return FlattenedNodesObserver.getFlattenedNodes(this)
313
281
  .filter(this._isActionNode)
314
- .filter(element => !element.hidden);
282
+ .filter(element => !element.hidden)
283
+ .sort((a, b) => a.dataset.index - b.dataset.index);
315
284
  }
316
285
  /**
317
286
  * Layout the actions available as buttons or menu items
@@ -335,56 +304,20 @@ class CosmozBottomBar extends PolymerElement {
335
304
  */
336
305
  _layoutActions() { // eslint-disable-line max-statements
337
306
  const elements = this._getElements(),
338
- toolbar = this.$.toolbar;
339
-
340
- let fits,
341
- newToolbarElement;
307
+ hasActions = elements.length > 0 || this.hasExtraItems;
308
+ this._setHasActions(hasActions);
342
309
 
343
- this._setHasActions(elements.length > 0 || this.hasExtraItems);
344
- if (!this.hasActions) {
310
+ if (!hasActions) {
345
311
  // No need to render if we don't have any actions
346
- return;
312
+ return this._setHasMenuItems(false);
347
313
  }
348
314
 
349
- const currentWidth = toolbar.clientWidth;
350
- fits = toolbar.scrollWidth <= currentWidth + 1;
351
-
352
- const toolbarElements = elements.filter(slotEq(BOTTOM_BAR_TOOLBAR_SLOT)),
353
- menuElements = elements.filter(slotEq(BOTTOM_BAR_MENU_SLOT));
354
-
315
+ const toolbarElements = elements.slice(0, this.maxToolbarItems),
316
+ menuElements = elements.slice(toolbarElements.length);
317
+ toolbarElements.forEach(el => this._moveElement(el, true));
318
+ menuElements.forEach(el => this._moveElement(el));
355
319
  this._setHasMenuItems(menuElements.length > 0);
356
-
357
- fits = fits && toolbarElements.length <= this.maxToolbarItems;
358
- fits = fits && toolbarElements.every(element => element.scrollWidth <= element.clientWidth);
359
-
360
-
361
- if (fits) {
362
- if (this._canAddMoreButtonToBar(currentWidth, toolbarElements, menuElements)) {
363
- newToolbarElement = menuElements[0];
364
- this._moveElement(newToolbarElement, true);
365
- // (pasleq) If we are moving the focused element from the menu to the toolbar
366
- // while the toolbar is open, this will cause an error in iron-control-state
367
- // that tries to handle lost of focus on an element that has been removed.
368
- if (toolbarElements.length > 0) {
369
- toolbarElements[0].focus();
370
- } else {
371
- newToolbarElement.focus();
372
- }
373
- this.$.menu.close();
374
- this._debounceLayoutActions();
375
- }
376
- return;
377
- }
378
-
379
- this._overflowWidth = currentWidth;
380
-
381
- if (toolbarElements.length < 1) {
382
- return;
383
- }
384
-
385
- const newMenuElement = toolbarElements[toolbarElements.length - 1];
386
- this._moveElement(newMenuElement, false);
387
- this._debounceLayoutActions();
320
+ this.$.menu.$.dropdown.notifyResize();
388
321
  }
389
322
 
390
323
  _moveElement(element, toToolbar) {
@@ -408,7 +341,6 @@ class CosmozBottomBar extends PolymerElement {
408
341
  return;
409
342
  }
410
343
  this._computedBarHeightKicker += 1;
411
- this._debounceLayoutActions();
412
344
  }
413
345
 
414
346
  _showHideBottomBar(visible) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-bottom-bar",
3
- "version": "4.0.5",
3
+ "version": "4.2.0",
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",
@@ -26,12 +26,10 @@
26
26
  ],
27
27
  "scripts": {
28
28
  "lint": "eslint --cache --ext .js .",
29
- "start": "es-dev-server",
30
- "test": "karma start --coverage",
31
- "test:watch": "karma start --auto-watch=true --single-run=false",
32
- "test:update-snapshots": "karma start --update-snapshots",
33
- "test:prune-snapshots": "karma start --prune-snapshots",
34
- "test:compatibility": "karma start --compatibility all --auto-watch=true --single-run=false"
29
+ "start": "wds",
30
+ "test": "wtr --coverage",
31
+ "test:watch": "wtr --watch",
32
+ "prepare": "husky install"
35
33
  },
36
34
  "release": {
37
35
  "plugins": [
@@ -52,14 +50,8 @@
52
50
  "@commitlint/config-conventional"
53
51
  ]
54
52
  },
55
- "husky": {
56
- "hooks": {
57
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
58
- }
59
- },
60
53
  "dependencies": {
61
- "@neovici/cosmoz-utils": "^3.12.0",
62
- "@neovici/cosmoz-viewinfo": "^3.1.3",
54
+ "@neovici/cosmoz-utils": "^3.21.0",
63
55
  "@polymer/iron-icons": "^3.0.1",
64
56
  "@polymer/iron-selector": "^3.0.0",
65
57
  "@polymer/paper-icon-button": "^3.0.0",
@@ -67,29 +59,25 @@
67
59
  "@polymer/paper-menu-button": "^3.0.0",
68
60
  "@polymer/polymer": "^3.3.1",
69
61
  "@webcomponents/shadycss": "^1.10.2",
70
- "haunted": "^4.7.0",
71
- "lit-html": "^1.2.1"
62
+ "haunted": "^4.8.0",
63
+ "lit-html": "^1.4.0"
72
64
  },
73
65
  "devDependencies": {
74
- "@commitlint/cli": "^11.0.0",
75
- "@commitlint/config-conventional": "^11.0.0",
66
+ "@commitlint/cli": "^15.0.0",
67
+ "@commitlint/config-conventional": "^15.0.0",
76
68
  "@neovici/eslint-config": "^1.3.0",
77
- "@open-wc/testing": "^2.5.29",
78
- "@open-wc/testing-karma": "^3.3.12",
69
+ "@open-wc/testing": "^2.5.0",
79
70
  "@polymer/iron-icon": "^3.0.1",
80
71
  "@polymer/paper-button": "^3.0.0",
81
72
  "@polymer/paper-toggle-button": "^3.0.0",
82
- "@semantic-release/changelog": "^5.0.1",
83
- "@semantic-release/git": "^9.0.0",
73
+ "@semantic-release/changelog": "^6.0.0",
74
+ "@semantic-release/git": "^10.0.0",
75
+ "@web/dev-server": "^0.1.0",
76
+ "@web/test-runner": "^0.13.0",
77
+ "@web/test-runner-selenium": "^0.5.0",
84
78
  "@webcomponents/webcomponentsjs": "^2.5.0",
85
- "deepmerge": "^4.2.2",
86
- "es-dev-server": "^1.57.8",
87
- "eslint": "^6.8.0",
88
- "husky": "^4.2.5",
89
- "karma": "^5.0.1",
90
- "karma-firefox-launcher": "^1.3.0",
91
- "karma-sauce-launcher": "^4.1.6",
92
- "semantic-release": "^17.2.3",
93
- "sinon": "^9.2.0"
79
+ "husky": "^7.0.0",
80
+ "semantic-release": "^18.0.0",
81
+ "sinon": "^12.0.0"
94
82
  }
95
83
  }
package/CHANGELOG.md DELETED
@@ -1,128 +0,0 @@
1
- ## [4.0.5](https://github.com/neovici/cosmoz-bottom-bar/compare/v4.0.4...v4.0.5) (2021-01-15)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * **cosmoz-bottom-bar:** ignore style elements ([b5330e9](https://github.com/neovici/cosmoz-bottom-bar/commit/b5330e9583eb9a2b6044e47a46d20615b8829d4c))
7
-
8
- ## [4.0.4](https://github.com/neovici/cosmoz-bottom-bar/compare/v4.0.3...v4.0.4) (2020-10-20)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * do not style slotted slots on Safari/iOS ([ee653c8](https://github.com/neovici/cosmoz-bottom-bar/commit/ee653c878a41ac400906262bb5a6e7e26e24027e))
14
-
15
- ## [4.0.3](https://github.com/neovici/cosmoz-bottom-bar/compare/v4.0.2...v4.0.3) (2020-10-15)
16
-
17
-
18
- ### Bug Fixes
19
-
20
- * don't recompute height ([7b52e06](https://github.com/neovici/cosmoz-bottom-bar/commit/7b52e068ed4e17cd3ac5259da5f09fce11237033))
21
- * restore cosmoz-bottom-bar-view animation behavior ([cf04651](https://github.com/neovici/cosmoz-bottom-bar/commit/cf04651f70a188bf99e80181402dd751684880f2))
22
-
23
- ## [4.0.2](https://github.com/neovici/cosmoz-bottom-bar/compare/v4.0.1...v4.0.2) (2020-10-15)
24
-
25
-
26
- ### Bug Fixes
27
-
28
- * disabled buttons in the menu are not styled ([3a0cf4a](https://github.com/neovici/cosmoz-bottom-bar/commit/3a0cf4a23a57c28152b30ae0ac8afead1a0da82b))
29
-
30
- ## [4.0.1](https://github.com/neovici/cosmoz-bottom-bar/compare/v4.0.0...v4.0.1) (2020-10-15)
31
-
32
-
33
- ### Bug Fixes
34
-
35
- * prevent resize observer loops ([7994a7f](https://github.com/neovici/cosmoz-bottom-bar/commit/7994a7f827e601e6ffbb18c7096e03af224dc098))
36
-
37
- # [4.0.0](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.1.5...v4.0.0) (2020-10-15)
38
-
39
-
40
- ### Features
41
-
42
- * distribute via slots ([ea66679](https://github.com/neovici/cosmoz-bottom-bar/commit/ea66679776135abef30f06b7917a5a131717aa7c)), closes [#24802](https://github.com/neovici/cosmoz-bottom-bar/issues/24802)
43
-
44
-
45
- ### BREAKING CHANGES
46
-
47
- * If your component allows adding content to the bottom bar via slots, then you have
48
- to also make sure you also export `bottom-bar-toolbar` and `bottom-bar-menu`, otherwise the actions
49
- will not show up.
50
-
51
- ## [3.1.5](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.1.4...v3.1.5) (2020-10-12)
52
-
53
-
54
- ### Bug Fixes
55
-
56
- * always run layout actions on resize ([f95925c](https://github.com/neovici/cosmoz-bottom-bar/commit/f95925ccf27c73765cb13a6f22fc1e6c84c0818e))
57
-
58
- ## [3.1.4](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.1.3...v3.1.4) (2020-10-02)
59
-
60
-
61
- ### Bug Fixes
62
-
63
- * remove iron-flex-layout from demos ([44faf8d](https://github.com/neovici/cosmoz-bottom-bar/commit/44faf8d5345a536d6de93437242881946a56002f))
64
- * replace iron-resizable-behavior with a ResizeObserver ([69b0c60](https://github.com/neovici/cosmoz-bottom-bar/commit/69b0c60c1fcbce542f3eb515f1fe34716d1df310)), closes [#83](https://github.com/neovici/cosmoz-bottom-bar/issues/83)
65
-
66
- ## [3.1.3](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.1.2...v3.1.3) (2020-08-24)
67
-
68
-
69
- ### Bug Fixes
70
-
71
- * undefined layoutDebouncer ([46a46e0](https://github.com/neovici/cosmoz-bottom-bar/commit/46a46e062f772b1312ddf7e3ef44686d1feee35d))
72
-
73
- ## [3.1.2](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.1.1...v3.1.2) (2020-08-20)
74
-
75
-
76
- ### Bug Fixes
77
-
78
- * on desktop bb remains inactive, if not explicitly made active ([956b9b2](https://github.com/neovici/cosmoz-bottom-bar/commit/956b9b2d7f44c927aa06a07a7e375e4afff0a514))
79
-
80
- ## [3.1.1](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.1.0...v3.1.1) (2020-08-19)
81
-
82
-
83
- ### Bug Fixes
84
-
85
- * remove iron-flex-layout ([2664d51](https://github.com/neovici/cosmoz-bottom-bar/commit/2664d5115eaacc966b4e9cfa7882b86ed196e0cd))
86
-
87
- # [3.1.0](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.0.11...v3.1.0) (2020-08-14)
88
-
89
-
90
- ### Features
91
-
92
- * convert cosmoz-bottom-bar-view to haunted ([6b4c674](https://github.com/neovici/cosmoz-bottom-bar/commit/6b4c6743c209a6fb81ce573638d40c075a925c41)), closes [#74](https://github.com/neovici/cosmoz-bottom-bar/issues/74)
93
-
94
- ## [3.0.11](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.0.10...v3.0.11) (2020-06-23)
95
-
96
-
97
- ### Bug Fixes
98
-
99
- * better hidden element handling ([3184992](https://github.com/neovici/cosmoz-bottom-bar/commit/3184992dad82951881eab58ec60c1019cdeec9a6))
100
- * improve initial distribution of toolbar elements ([f195cfb](https://github.com/neovici/cosmoz-bottom-bar/commit/f195cfb6c33d5d8110e8dc3362350767e932600c))
101
-
102
- ## [3.0.10](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.0.9...v3.0.10) (2020-01-13)
103
-
104
-
105
- ### Bug Fixes
106
-
107
- * reduce max toolbar items from 3 to 1 ([#70](https://github.com/neovici/cosmoz-bottom-bar/issues/70)) ([ae3a781](https://github.com/neovici/cosmoz-bottom-bar/commit/ae3a781))
108
-
109
- ## [3.0.9](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.0.8...v3.0.9) (2020-01-10)
110
-
111
-
112
- ### Bug Fixes
113
-
114
- * correct package version ([9132345](https://github.com/neovici/cosmoz-bottom-bar/commit/9132345))
115
-
116
- ## [3.0.5](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.0.4...v3.0.5) (2019-10-10)
117
-
118
-
119
- ### Bug Fixes
120
-
121
- * **readme:** missing badges ([5217901](https://github.com/neovici/cosmoz-bottom-bar/commit/5217901))
122
-
123
- ## [3.0.4](https://github.com/neovici/cosmoz-bottom-bar/compare/v3.0.3...v3.0.4) (2019-10-08)
124
-
125
-
126
- ### Bug Fixes
127
-
128
- * **ci:** adopt semantic release ([1e5240f](https://github.com/neovici/cosmoz-bottom-bar/commit/1e5240f))
@@ -1,62 +0,0 @@
1
- import {
2
- useEffect,
3
- useState,
4
- useMemo
5
- } from 'haunted';
6
- import { useViewInfo } from '@neovici/cosmoz-viewinfo';
7
-
8
- const useBottomBarView = ({
9
- active: initialActive = true,
10
- fixed
11
- }) => { /* eslint-disable no-return-assign */
12
- const { desktop } = useViewInfo(),
13
- isFixed = fixed ?? desktop,
14
- [active, setActive] = useState(initialActive),
15
- info = useMemo(() => ({}), []);
16
-
17
- useEffect(() => {
18
- if (isFixed) {
19
- return;
20
- }
21
- const
22
- { current: el } = info,
23
- opts = { passive: true },
24
- onScroll = () => {
25
- if (info.raf) {
26
- cancelAnimationFrame(info.raf);
27
- }
28
- info.raf = requestAnimationFrame(() => info.raf = requestAnimationFrame(() => {
29
- const { scrollTop } = el;
30
- setActive(
31
- scrollTop < 2 // at top
32
- || info.scrollTop > scrollTop // scrolling up
33
- || el.scrollHeight - scrollTop - el.offsetHeight < 3 // at bottom
34
- );
35
- Object.assign(info, {
36
- scrollTop,
37
- raf: undefined
38
- });
39
- }));
40
- };
41
- el.addEventListener('scroll', onScroll, opts);
42
- onScroll();
43
- return () => {
44
- el.removeEventListener('scroll', onScroll, opts);
45
- if (info.raf) {
46
- cancelAnimationFrame(info.raf);
47
- info.raf = undefined;
48
- }
49
- };
50
- }, [isFixed, info]);
51
-
52
- useEffect(() => {
53
- setActive(initialActive);
54
- }, [initialActive, setActive]);
55
-
56
- return {
57
- active,
58
- info
59
- };
60
- };
61
-
62
- export { useBottomBarView };