@lumx/react 4.11.0-next.3 → 4.11.0-next.5
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/index.d.ts +5 -1
- package/index.js +11 -4
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/utils/index.d.ts +4 -7
- package/utils/index.js +52 -38
- package/utils/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@floating-ui/react-dom": "^2.1.7",
|
|
10
|
-
"@lumx/core": "^4.11.0-next.
|
|
11
|
-
"@lumx/icons": "^4.11.0-next.
|
|
10
|
+
"@lumx/core": "^4.11.0-next.5",
|
|
11
|
+
"@lumx/icons": "^4.11.0-next.5",
|
|
12
12
|
"body-scroll-lock": "^3.1.5"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
@@ -100,6 +100,6 @@
|
|
|
100
100
|
"build:storybook": "storybook build"
|
|
101
101
|
},
|
|
102
102
|
"sideEffects": false,
|
|
103
|
-
"version": "4.11.0-next.
|
|
103
|
+
"version": "4.11.0-next.5",
|
|
104
104
|
"stableVersion": "4.10.0"
|
|
105
105
|
}
|
package/utils/index.d.ts
CHANGED
|
@@ -32,18 +32,15 @@ interface ClickAwayProviderProps extends ClickAwayParameters {
|
|
|
32
32
|
*/
|
|
33
33
|
declare const ClickAwayProvider: React.FC<ClickAwayProviderProps>;
|
|
34
34
|
|
|
35
|
-
type EventCallback = (evt?: Event) => void;
|
|
36
35
|
interface InfiniteScrollProps {
|
|
37
|
-
|
|
36
|
+
/** Callback when infinite scroll component is in view */
|
|
37
|
+
callback: (evt?: Event) => void;
|
|
38
|
+
/** Customize intersection observer option */
|
|
38
39
|
options?: IntersectionObserverInit;
|
|
39
40
|
}
|
|
41
|
+
|
|
40
42
|
/**
|
|
41
43
|
* Handles basic callback pattern by using intersection observers.
|
|
42
|
-
*
|
|
43
|
-
* @param {Function} callback The callback to execute once the element is in the viewport or is intersecting
|
|
44
|
-
* with its root element.
|
|
45
|
-
* @param {Object} options The set of options we want to set to the intersection observer.
|
|
46
|
-
* @return {Element} The Infinite scroll element.
|
|
47
44
|
*/
|
|
48
45
|
declare const InfiniteScroll: React__default.FC<InfiniteScrollProps>;
|
|
49
46
|
|
package/utils/index.js
CHANGED
|
@@ -10,15 +10,52 @@ import isNil from 'lodash/isNil.js';
|
|
|
10
10
|
import groupBy from 'lodash/groupBy.js';
|
|
11
11
|
import uniqueId from 'lodash/uniqueId.js';
|
|
12
12
|
|
|
13
|
-
// The error margin in px we want to have for triggering infinite scroll
|
|
14
|
-
const CLASSNAME = 'lumx-infinite-scroll-anchor';
|
|
15
13
|
/**
|
|
16
|
-
*
|
|
14
|
+
* Sets up an IntersectionObserver on the given element.
|
|
15
|
+
* Calls `callback` when at least one observed entry is intersecting.
|
|
16
|
+
* Returns a cleanup function that unobserves the element.
|
|
17
|
+
*/
|
|
18
|
+
function setupInfiniteScrollObserver(element, callback, options) {
|
|
19
|
+
const observer = new IntersectionObserver((entries = []) => {
|
|
20
|
+
const hasIntersection = entries.some(entry => entry.isIntersecting);
|
|
21
|
+
if (!hasIntersection) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
callback();
|
|
25
|
+
}, options);
|
|
26
|
+
observer.observe(element);
|
|
27
|
+
return () => {
|
|
28
|
+
observer.unobserve(element);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const INFINITE_SCROLL_CLASSNAME = 'lumx-infinite-scroll-anchor';
|
|
33
|
+
/**
|
|
34
|
+
* Framework-agnostic InfiniteScroll sentinel component.
|
|
35
|
+
*
|
|
36
|
+
* Renders a tiny invisible div that triggers a callback when it enters the viewport
|
|
37
|
+
* (or intersects its root element) via IntersectionObserver.
|
|
17
38
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
* The div has a small height (4px) to avoid issues when a browser zoom is applied,
|
|
40
|
+
* where a zero-height element might not trigger IntersectionObserver reliably.
|
|
41
|
+
*/
|
|
42
|
+
const InfiniteScroll$1 = ({
|
|
43
|
+
ref
|
|
44
|
+
}) =>
|
|
45
|
+
/*#__PURE__*/
|
|
46
|
+
// In order to avoid issues when a zoom is added to the browser, we add a small height to the div so that
|
|
47
|
+
// the intersection has a higher chance of working correctly.
|
|
48
|
+
jsx("div", {
|
|
49
|
+
ref: ref,
|
|
50
|
+
"aria-hidden": "true",
|
|
51
|
+
className: INFINITE_SCROLL_CLASSNAME,
|
|
52
|
+
style: {
|
|
53
|
+
height: '4px'
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Handles basic callback pattern by using intersection observers.
|
|
22
59
|
*/
|
|
23
60
|
const InfiniteScroll = ({
|
|
24
61
|
callback,
|
|
@@ -26,40 +63,17 @@ const InfiniteScroll = ({
|
|
|
26
63
|
}) => {
|
|
27
64
|
const elementRef = React__default.useRef(null);
|
|
28
65
|
useEffect(() => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
callback();
|
|
37
|
-
}, options);
|
|
38
|
-
const currentRef = elementRef.current;
|
|
39
|
-
if (elementRef && elementRef.current) {
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
observer.observe(elementRef.current);
|
|
66
|
+
const {
|
|
67
|
+
current: element
|
|
68
|
+
} = elementRef;
|
|
69
|
+
if (!element) {
|
|
70
|
+
return undefined;
|
|
43
71
|
}
|
|
44
|
-
return (
|
|
45
|
-
if (currentRef) {
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
observer.unobserve(currentRef);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
72
|
+
return setupInfiniteScrollObserver(element, callback, options);
|
|
51
73
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
74
|
}, [elementRef.current, callback]);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// the intersection has a higher chance of working correctly.
|
|
56
|
-
return /*#__PURE__*/jsx("div", {
|
|
57
|
-
ref: elementRef,
|
|
58
|
-
"aria-hidden": "true",
|
|
59
|
-
className: CLASSNAME,
|
|
60
|
-
style: {
|
|
61
|
-
height: '4px'
|
|
62
|
-
}
|
|
75
|
+
return InfiniteScroll$1({
|
|
76
|
+
ref: elementRef
|
|
63
77
|
});
|
|
64
78
|
};
|
|
65
79
|
|