@micromag/element-scroll 0.3.767 → 0.3.771
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/es/index.js +22 -1
- package/package.json +3 -3
package/es/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
4
|
import { useScroll } from '@use-gesture/react';
|
|
4
5
|
import classNames from 'classnames';
|
|
5
6
|
import PropTypes from 'prop-types';
|
|
6
|
-
import React, {
|
|
7
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
7
8
|
import { useDimensionObserver } from '@micromag/core/hooks';
|
|
8
9
|
|
|
9
10
|
var styles = {"container":"micromag-element-scroll-container","scrollable":"micromag-element-scroll-scrollable","arrowContainer":"micromag-element-scroll-arrowContainer","arrow":"micromag-element-scroll-arrow","upAndDown":"micromag-element-scroll-upAndDown","withScroll":"micromag-element-scroll-withScroll","withArrow":"micromag-element-scroll-withArrow","withShadow":"micromag-element-scroll-withShadow","top":"micromag-element-scroll-top","scrollee":"micromag-element-scroll-scrollee","middle":"micromag-element-scroll-middle","bottom":"micromag-element-scroll-bottom","disabled":"micromag-element-scroll-disabled"};
|
|
@@ -18,6 +19,8 @@ var propTypes = {
|
|
|
18
19
|
scrolleeClassName: PropTypes.string,
|
|
19
20
|
children: PropTypes.node,
|
|
20
21
|
scrollPosition: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
22
|
+
triggers: PropTypes.arrayOf(PropTypes.number),
|
|
23
|
+
onScrolledTrigger: PropTypes.func,
|
|
21
24
|
onScrolledBottom: PropTypes.func,
|
|
22
25
|
onScrolledNotBottom: PropTypes.func,
|
|
23
26
|
onScrollHeightChange: PropTypes.func,
|
|
@@ -36,6 +39,8 @@ var defaultProps = {
|
|
|
36
39
|
scrolleeClassName: null,
|
|
37
40
|
children: null,
|
|
38
41
|
scrollPosition: null,
|
|
42
|
+
triggers: [0.1, 0.25, 0.5, 0.75, 0.9, 1.0],
|
|
43
|
+
onScrolledTrigger: null,
|
|
39
44
|
onScrolledBottom: null,
|
|
40
45
|
onScrolledNotBottom: null,
|
|
41
46
|
onScrollHeightChange: null,
|
|
@@ -53,6 +58,8 @@ function Scroll(_ref) {
|
|
|
53
58
|
scrolleeClassName = _ref.scrolleeClassName,
|
|
54
59
|
children = _ref.children,
|
|
55
60
|
scrollPosition = _ref.scrollPosition,
|
|
61
|
+
triggers = _ref.triggers,
|
|
62
|
+
onScrolledTrigger = _ref.onScrolledTrigger,
|
|
56
63
|
onScrolledBottom = _ref.onScrolledBottom,
|
|
57
64
|
onScrolledNotBottom = _ref.onScrolledNotBottom,
|
|
58
65
|
onScrollHeightChange = _ref.onScrollHeightChange,
|
|
@@ -63,6 +70,7 @@ function Scroll(_ref) {
|
|
|
63
70
|
width: width,
|
|
64
71
|
height: height
|
|
65
72
|
};
|
|
73
|
+
var triggersCompletedRef = useRef([]);
|
|
66
74
|
var _useState = useState(false),
|
|
67
75
|
_useState2 = _slicedToArray(_useState, 2),
|
|
68
76
|
withArrow = _useState2[0],
|
|
@@ -85,6 +93,19 @@ function Scroll(_ref) {
|
|
|
85
93
|
var newWithArrow = scrollY <= 1;
|
|
86
94
|
var maxScrollAmount = scrolleeHeight - scrollableHeight;
|
|
87
95
|
var nowReachedBottom = scrollY + 1 >= maxScrollAmount;
|
|
96
|
+
var progress = Math.min(Math.max((scrollY + 1) / maxScrollAmount, 0), 1);
|
|
97
|
+
var newTriggersCompleted = (triggers || []).filter(function (step) {
|
|
98
|
+
return progress >= step && triggersCompletedRef.current.indexOf(step) === -1;
|
|
99
|
+
});
|
|
100
|
+
newTriggersCompleted.forEach(function (step) {
|
|
101
|
+
if (onScrolledTrigger != null) {
|
|
102
|
+
// console.log('call me', step, progress);
|
|
103
|
+
onScrolledTrigger(step);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (newTriggersCompleted.length > 0) {
|
|
107
|
+
triggersCompletedRef.current = [].concat(_toConsumableArray(triggersCompletedRef.current), _toConsumableArray(newTriggersCompleted));
|
|
108
|
+
}
|
|
88
109
|
if (nowReachedBottom) {
|
|
89
110
|
if (!reachedBottom.current) {
|
|
90
111
|
if (onScrolledBottom !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-scroll",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.771",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@babel/runtime": "^7.13.10",
|
|
62
|
-
"@micromag/core": "^0.3.
|
|
62
|
+
"@micromag/core": "^0.3.769",
|
|
63
63
|
"@use-gesture/react": "^10.3.0",
|
|
64
64
|
"classnames": "^2.2.6",
|
|
65
65
|
"lodash": "^4.17.21",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"access": "public",
|
|
72
72
|
"registry": "https://registry.npmjs.org/"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "a74bf984979f2bee58b57859808a8d9f6fa31f4a"
|
|
75
75
|
}
|