UNPKG

1.88 kBTypeScriptView Raw
1import { PureComponent, Validator, Requireable } from 'react';
2
3export type SizedColumnProps = {
4 adjustedWidth: number;
5 columnWidth: number;
6 getColumnWidth: () => number;
7 registerChild: any;
8};
9
10export type ColumnSizerProps = {
11 /**
12 * Function responsible for rendering a virtualized Grid.
13 * This function should implement the following signature:
14 * ({ adjustedWidth, getColumnWidth, registerChild }) => PropTypes.element
15 *
16 * The specified :getColumnWidth function should be passed to the Grid's :columnWidth property.
17 * The :registerChild should be passed to the Grid's :ref property.
18 * The :adjustedWidth property is optional; it reflects the lesser of the overall width or the width of all columns.
19 */
20 children: (props: SizedColumnProps) => React.ReactNode;
21 /** Optional maximum allowed column width */
22 columnMaxWidth?: number;
23 /** Optional minimum allowed column width */
24 columnMinWidth?: number;
25 /** Number of columns in Grid or Table child */
26 columnCount?: number;
27 /** Width of Grid or Table child */
28 width: number;
29 /**
30 * PLEASE NOTE
31 * The [key: string]: any; line is here on purpose
32 * This is due to the need of force re-render of PureComponent
33 * Check the following link if you want to know more
34 * https://github.com/bvaughn/react-virtualized#pass-thru-props
35 */
36 [key: string]: any;
37};
38/**
39 * High-order component that auto-calculates column-widths for `Grid` cells.
40 */
41export class ColumnSizer extends PureComponent<ColumnSizerProps> {
42 static propTypes: {
43 children: Validator<(props: SizedColumnProps) => React.ReactNode>;
44 columnMaxWidth: Requireable<number>;
45 columnMinWidth: Requireable<number>;
46 columnCount: Validator<number>;
47 width: Validator<number>;
48 };
49}
50
51export default ColumnSizer;