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 | undefined;
|
17 | |
18 |
|
19 |
|
20 |
|
21 | autoHeight?: boolean | undefined;
|
22 |
|
23 | className?: string | undefined;
|
24 | |
25 |
|
26 |
|
27 |
|
28 | estimatedRowSize?: number | undefined;
|
29 |
|
30 | height: number;
|
31 |
|
32 | noRowsRenderer?: (() => JSX.Element) | undefined;
|
33 | /**
|
34 | * Callback invoked with information about the slice of rows that were just rendered.
|
35 | * ({ startIndex, stopIndex }): void
|
36 | */
|
37 | onRowsRendered?: ((info: RenderedRows) => void) | undefined;
|
38 | /**
|
39 | * Number of rows to render above/below the visible bounds of the list.
|
40 | * These rows can help for smoother scrolling on touch devices.
|
41 | */
|
42 | overscanRowCount?: number | undefined;
|
43 | /**
|
44 | * Callback invoked whenever the scroll offset changes within the inner scrollable region.
|
45 | * This callback can be used to sync scrolling between lists, tables, or grids.
|
46 | * ({ clientHeight, scrollHeight, scrollTop }): void
|
47 | */
|
48 | onScroll?: ((params: OnScrollParams) => void) | undefined;
|
49 | /** See Grid#overscanIndicesGetter */
|
50 | overscanIndicesGetter?: OverscanIndicesGetter | undefined;
|
51 | /**
|
52 | * Either a fixed row height (number) or a function that returns the height of a row given its index.
|
53 | * ({ index: number }): number
|
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 | undefined;
|
62 | /** Row index to ensure visible (by forcefully scrolling if necessary) */
|
63 | scrollToIndex?: number | undefined;
|
64 | /** Vertical offset. */
|
65 | scrollTop?: number | undefined;
|
66 | /** Optional inline style */
|
67 | style?: React.CSSProperties | undefined;
|
68 | /** Tab index for focus */
|
69 | tabIndex?: number | null | undefined;
|
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 | undefined;
|
96 |
|
97 | forceUpdateGrid(): void;
|
98 |
|
99 |
|
100 | getOffsetForRow(params: { alignment?: Alignment | undefined; index?: number | undefined }): 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;
|