UNPKG

2.63 kBTypeScriptView Raw
1import { PureComponent } from 'react';
2
3export type CellMeasurerCacheInterface = {
4 hasFixedWidth(): boolean;
5 hasFixedHeight(): boolean;
6 has(rowIndex: number, columnIndex: number): boolean;
7 set(rowIndex: number, columnIndex: number, width: number, height: number): void;
8 getHeight(rowIndex: number, columnIndex?: number): number;
9 getWidth(rowIndex: number, columnIndex?: number): number;
10};
11
12export type KeyMapper = (rowIndex: number, columnIndex: number) => any;
13
14export type CellMeasurerCacheParams = {
15 defaultHeight?: number;
16 defaultWidth?: number;
17 fixedHeight?: boolean;
18 fixedWidth?: boolean;
19 minHeight?: number;
20 minWidth?: number;
21 keyMapper?: KeyMapper;
22};
23export class CellMeasurerCache implements CellMeasurerCacheInterface {
24 constructor(params?: CellMeasurerCacheParams);
25 clear(rowIndex: number, columnIndex: number): void;
26 clearAll(): void;
27 columnWidth: (params: { index: number }) => number;
28 readonly defaultHeight: number;
29 readonly defaultWidth: number;
30 hasFixedHeight(): boolean;
31 hasFixedWidth(): boolean;
32 getHeight(rowIndex: number, columnIndex: number): number;
33 getWidth(rowIndex: number, columnIndex: number): number;
34 has(rowIndex: number, columnIndex: number): boolean;
35 rowHeight: (params: { index: number }) => number;
36 set(rowIndex: number, columnIndex: number, width: number, height: number): void;
37}
38
39export type CellPosition = {
40 columnIndex: number;
41 rowIndex: number;
42};
43
44export type MeasuredCellParent = {
45 invalidateCellSizeAfterRender?: (cell: CellPosition) => void;
46 recomputeGridSize?: (cell: CellPosition) => void;
47};
48
49export type CellMeasurerChildProps = {
50 measure: () => void,
51 registerChild?: (element: Element) => void
52}
53
54export type CellMeasurerProps = {
55 cache: CellMeasurerCacheInterface;
56 children: ((props: CellMeasurerChildProps) => React.ReactNode) | React.ReactNode;
57 columnIndex?: number;
58 index?: number;
59 parent: MeasuredCellParent;
60 rowIndex?: number;
61 style?: React.CSSProperties;
62 /**
63 * PLEASE NOTE
64 * The [key: string]: any; line is here on purpose
65 * This is due to the need of force re-render of PureComponent
66 * Check the following link if you want to know more
67 * https://github.com/bvaughn/react-virtualized#pass-thru-props
68 */
69 [key: string]: any;
70};
71/**
72 * Wraps a cell and measures its rendered content.
73 * Measurements are stored in a per-cell cache.
74 * Cached-content is not be re-measured.
75 */
76export class CellMeasurer extends PureComponent<CellMeasurerProps> {}
77
78export default CellMeasurer;
79
\No newline at end of file