@lumx/react 2.0.1-alpha.0 → 2.0.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.
|
@@ -4,6 +4,8 @@ import { i as isComponent } from './type.js';
|
|
|
4
4
|
import { a as Popover, P as Placement } from './Popover2.js';
|
|
5
5
|
import { L as List } from './List2.js';
|
|
6
6
|
|
|
7
|
+
// The error margin in px we want to have for triggering infinite scroll
|
|
8
|
+
var SCROLL_TRIGGER_MARGIN = 5;
|
|
7
9
|
/**
|
|
8
10
|
* Listen to clicks away from a given element and callback the passed in function.
|
|
9
11
|
*
|
|
@@ -11,8 +13,10 @@ import { L as List } from './List2.js';
|
|
|
11
13
|
* @param [callback] A callback function to call when the bottom of the reference element is reached.
|
|
12
14
|
* @param [callbackOnMount] A callback function to call when the component is mounted.
|
|
13
15
|
*/
|
|
16
|
+
|
|
14
17
|
var useInfiniteScroll = function useInfiniteScroll(ref, callback) {
|
|
15
18
|
var callbackOnMount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
19
|
+
var scrollTriggerMargin = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : SCROLL_TRIGGER_MARGIN;
|
|
16
20
|
useEffect(function () {
|
|
17
21
|
var current = ref.current;
|
|
18
22
|
|
|
@@ -21,7 +25,7 @@ var useInfiniteScroll = function useInfiniteScroll(ref, callback) {
|
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
var isAtBottom = function isAtBottom() {
|
|
24
|
-
return Boolean(current && current.scrollTop + current.clientHeight
|
|
28
|
+
return Boolean(current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin);
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
var onScroll = function onScroll(e) {
|
|
@@ -40,7 +44,7 @@ var useInfiniteScroll = function useInfiniteScroll(ref, callback) {
|
|
|
40
44
|
current.removeEventListener('scroll', onScroll);
|
|
41
45
|
current.removeEventListener('resize', onScroll);
|
|
42
46
|
};
|
|
43
|
-
}, [ref, callback]);
|
|
47
|
+
}, [ref, callback, scrollTriggerMargin]);
|
|
44
48
|
useEffect(function () {
|
|
45
49
|
if (callback && callbackOnMount) {
|
|
46
50
|
callback();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown2.js","sources":["../../../src/hooks/useInfiniteScroll.tsx","../../../src/components/dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\ntype useInfiniteScrollType = (\n ref: React.RefObject<HTMLElement>,\n callback?: EventCallback,\n callbackOnMount?: boolean,\n) => void;\ntype EventCallback = (evt?: Event) => void;\n\n/**\n * Listen to clicks away from a given element and callback the passed in function.\n *\n * @param ref A reference to the element on which you want to listen scroll event.\n * @param [callback] A callback function to call when the bottom of the reference element is reached.\n * @param [callbackOnMount] A callback function to call when the component is mounted.\n */\nexport const useInfiniteScroll: useInfiniteScrollType = (ref, callback, callbackOnMount = false) => {\n useEffect(() => {\n const { current } = ref;\n if (!callback || !current) {\n return undefined;\n }\n\n const isAtBottom = () => Boolean(current && current.scrollTop + current.clientHeight >= current.scrollHeight);\n\n const onScroll = (e?: Event): void => {\n if (isAtBottom()) {\n callback(e);\n }\n };\n\n if (isAtBottom()) {\n onScroll();\n }\n\n current.addEventListener('scroll', onScroll);\n current.addEventListener('resize', onScroll);\n return () => {\n current.removeEventListener('scroll', onScroll);\n current.removeEventListener('resize', onScroll);\n };\n }, [ref, callback]);\n\n useEffect(() => {\n if (callback && callbackOnMount) {\n callback();\n }\n }, [callback, callbackOnMount]);\n};\n","import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { List, ListProps } from '@lumx/react/components/list/List';\nimport { Offset, Placement, Popover } from '@lumx/react/components/popover/Popover';\nimport { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DropdownProps extends GenericProps {\n /** Reference to the element around which the dropdown is placed.\n * @see {@link PopoverProps#anchorRef}\n */\n anchorRef: React.RefObject<HTMLElement>;\n /** Dropdown content. */\n children: React.ReactNode;\n /**\n * Whether a click anywhere out of the Dropdown would close it or not.\n * @see {@link PopoverProps#closeOnClickAway}\n */\n closeOnClickAway?: boolean;\n /**\n * Whether to close the Dropdown when clicking in it or not.\n */\n closeOnClick?: boolean;\n /**\n * Whether an escape key press would close the Dropdown or not.\n * @see {@link PopoverProps#closeOnEscape}\n */\n closeOnEscape?: boolean;\n /**\n * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.\n * @see {@link PopoverProps#fitToAnchorWidth}\n */\n fitToAnchorWidth?: boolean;\n /**\n * Whether the dropdown should shrink to fit within the viewport height or not.\n * @see {@link PopoverProps#fitWithinViewportHeight}\n */\n fitWithinViewportHeight?: boolean;\n /**\n * Whether the dropdown should be displayed or not. Useful to control the Dropdown from outside the component.\n * @see {@link PopoverProps#isOpen}\n */\n isOpen: boolean;\n /**\n * Offset applied to the Dropdown position.\n * @see {@link PopoverProps#offset}\n */\n offset?: Offset;\n /**\n * Preferred Dropdown placement against the anchor element.\n * @see {@link PopoverProps#placement}\n */\n placement?: Placement;\n /** Whether the focus should be set on the list when the dropdown is open or not. */\n shouldFocusOnOpen?: boolean;\n /**\n * Z-axis position.\n * @see {@link PopoverProps#zIndex}\n */\n zIndex?: number;\n /**\n * On close callback.\n * @see {@link PopoverProps#onClose}\n */\n onClose?(): void;\n /** On scroll end callback. */\n onInfiniteScroll?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dropdown';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DropdownProps> = {\n closeOnClick: true,\n closeOnClickAway: true,\n closeOnEscape: true,\n fitToAnchorWidth: true,\n fitWithinViewportHeight: true,\n placement: Placement.BOTTOM_START,\n shouldFocusOnOpen: true,\n};\n\n/**\n * Dropdown component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n anchorRef,\n children,\n className,\n closeOnClick,\n closeOnClickAway,\n closeOnEscape,\n fitToAnchorWidth,\n fitWithinViewportHeight,\n isOpen,\n offset,\n onClose,\n onInfiniteScroll,\n placement,\n shouldFocusOnOpen,\n zIndex,\n ...forwardedProps\n } = props;\n const innerRef = useRef<HTMLDivElement>(null);\n const listElement = useRef(null);\n\n useInfiniteScroll(innerRef, onInfiniteScroll);\n\n const popperElement = useMemo(() => {\n return !Array.isArray(children) && isComponent(List)(children)\n ? cloneElement<ListProps>(children, {\n ...children.props,\n ref: listElement,\n onClick(evt: MouseEvent) {\n children.props.onClick?.(evt);\n\n if (closeOnClick) {\n onClose?.();\n }\n },\n isClickable: true,\n })\n : children;\n }, [children, closeOnClick, onClose]);\n\n return isOpen ? (\n <Popover\n ref={ref}\n {...forwardedProps}\n anchorRef={anchorRef}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}\n closeOnClickAway={closeOnClickAway}\n closeOnEscape={closeOnEscape}\n fitToAnchorWidth={fitToAnchorWidth}\n fitWithinViewportHeight={fitWithinViewportHeight}\n focusElement={shouldFocusOnOpen ? listElement : undefined}\n isOpen={isOpen}\n offset={offset}\n onClose={onClose}\n placement={placement}\n zIndex={zIndex}\n >\n <div className={`${CLASSNAME}__menu`} ref={innerRef}>\n {popperElement}\n </div>\n </Popover>\n ) : null;\n});\nDropdown.displayName = COMPONENT_NAME;\nDropdown.className = CLASSNAME;\nDropdown.defaultProps = DEFAULT_PROPS;\n"],"names":["useInfiniteScroll","ref","callback","callbackOnMount","useEffect","current","undefined","isAtBottom","Boolean","scrollTop","clientHeight","scrollHeight","onScroll","e","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","closeOnClick","closeOnClickAway","closeOnEscape","fitToAnchorWidth","fitWithinViewportHeight","placement","Placement","BOTTOM_START","shouldFocusOnOpen","Dropdown","forwardRef","props","anchorRef","children","className","isOpen","offset","onClose","onInfiniteScroll","zIndex","forwardedProps","innerRef","useRef","listElement","popperElement","useMemo","Array","isArray","isComponent","List","cloneElement","onClick","evt","isClickable","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;;AASA;;;;;;;AAOO,IAAMA,iBAAwC,GAAG,SAA3CA,iBAA2C,CAACC,GAAD,EAAMC,QAAN,EAA4C;AAAA,MAA5BC,eAA4B,uEAAV,KAAU;AAChGC,EAAAA,SAAS,CAAC,YAAM;AAAA,QACJC,OADI,GACQJ,GADR,CACJI,OADI;;AAEZ,QAAI,CAACH,QAAD,IAAa,CAACG,OAAlB,EAA2B;AACvB,aAAOC,SAAP;AACH;;AAED,QAAMC,UAAU,GAAG,SAAbA,UAAa;AAAA,aAAMC,OAAO,CAACH,OAAO,IAAIA,OAAO,CAACI,SAAR,GAAoBJ,OAAO,CAACK,YAA5B,IAA4CL,OAAO,CAACM,YAAhE,CAAb;AAAA,KAAnB;;AAEA,QAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,CAAD,EAAqB;AAClC,UAAIN,UAAU,EAAd,EAAkB;AACdL,QAAAA,QAAQ,CAACW,CAAD,CAAR;AACH;AACJ,KAJD;;AAMA,QAAIN,UAAU,EAAd,EAAkB;AACdK,MAAAA,QAAQ;AACX;;AAEDP,IAAAA,OAAO,CAACS,gBAAR,CAAyB,QAAzB,EAAmCF,QAAnC;AACAP,IAAAA,OAAO,CAACS,gBAAR,CAAyB,QAAzB,EAAmCF,QAAnC;AACA,WAAO,YAAM;AACTP,MAAAA,OAAO,CAACU,mBAAR,CAA4B,QAA5B,EAAsCH,QAAtC;AACAP,MAAAA,OAAO,CAACU,mBAAR,CAA4B,QAA5B,EAAsCH,QAAtC;AACH,KAHD;AAIH,GAxBQ,E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AS,EAAER,SAHf;AAII,IAAA,SAAS,EAAEsB,UAAU,CAACpB,SAAD,EAAYqB,kBAAkB,CAAC;AAAEC,MAAAA,MAAM,EAAEvC;AAAV,KAAD,CAA9B,CAJzB;AAKI,IAAA,gBAAgB,EAAEI,gBALtB;AAMI,IAAA,aAAa,EAAEC,aANnB;AAOI,IAAA,gBAAgB,EAAEC,gBAPtB;AAQI,IAAA,uBAAuB,EAAEC,uBAR7B;AASI,IAAA,YAAY,EAAEI,iBAAiB,GAAGe,WAAH,GAAiBrC,SATpD;AAUI,IAAA,MAAM,EAAE6B,MAVZ;AAWI,IAAA,MAAM,EAAEC,MAXZ;AAYI,IAAA,OAAO,EAAEC,OAZb;AAaI,IAAA,SAAS,EAAEZ,SAbf;AAcI,IAAA,MAAM,EAAEc;AAdZ,MAgBI;AAAK,IAAA,SAAS,YAAKtB,SAAL,WAAd;AAAsC,IAAA,GAAG,EAAEwB;AAA3C,KACKG,aADL,CAhBJ,CADS,GAqBT,IArBJ;AAsBH,CA/DsE;AAgEvEf,QAAQ,CAAC4B,WAAT,GAAuBzC,cAAvB;AACAa,QAAQ,CAACK,SAAT,GAAqBjB,SAArB;AACAY,QAAQ,CAAC6B,YAAT,GAAwBvC,aAAxB;;;;"}
|
|
1
|
+
{"version":3,"file":"Dropdown2.js","sources":["../../../src/hooks/useInfiniteScroll.tsx","../../../src/components/dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\ntype useInfiniteScrollType = (\n ref: React.RefObject<HTMLElement>,\n callback?: EventCallback,\n callbackOnMount?: boolean,\n) => void;\ntype EventCallback = (evt?: Event) => void;\n\n// The error margin in px we want to have for triggering infinite scroll\nconst SCROLL_TRIGGER_MARGIN = 5;\n\n/**\n * Listen to clicks away from a given element and callback the passed in function.\n *\n * @param ref A reference to the element on which you want to listen scroll event.\n * @param [callback] A callback function to call when the bottom of the reference element is reached.\n * @param [callbackOnMount] A callback function to call when the component is mounted.\n */\nexport const useInfiniteScroll: useInfiniteScrollType = (\n ref,\n callback,\n callbackOnMount = false,\n scrollTriggerMargin = SCROLL_TRIGGER_MARGIN,\n) => {\n useEffect(() => {\n const { current } = ref;\n if (!callback || !current) {\n return undefined;\n }\n\n const isAtBottom = () =>\n Boolean(\n current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin,\n );\n\n const onScroll = (e?: Event): void => {\n if (isAtBottom()) {\n callback(e);\n }\n };\n\n if (isAtBottom()) {\n onScroll();\n }\n\n current.addEventListener('scroll', onScroll);\n current.addEventListener('resize', onScroll);\n return () => {\n current.removeEventListener('scroll', onScroll);\n current.removeEventListener('resize', onScroll);\n };\n }, [ref, callback, scrollTriggerMargin]);\n\n useEffect(() => {\n if (callback && callbackOnMount) {\n callback();\n }\n }, [callback, callbackOnMount]);\n};\n","import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { List, ListProps } from '@lumx/react/components/list/List';\nimport { Offset, Placement, Popover } from '@lumx/react/components/popover/Popover';\nimport { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DropdownProps extends GenericProps {\n /** Reference to the element around which the dropdown is placed.\n * @see {@link PopoverProps#anchorRef}\n */\n anchorRef: React.RefObject<HTMLElement>;\n /** Dropdown content. */\n children: React.ReactNode;\n /**\n * Whether a click anywhere out of the Dropdown would close it or not.\n * @see {@link PopoverProps#closeOnClickAway}\n */\n closeOnClickAway?: boolean;\n /**\n * Whether to close the Dropdown when clicking in it or not.\n */\n closeOnClick?: boolean;\n /**\n * Whether an escape key press would close the Dropdown or not.\n * @see {@link PopoverProps#closeOnEscape}\n */\n closeOnEscape?: boolean;\n /**\n * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.\n * @see {@link PopoverProps#fitToAnchorWidth}\n */\n fitToAnchorWidth?: boolean;\n /**\n * Whether the dropdown should shrink to fit within the viewport height or not.\n * @see {@link PopoverProps#fitWithinViewportHeight}\n */\n fitWithinViewportHeight?: boolean;\n /**\n * Whether the dropdown should be displayed or not. Useful to control the Dropdown from outside the component.\n * @see {@link PopoverProps#isOpen}\n */\n isOpen: boolean;\n /**\n * Offset applied to the Dropdown position.\n * @see {@link PopoverProps#offset}\n */\n offset?: Offset;\n /**\n * Preferred Dropdown placement against the anchor element.\n * @see {@link PopoverProps#placement}\n */\n placement?: Placement;\n /** Whether the focus should be set on the list when the dropdown is open or not. */\n shouldFocusOnOpen?: boolean;\n /**\n * Z-axis position.\n * @see {@link PopoverProps#zIndex}\n */\n zIndex?: number;\n /**\n * On close callback.\n * @see {@link PopoverProps#onClose}\n */\n onClose?(): void;\n /** On scroll end callback. */\n onInfiniteScroll?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dropdown';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DropdownProps> = {\n closeOnClick: true,\n closeOnClickAway: true,\n closeOnEscape: true,\n fitToAnchorWidth: true,\n fitWithinViewportHeight: true,\n placement: Placement.BOTTOM_START,\n shouldFocusOnOpen: true,\n};\n\n/**\n * Dropdown component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n anchorRef,\n children,\n className,\n closeOnClick,\n closeOnClickAway,\n closeOnEscape,\n fitToAnchorWidth,\n fitWithinViewportHeight,\n isOpen,\n offset,\n onClose,\n onInfiniteScroll,\n placement,\n shouldFocusOnOpen,\n zIndex,\n ...forwardedProps\n } = props;\n const innerRef = useRef<HTMLDivElement>(null);\n const listElement = useRef(null);\n\n useInfiniteScroll(innerRef, onInfiniteScroll);\n\n const popperElement = useMemo(() => {\n return !Array.isArray(children) && isComponent(List)(children)\n ? cloneElement<ListProps>(children, {\n ...children.props,\n ref: listElement,\n onClick(evt: MouseEvent) {\n children.props.onClick?.(evt);\n\n if (closeOnClick) {\n onClose?.();\n }\n },\n isClickable: true,\n })\n : children;\n }, [children, closeOnClick, onClose]);\n\n return isOpen ? (\n <Popover\n ref={ref}\n {...forwardedProps}\n anchorRef={anchorRef}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}\n closeOnClickAway={closeOnClickAway}\n closeOnEscape={closeOnEscape}\n fitToAnchorWidth={fitToAnchorWidth}\n fitWithinViewportHeight={fitWithinViewportHeight}\n focusElement={shouldFocusOnOpen ? listElement : undefined}\n isOpen={isOpen}\n offset={offset}\n onClose={onClose}\n placement={placement}\n zIndex={zIndex}\n >\n <div className={`${CLASSNAME}__menu`} ref={innerRef}>\n {popperElement}\n </div>\n </Popover>\n ) : null;\n});\nDropdown.displayName = COMPONENT_NAME;\nDropdown.className = CLASSNAME;\nDropdown.defaultProps = DEFAULT_PROPS;\n"],"names":["SCROLL_TRIGGER_MARGIN","useInfiniteScroll","ref","callback","callbackOnMount","scrollTriggerMargin","useEffect","current","undefined","isAtBottom","Boolean","scrollHeight","scrollTop","clientHeight","onScroll","e","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","closeOnClick","closeOnClickAway","closeOnEscape","fitToAnchorWidth","fitWithinViewportHeight","placement","Placement","BOTTOM_START","shouldFocusOnOpen","Dropdown","forwardRef","props","anchorRef","children","className","isOpen","offset","onClose","onInfiniteScroll","zIndex","forwardedProps","innerRef","useRef","listElement","popperElement","useMemo","Array","isArray","isComponent","List","cloneElement","onClick","evt","isClickable","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;;AASA;AACA,IAAMA,qBAAqB,GAAG,CAA9B;AAEA;;;;;;;;AAOO,IAAMC,iBAAwC,GAAG,SAA3CA,iBAA2C,CACpDC,GADoD,EAEpDC,QAFoD,EAKnD;AAAA,MAFDC,eAEC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BrC,SATpD;AAUI,IAAA,MAAM,EAAE6B,MAVZ;AAWI,IAAA,MAAM,EAAEC,MAXZ;AAYI,IAAA,OAAO,EAAEC,OAZb;AAaI,IAAA,SAAS,EAAEZ,SAbf;AAcI,IAAA,MAAM,EAAEc;AAdZ,MAgBI;AAAK,IAAA,SAAS,YAAKtB,SAAL,WAAd;AAAsC,IAAA,GAAG,EAAEwB;AAA3C,KACKG,aADL,CAhBJ,CADS,GAqBT,IArBJ;AAsBH,CA/DsE;AAgEvEf,QAAQ,CAAC4B,WAAT,GAAuBzC,cAAvB;AACAa,QAAQ,CAACK,SAAT,GAAqBjB,SAArB;AACAY,QAAQ,CAAC6B,YAAT,GAAwBvC,aAAxB;;;;"}
|
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@juggle/resize-observer": "^3.2.0",
|
|
10
|
-
"@lumx/core": "^2.0.1
|
|
11
|
-
"@lumx/icons": "^2.0.1
|
|
10
|
+
"@lumx/core": "^2.0.1",
|
|
11
|
+
"@lumx/icons": "^2.0.1",
|
|
12
12
|
"@popperjs/core": "^2.5.4",
|
|
13
13
|
"body-scroll-lock": "^3.1.5",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -123,9 +123,9 @@
|
|
|
123
123
|
"storybook": "start-storybook -s ../site-demo/static/ -p 9000"
|
|
124
124
|
},
|
|
125
125
|
"sideEffects": false,
|
|
126
|
-
"version": "2.0.1
|
|
126
|
+
"version": "2.0.1",
|
|
127
127
|
"resolutions": {
|
|
128
128
|
"**/style-loader": "^1.0.0"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "564dc03017aa2a246dfb40040f2055e812129364"
|
|
131
131
|
}
|
|
@@ -7,6 +7,9 @@ type useInfiniteScrollType = (
|
|
|
7
7
|
) => void;
|
|
8
8
|
type EventCallback = (evt?: Event) => void;
|
|
9
9
|
|
|
10
|
+
// The error margin in px we want to have for triggering infinite scroll
|
|
11
|
+
const SCROLL_TRIGGER_MARGIN = 5;
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* Listen to clicks away from a given element and callback the passed in function.
|
|
12
15
|
*
|
|
@@ -14,14 +17,22 @@ type EventCallback = (evt?: Event) => void;
|
|
|
14
17
|
* @param [callback] A callback function to call when the bottom of the reference element is reached.
|
|
15
18
|
* @param [callbackOnMount] A callback function to call when the component is mounted.
|
|
16
19
|
*/
|
|
17
|
-
export const useInfiniteScroll: useInfiniteScrollType = (
|
|
20
|
+
export const useInfiniteScroll: useInfiniteScrollType = (
|
|
21
|
+
ref,
|
|
22
|
+
callback,
|
|
23
|
+
callbackOnMount = false,
|
|
24
|
+
scrollTriggerMargin = SCROLL_TRIGGER_MARGIN,
|
|
25
|
+
) => {
|
|
18
26
|
useEffect(() => {
|
|
19
27
|
const { current } = ref;
|
|
20
28
|
if (!callback || !current) {
|
|
21
29
|
return undefined;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
const isAtBottom = () =>
|
|
32
|
+
const isAtBottom = () =>
|
|
33
|
+
Boolean(
|
|
34
|
+
current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin,
|
|
35
|
+
);
|
|
25
36
|
|
|
26
37
|
const onScroll = (e?: Event): void => {
|
|
27
38
|
if (isAtBottom()) {
|
|
@@ -39,7 +50,7 @@ export const useInfiniteScroll: useInfiniteScrollType = (ref, callback, callback
|
|
|
39
50
|
current.removeEventListener('scroll', onScroll);
|
|
40
51
|
current.removeEventListener('resize', onScroll);
|
|
41
52
|
};
|
|
42
|
-
}, [ref, callback]);
|
|
53
|
+
}, [ref, callback, scrollTriggerMargin]);
|
|
43
54
|
|
|
44
55
|
useEffect(() => {
|
|
45
56
|
if (callback && callbackOnMount) {
|