1 | import { PureComponent } from "react";
|
2 | import { IndexRange } from "../../index";
|
3 | import { CellMeasurerCacheInterface, KeyMapper, MeasuredCellParent } from "./CellMeasurer";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export const DEFAULT_SCROLLING_RESET_TIME_INTERVAL = 150;
|
9 |
|
10 | export type OnCellsRenderedCallback = (params: IndexRange) => void;
|
11 |
|
12 | export type OnScrollCallback = (params: { clientHeight: number; scrollHeight: number; scrollTop: number }) => void;
|
13 |
|
14 | export type MasonryCellProps = {
|
15 | index: number;
|
16 | isScrolling: boolean;
|
17 | key: React.Key;
|
18 | parent: MeasuredCellParent;
|
19 | style?: React.CSSProperties | undefined;
|
20 | };
|
21 |
|
22 | export type CellRenderer = (props: MasonryCellProps) => React.ReactNode;
|
23 |
|
24 | export type MasonryProps = {
|
25 | autoHeight: boolean;
|
26 | cellCount: number;
|
27 | cellMeasurerCache: CellMeasurerCacheInterface;
|
28 | cellPositioner: Positioner;
|
29 | cellRenderer: CellRenderer;
|
30 | className?: string | undefined;
|
31 | height: number;
|
32 | id?: string | undefined;
|
33 | keyMapper?: KeyMapper | undefined;
|
34 | onCellsRendered?: OnCellsRenderedCallback | undefined;
|
35 | onScroll?: OnScrollCallback | undefined;
|
36 | overscanByPixels?: number | undefined;
|
37 | role?: string | undefined;
|
38 | scrollingResetTimeInterval?: number | undefined;
|
39 | style?: React.CSSProperties | undefined;
|
40 | tabIndex?: number | null | undefined;
|
41 | width: number;
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | [key: string]: any;
|
50 | };
|
51 |
|
52 | export type MasonryState = {
|
53 | isScrolling: boolean;
|
54 | scrollTop: number;
|
55 | };
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export class Masonry extends PureComponent<MasonryProps, MasonryState> {
|
86 | static defaultProps: {
|
87 | autoHeight: false;
|
88 | keyMapper: identity;
|
89 | onCellsRendered: noop;
|
90 | onScroll: noop;
|
91 | overscanByPixels: 20;
|
92 | role: "grid";
|
93 | scrollingResetTimeInterval: typeof DEFAULT_SCROLLING_RESET_TIME_INTERVAL;
|
94 | style: emptyObject;
|
95 | tabIndex: 0;
|
96 | };
|
97 |
|
98 | clearCellPositions(): void;
|
99 |
|
100 |
|
101 | invalidateCellSizeAfterRender(params: { rowIndex: number }): void;
|
102 |
|
103 | recomputeCellPositions(): void;
|
104 |
|
105 | static getDerivedStateFromProps(nextProps: MasonryProps, prevState: MasonryState): MasonryState | null;
|
106 | }
|
107 |
|
108 | export default Masonry;
|
109 |
|
110 | export type emptyObject = {};
|
111 |
|
112 | export type identity = <T>(value: T) => T;
|
113 |
|
114 | export type noop = () => void;
|
115 |
|
116 | export type Position = {
|
117 | left: number;
|
118 | top: number;
|
119 | };
|
120 |
|
121 | export type createCellPositionerParams = {
|
122 | cellMeasurerCache: CellMeasurerCacheInterface;
|
123 | columnCount: number;
|
124 | columnWidth: number;
|
125 | spacer?: number | undefined;
|
126 | };
|
127 |
|
128 | export type resetParams = {
|
129 | columnCount: number;
|
130 | columnWidth: number;
|
131 | spacer?: number | undefined;
|
132 | };
|
133 |
|
134 | export type Positioner = ((index: number) => Position) & {
|
135 | reset: (params: resetParams) => void;
|
136 | };
|
137 |
|
138 | export const createCellPositioner: (params: createCellPositionerParams) => Positioner;
|