@codeleap/web 3.12.1 → 3.12.3
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/package.json +1 -1
- package/src/lib/ListMasonry.tsx +54 -29
package/package.json
CHANGED
package/src/lib/ListMasonry.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { useWindowSize } from '@react-hook/window-size'
|
|
3
|
-
import { AnyFunction, onUpdate, usePrevious } from '@codeleap/common'
|
|
3
|
+
import { AnyFunction, onUpdate, usePrevious, useState } from '@codeleap/common'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
useMasonry,
|
|
@@ -10,8 +10,11 @@ import {
|
|
|
10
10
|
useResizeObserver,
|
|
11
11
|
MasonryProps,
|
|
12
12
|
RenderComponentProps,
|
|
13
|
+
MasonryScroller,
|
|
13
14
|
} from 'masonic'
|
|
14
15
|
|
|
16
|
+
import { EmptyPlaceholder } from '../components/EmptyPlaceholder'
|
|
17
|
+
|
|
15
18
|
export type ItemMasonryProps<T> = RenderComponentProps<T>
|
|
16
19
|
|
|
17
20
|
export type ListMasonryProps<T> = MasonryProps<T> & {
|
|
@@ -20,7 +23,17 @@ export type ListMasonryProps<T> = MasonryProps<T> & {
|
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
|
|
23
|
-
const
|
|
26
|
+
const {
|
|
27
|
+
columnCount,
|
|
28
|
+
columnGutter,
|
|
29
|
+
rowGutter,
|
|
30
|
+
items,
|
|
31
|
+
render,
|
|
32
|
+
} = props
|
|
33
|
+
|
|
34
|
+
const data = items || []
|
|
35
|
+
|
|
36
|
+
const [reloadingLayout, setReloadingLayout] = useState(false)
|
|
24
37
|
|
|
25
38
|
const dataPreviousLength = usePrevious(data?.length)
|
|
26
39
|
|
|
@@ -34,7 +47,11 @@ export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
|
|
|
34
47
|
|
|
35
48
|
onUpdate(() => {
|
|
36
49
|
if (!!masonryUpdater && !!props?.itemsRehydrateIndicator) {
|
|
37
|
-
|
|
50
|
+
setReloadingLayout(true)
|
|
51
|
+
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
setReloadingLayout(false)
|
|
54
|
+
}, 3000)
|
|
38
55
|
}
|
|
39
56
|
}, [masonryUpdater])
|
|
40
57
|
|
|
@@ -47,34 +64,42 @@ export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
|
|
|
47
64
|
|
|
48
65
|
const containerPosition = useContainerPosition(containerRef, windowSize)
|
|
49
66
|
|
|
50
|
-
const listProps =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) as any
|
|
60
|
-
|
|
61
|
-
listProps.positioner = usePositioner({
|
|
67
|
+
const listProps = {
|
|
68
|
+
offset: containerPosition?.offset,
|
|
69
|
+
width: containerPosition?.width || containerRef?.current?.clientWidth || windowSize?.[0],
|
|
70
|
+
height: windowSize?.[1],
|
|
71
|
+
containerRef,
|
|
72
|
+
scrollFps: props?.scrollFps || 12,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const positioner = usePositioner({
|
|
62
76
|
width: listProps?.width,
|
|
63
|
-
columnGutter:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}, [masonryUpdater])
|
|
77
|
+
columnGutter: columnGutter,
|
|
78
|
+
columnCount: columnCount,
|
|
79
|
+
maxColumnCount: columnCount,
|
|
80
|
+
rowGutter: rowGutter
|
|
81
|
+
}, [masonryUpdater, reloadingLayout])
|
|
69
82
|
|
|
70
|
-
const
|
|
83
|
+
const resizeObserver = useResizeObserver(positioner)
|
|
71
84
|
|
|
72
|
-
|
|
85
|
+
if (reloadingLayout) {
|
|
86
|
+
return (
|
|
87
|
+
<EmptyPlaceholder loading={true} />
|
|
88
|
+
)
|
|
89
|
+
}
|
|
73
90
|
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
return (
|
|
92
|
+
<MasonryScroller
|
|
93
|
+
// {...props}
|
|
94
|
+
positioner={positioner}
|
|
95
|
+
resizeObserver={resizeObserver}
|
|
96
|
+
containerRef={containerRef}
|
|
97
|
+
items={data}
|
|
98
|
+
height={listProps?.height}
|
|
99
|
+
offset={listProps?.offset}
|
|
100
|
+
overscanBy={6}
|
|
101
|
+
render={render}
|
|
102
|
+
scrollFps={listProps?.scrollFps}
|
|
103
|
+
/>
|
|
104
|
+
)
|
|
80
105
|
}
|