@tap-payments/os-micro-frontend-shared 0.0.290 → 0.0.292
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/build/components/ScrollLoader/ScrollLoader.d.ts +10 -0
- package/build/components/ScrollLoader/ScrollLoader.js +64 -0
- package/build/components/ScrollLoader/index.d.ts +3 -0
- package/build/components/ScrollLoader/index.js +3 -0
- package/build/components/VirtualTable/SheetView/SheetViewVirtualTable.js +2 -2
- package/build/components/VirtualTable/components/index.d.ts +1 -1
- package/build/components/index.d.ts +2 -0
- package/build/components/index.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { StackProps } from '@mui/material/Stack';
|
|
3
|
+
export type ScrollLoaderProps<IRootProps extends object = StackProps> = PropsWithChildren<IRootProps & {
|
|
4
|
+
component?: React.FC<IRootProps> | React.ElementType;
|
|
5
|
+
loadMoreItems: () => Promise<unknown>;
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
hasMore?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
declare const ScrollLoader: <IRootProps extends object = StackProps>(props: ScrollLoaderProps<IRootProps>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default ScrollLoader;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
14
|
+
import Stack from '@mui/material/Stack';
|
|
15
|
+
const OFFSET = 50;
|
|
16
|
+
const isNearBottom = (el, offset = OFFSET) => {
|
|
17
|
+
const scrollBottom = el.scrollTop + el.clientHeight;
|
|
18
|
+
const scrollHeight = el.scrollHeight;
|
|
19
|
+
return scrollHeight - scrollBottom <= offset;
|
|
20
|
+
};
|
|
21
|
+
const ScrollLoader = (props) => {
|
|
22
|
+
const { component = Stack, loadMoreItems, hasMore, loading, children } = props, rootProps = __rest(props, ["component", "loadMoreItems", "hasMore", "loading", "children"]);
|
|
23
|
+
const [initialChecked, setInitialChecked] = useState(false);
|
|
24
|
+
const loadMoreItemsRef = useRef(loadMoreItems);
|
|
25
|
+
const containerRef = useRef(null);
|
|
26
|
+
loadMoreItemsRef.current = loadMoreItems;
|
|
27
|
+
const Component = component;
|
|
28
|
+
const handleScroll = useCallback(() => {
|
|
29
|
+
const el = containerRef.current;
|
|
30
|
+
if (!el || loading || !hasMore)
|
|
31
|
+
return;
|
|
32
|
+
const isBottom = isNearBottom(el);
|
|
33
|
+
if (isBottom)
|
|
34
|
+
loadMoreItemsRef.current();
|
|
35
|
+
}, [loading, hasMore]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const el = containerRef.current;
|
|
38
|
+
if (!el)
|
|
39
|
+
return;
|
|
40
|
+
el.addEventListener('scroll', handleScroll);
|
|
41
|
+
return () => el.removeEventListener('scroll', handleScroll);
|
|
42
|
+
}, [handleScroll]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const el = containerRef.current;
|
|
45
|
+
if (!el || loading)
|
|
46
|
+
return;
|
|
47
|
+
const timeout = setTimeout(() => {
|
|
48
|
+
const isBottom = isNearBottom(el);
|
|
49
|
+
if (isBottom && !initialChecked) {
|
|
50
|
+
loadMoreItemsRef.current();
|
|
51
|
+
setInitialChecked(true);
|
|
52
|
+
}
|
|
53
|
+
}, 2000);
|
|
54
|
+
return () => {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
};
|
|
57
|
+
}, [loading, initialChecked]);
|
|
58
|
+
return (_jsx(Component, Object.assign({ overflow: "auto", ref: containerRef, style: {
|
|
59
|
+
overflow: 'auto',
|
|
60
|
+
height: '100%',
|
|
61
|
+
maxHeight: '100%',
|
|
62
|
+
} }, rootProps, { children: children })));
|
|
63
|
+
};
|
|
64
|
+
export default ScrollLoader;
|
|
@@ -123,7 +123,7 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
|
|
|
123
123
|
overflowX: isPinned ? 'hidden' : 'auto',
|
|
124
124
|
paddingBottom: isPinned ? '25px' : '13px',
|
|
125
125
|
backgroundColor: isPinned ? 'transparent' : '#F6F8FACC',
|
|
126
|
-
} }, { children: ListItemWrapper })));
|
|
126
|
+
} }, { children: ListItemWrapper }), `${containerKey}-${rows.length}`));
|
|
127
127
|
} })) })));
|
|
128
128
|
}, [
|
|
129
129
|
itemsCount,
|
|
@@ -186,7 +186,7 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
|
|
|
186
186
|
height: 'auto',
|
|
187
187
|
display: 'flex',
|
|
188
188
|
flexDirection: 'column',
|
|
189
|
-
} }, { children: _jsx(SheetViewTableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps }) })) }))] })) }))) : (_jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_StyledTableBox", "data-title": tableTitle, "data-direction": theme.direction, "data-are-all-rows-loaded": !!areAllRowsLoaded, "data-is-fetching-next-page": !!isFetchingNextPage, "data-scroll-to-index": scrollToIndex, "data-is-loading": !!isLoading, "data-is-error": !!isError, "data-is-error-timeout": !!hasTimeoutError, "data-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView }, { children:
|
|
189
|
+
} }, { children: _jsx(SheetViewTableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps }) })) }))] })) }))) : (_jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_StyledTableBox", "data-title": tableTitle, "data-direction": theme.direction, "data-are-all-rows-loaded": !!areAllRowsLoaded, "data-is-fetching-next-page": !!isFetchingNextPage, "data-scroll-to-index": scrollToIndex, "data-is-loading": !!isLoading, "data-is-error": !!isError, "data-is-error-timeout": !!hasTimeoutError, "data-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView }, { children: _jsxs(TableWrapper, Object.assign({ isSheetView: true, "data-testid": "SheetViewVirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: tableBodyStyles }, { children: [showHeader && (_jsx(UnpinnedTableHeaderWrapper, { children: _jsx(SheetViewTableHeader, { "data-testid": "SheetViewVirtualTable_LoadingTableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: orderedColumns, headerProps: headerProps, showBackDrop: showBackDrop, pinnedColumns: [], onColumnPin: handleColumnPin, isPinnable: false, lastColumnId: lastColumnId, selectedColumn: selectedColumn, onColumnClick: handleColumnClick }) })), _jsx(TableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps })] })) })))) : (_jsxs(SheetViewVirtualTableWrapper, { children: [renderPinnedColumn('start', pinnedStartColumnsData, pinnedStartColumnsWidth, pinnedStartColumns), _jsx(MainTableWrapper, Object.assign({ hasPinnedStart: pinnedStartColumnsData.length > 0, hasPinnedEnd: pinnedEndColumnsData.length > 0 }, { children: _jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_StyledTableBox", "data-title": tableTitle, "data-direction": theme.direction, "data-are-all-rows-loaded": !!areAllRowsLoaded, "data-is-fetching-next-page": !!isFetchingNextPage, "data-scroll-to-index": scrollToIndex, "data-is-loading": !!isLoading, "data-is-error": !!isError, "data-is-error-timeout": !!hasTimeoutError, "data-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView, scrollable: true }, { children: _jsxs(TableWrapper, Object.assign({ "data-testid": "SheetViewVirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: Object.assign(Object.assign({}, tableBodyStyles), { display: 'flex', flexDirection: 'column', height: '100%' }) }, { children: [showHeader && (_jsx(UnpinnedTableHeaderWrapper, { children: _jsx(SheetViewTableHeader, { "data-testid": "SheetViewVirtualTable_UnpinnedTableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: unpinnedColumnsData, headerProps: headerProps, showBackDrop: showBackDrop, pinnedColumns: [...pinnedStartColumns, ...pinnedEndColumns], onColumnPin: handleColumnPin, isPinnable: isPinnable, lastColumnId: lastColumnId, selectedColumn: selectedColumn, onColumnClick: handleColumnClick }) })), _jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
|
|
190
190
|
width: '100%',
|
|
191
191
|
minWidth: 'fit-content',
|
|
192
192
|
} }, { children: _jsx(StyledBox, Object.assign({ "data-testid": "SheetViewVirtualTable_ScrollableStyledBox", hidePadding: true, className: "list-wrapper" }, { children: createVirtualTableContainer(unpinnedColumnsData, 'scrollable', false) })) }))] })) })) })), renderPinnedColumn('end', pinnedEndColumnsData, pinnedEndColumnsWidth, [...pinnedStartColumns, ...pinnedEndColumns])] })) }), _jsx(TableFooter, Object.assign({ "data-testid": "SheetViewVirtualTable_TableFooter", showSeparator: true, showBackDrop: showBackDrop, onPointerDown: onPointerDown }, footerProps))] }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as ColumnFilter, Inputs, List, CustomColumnFilterProps } from './ColumnFilter';
|
|
1
|
+
export { default as ColumnFilter, Inputs, List, type CustomColumnFilterProps } from './ColumnFilter';
|
|
2
2
|
export * from './EmptyList';
|
|
3
3
|
export * from './ErrorList';
|
|
4
4
|
export * from './TableFooter';
|
|
@@ -95,3 +95,5 @@ export * from './TableHeader';
|
|
|
95
95
|
export { default as RangeCalender } from './RangeCalender';
|
|
96
96
|
export { default as AppServices } from './AppServices';
|
|
97
97
|
export * from './SourceChips';
|
|
98
|
+
export { default as ScrollLoader } from './ScrollLoader';
|
|
99
|
+
export * from './ScrollLoader';
|
|
@@ -95,3 +95,5 @@ export * from './TableHeader';
|
|
|
95
95
|
export { default as RangeCalender } from './RangeCalender';
|
|
96
96
|
export { default as AppServices } from './AppServices';
|
|
97
97
|
export * from './SourceChips';
|
|
98
|
+
export { default as ScrollLoader } from './ScrollLoader';
|
|
99
|
+
export * from './ScrollLoader';
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.0.292",
|
|
5
|
+
"testVersion": 0,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|