1 | import { PureComponent, Validator, Requireable } from 'react';
|
2 | import { Grid, GridCoreProps, GridCellProps, OverscanIndicesGetter } from './Grid';
|
3 | import { Index, IndexRange, OverscanIndexRange, Alignment } from '../../index';
|
4 | import { CellMeasurerCache, CellPosition } from './CellMeasurer';
|
5 | import { OnScrollParams } from './ScrollSync';
|
6 |
|
7 | export type ListRowProps = Pick<GridCellProps, Exclude<keyof GridCellProps, 'rowIndex'>> & {
|
8 | index: GridCellProps['rowIndex'];
|
9 | };
|
10 |
|
11 | export type ListRowRenderer = (props: ListRowProps) => React.ReactNode;
|
12 |
|
13 | export type RenderedRows = OverscanIndexRange & IndexRange;
|
14 |
|
15 | export type ListProps = GridCoreProps & {
|
16 | deferredMeasurementCache?: CellMeasurerCache;
|
17 | |
18 |
|
19 |
|
20 |
|
21 | autoHeight?: boolean;
|
22 |
|
23 | className?: string;
|
24 | |
25 |
|
26 |
|
27 |
|
28 | estimatedRowSize?: number;
|
29 |
|
30 | height: number;
|
31 |
|
32 | noRowsRenderer?: () => JSX.Element;
|
33 | |
34 |
|
35 |
|
36 |
|
37 | onRowsRendered?: (info: RenderedRows) => void;
|
38 | |
39 |
|
40 |
|
41 |
|
42 | overscanRowCount?: number;
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 | onScroll?: (params: OnScrollParams) => void;
|
49 |
|
50 | overscanIndicesGetter?: OverscanIndicesGetter;
|
51 | |
52 |
|
53 |
|
54 |
|
55 | rowHeight: number | ((info: Index) => number);
|
56 | /** Responsible for rendering a row given an index; ({ index: number }): node */
|
57 | rowRenderer: ListRowRenderer;
|
58 | /** Number of rows in list. */
|
59 | rowCount: number;
|
60 | /** See Grid#scrollToAlignment */
|
61 | scrollToAlignment?: string;
|
62 | /** Row index to ensure visible (by forcefully scrolling if necessary) */
|
63 | scrollToIndex?: number;
|
64 | /** Vertical offset. */
|
65 | scrollTop?: number;
|
66 | /** Optional inline style */
|
67 | style?: React.CSSProperties;
|
68 | /** Tab index for focus */
|
69 | tabIndex?: number | null;
|
70 | /** Width of list */
|
71 | width: number;
|
72 | };
|
73 | /**
|
74 | * It is inefficient to create and manage a large list of DOM elements within a scrolling container
|
75 | * if only a few of those elements are visible. The primary purpose of this component is to improve
|
76 | * performance by only rendering the DOM nodes that a user is able to see based on their current
|
77 | * scroll position.
|
78 | *
|
79 | * This component renders a virtualized list of elements with either fixed or dynamic heights.
|
80 | */
|
81 | export class List extends PureComponent<ListProps> {
|
82 | static defaultProps: {
|
83 | autoHeight: false;
|
84 | estimatedRowSize: 30;
|
85 | onScroll: () => void;
|
86 | noRowsRenderer: () => null;
|
87 | onRowsRendered: () => void;
|
88 | overscanIndicesGetter: OverscanIndicesGetter;
|
89 | overscanRowCount: 10;
|
90 | scrollToAlignment: 'auto';
|
91 | scrollToIndex: -1;
|
92 | style: {};
|
93 | };
|
94 |
|
95 | Grid?: Grid;
|
96 |
|
97 | forceUpdateGrid(): void;
|
98 |
|
99 |
|
100 | getOffsetForRow(params: { alignment?: Alignment; index?: number }): number;
|
101 |
|
102 |
|
103 | invalidateCellSizeAfterRender({ columnIndex, rowIndex }: CellPosition): void;
|
104 |
|
105 |
|
106 | measureAllRows(): void;
|
107 |
|
108 |
|
109 | recomputeGridSize(params?: Partial<CellPosition>): void;
|
110 |
|
111 |
|
112 | recomputeRowHeights(index?: number): void;
|
113 |
|
114 |
|
115 | scrollToPosition(scrollTop?: number): void;
|
116 |
|
117 |
|
118 | scrollToRow(index?: number): void;
|
119 | }
|
120 |
|
121 | export default List;
|