@tapcart/mobile-components 0.7.55 → 0.7.56
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.
|
@@ -3,13 +3,16 @@ import { type VariantProps } from "class-variance-authority";
|
|
|
3
3
|
interface GridType {
|
|
4
4
|
className: any;
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
isLoadingMore: boolean;
|
|
7
|
+
loaderItem: React.ReactNode;
|
|
6
8
|
overscan?: number;
|
|
9
|
+
estimatedHeight?: number;
|
|
7
10
|
}
|
|
8
11
|
declare const virtualGridVariants: (props?: ({
|
|
9
12
|
columns?: 1 | 2 | 3 | 4 | null | undefined;
|
|
10
13
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
11
14
|
export interface VirtualGridProps extends GridType, VariantProps<typeof virtualGridVariants> {
|
|
12
15
|
}
|
|
13
|
-
declare function VirtualGrid({ className, columns, children, overscan, ...props }: VirtualGridProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
declare function VirtualGrid({ className, columns, children, overscan, estimatedHeight, isLoadingMore, loaderItem, ...props }: VirtualGridProps): import("react/jsx-runtime").JSX.Element;
|
|
14
17
|
export { VirtualGrid, virtualGridVariants };
|
|
15
18
|
//# sourceMappingURL=virtual-grid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-grid.d.ts","sourceRoot":"","sources":["../../../components/ui/virtual-grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAMjE,UAAU,QAAQ;IAChB,SAAS,EAAE,GAAG,CAAA;IACd,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"virtual-grid.d.ts","sourceRoot":"","sources":["../../../components/ui/virtual-grid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAMjE,UAAU,QAAQ;IAChB,SAAS,EAAE,GAAG,CAAA;IACd,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,aAAa,EAAE,OAAO,CAAA;IACtB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,QAAA,MAAM,mBAAmB;;mFAYvB,CAAA;AAEF,MAAM,WAAW,gBACf,SAAQ,QAAQ,EACd,YAAY,CAAC,OAAO,mBAAmB,CAAC;CAAG;AAE/C,iBAAS,WAAW,CAAC,EACnB,SAAS,EACT,OAAO,EACP,QAAQ,EACR,QAAa,EACb,eAAqB,EACrB,aAAa,EACb,UAAU,EACV,GAAG,KAAK,EACT,EAAE,gBAAgB,2CAkElB;AAED,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -29,17 +29,20 @@ const virtualGridVariants = cva("grid", {
|
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
31
|
function VirtualGrid(_a) {
|
|
32
|
-
var { className, columns, children, overscan = 50 } = _a, props = __rest(_a, ["className", "columns", "children", "overscan"]);
|
|
32
|
+
var { className, columns, children, overscan = 50, estimatedHeight = 375, isLoadingMore, loaderItem } = _a, props = __rest(_a, ["className", "columns", "children", "overscan", "estimatedHeight", "isLoadingMore", "loaderItem"]);
|
|
33
|
+
const NUM_LOADER_ITEMS = 8;
|
|
34
|
+
const col = columns || 2;
|
|
33
35
|
const parentRef = React.useRef(null);
|
|
34
36
|
const childrenArray = React.Children.toArray(children);
|
|
35
|
-
const rowCount = Math.ceil(childrenArray.length /
|
|
37
|
+
const rowCount = Math.ceil(childrenArray.length / col);
|
|
38
|
+
const loaderRowCount = Math.ceil(NUM_LOADER_ITEMS / col);
|
|
39
|
+
const totalItems = isLoadingMore ? rowCount + loaderRowCount : rowCount;
|
|
36
40
|
const rowVirtualizer = useVirtual({
|
|
37
|
-
size:
|
|
41
|
+
size: totalItems,
|
|
38
42
|
parentRef,
|
|
39
|
-
estimateSize: React.useCallback(() =>
|
|
43
|
+
estimateSize: React.useCallback(() => estimatedHeight, []),
|
|
40
44
|
overscan,
|
|
41
45
|
});
|
|
42
|
-
const col = columns || 2;
|
|
43
46
|
React.useEffect(() => {
|
|
44
47
|
rowVirtualizer.measure();
|
|
45
48
|
}, [childrenArray.length]);
|
|
@@ -47,6 +50,10 @@ function VirtualGrid(_a) {
|
|
|
47
50
|
height: rowVirtualizer.totalSize,
|
|
48
51
|
} }, props, { children: rowVirtualizer.virtualItems.map((virtualRow) => {
|
|
49
52
|
const rowStartIndex = virtualRow.index * col;
|
|
53
|
+
// Render loader as a full row if we're loading and this is the last virtual row
|
|
54
|
+
if (isLoadingMore && virtualRow.index === rowCount - 1) {
|
|
55
|
+
return (_jsx(React.Fragment, { children: Array.from({ length: NUM_LOADER_ITEMS }).map((_, index) => (_jsx("div", Object.assign({ ref: virtualRow.measureRef }, { children: loaderItem }), index))) }, "loader"));
|
|
56
|
+
}
|
|
50
57
|
return (_jsx(React.Fragment, { children: Array.from({ length: col }).map((_, colIndex) => {
|
|
51
58
|
const index = rowStartIndex + colIndex;
|
|
52
59
|
if (index >= childrenArray.length)
|