1 | import { JSX, PureComponent } from "react";
|
2 | import { Alignment, IndexRange, OverscanIndexRange } from "../../index";
|
3 | import { CellPosition } from "./CellMeasurer";
|
4 | import { Grid, GridCellProps, GridCoreProps, OverscanIndicesGetter } from "./Grid";
|
5 |
|
6 | export type ListRowProps = Pick<GridCellProps, Exclude<keyof GridCellProps, "rowIndex">> & {
|
7 | index: GridCellProps["rowIndex"];
|
8 | };
|
9 |
|
10 | export type ListRowRenderer = (props: ListRowProps) => React.ReactNode;
|
11 |
|
12 | export type RenderedRows = OverscanIndexRange & IndexRange;
|
13 |
|
14 | export type ListProps = GridCoreProps & {
|
15 |
|
16 | noRowsRenderer?: (() => JSX.Element) | undefined;
|
17 | /**
|
18 | * Callback invoked with information about the slice of rows that were just rendered.
|
19 | * ({ startIndex, stopIndex }): void
|
20 | */
|
21 | onRowsRendered?: ((info: RenderedRows) => void) | undefined;
|
22 | /** Responsible for rendering a row given an index; ({ index: number }): node */
|
23 | rowRenderer: ListRowRenderer;
|
24 | /** Row index to ensure visible (by forcefully scrolling if necessary) */
|
25 | scrollToIndex?: number | undefined;
|
26 | };
|
27 | /**
|
28 | * It is inefficient to create and manage a large list of DOM elements within a scrolling container
|
29 | * if only a few of those elements are visible. The primary purpose of this component is to improve
|
30 | * performance by only rendering the DOM nodes that a user is able to see based on their current
|
31 | * scroll position.
|
32 | *
|
33 | * This component renders a virtualized list of elements with either fixed or dynamic heights.
|
34 | */
|
35 | export class List extends PureComponent<ListProps> {
|
36 | static defaultProps: {
|
37 | autoHeight: false;
|
38 | estimatedRowSize: 30;
|
39 | onScroll: () => void;
|
40 | noRowsRenderer: () => null;
|
41 | onRowsRendered: () => void;
|
42 | overscanIndicesGetter: OverscanIndicesGetter;
|
43 | overscanRowCount: 10;
|
44 | scrollToAlignment: "auto";
|
45 | scrollToIndex: -1;
|
46 | style: {};
|
47 | };
|
48 |
|
49 | Grid?: Grid | undefined;
|
50 |
|
51 | forceUpdateGrid(): void;
|
52 |
|
53 |
|
54 | getOffsetForRow(params: { alignment?: Alignment | undefined; index?: number | undefined }): number;
|
55 |
|
56 |
|
57 | invalidateCellSizeAfterRender({ columnIndex, rowIndex }: CellPosition): void;
|
58 |
|
59 |
|
60 | measureAllRows(): void;
|
61 |
|
62 |
|
63 | recomputeGridSize(params?: Partial<CellPosition>): void;
|
64 |
|
65 |
|
66 | recomputeRowHeights(index?: number): void;
|
67 |
|
68 |
|
69 | scrollToPosition(scrollTop?: number): void;
|
70 |
|
71 |
|
72 | scrollToRow(index?: number): void;
|
73 | }
|
74 |
|
75 | export default List;
|