UNPKG

2.65 kBTypeScriptView Raw
1import { PureComponent, Validator, Requireable } from 'react';
2import * as PropTypes from 'prop-types';
3
4export type Size = {
5 height: number;
6 width: number;
7};
8export type Dimensions = Size;
9
10export type AutoSizerProps = {
11 /**
12 * Function responsible for rendering children.
13 * This function should implement the following signature:
14 * ({ height, width }) => PropTypes.element
15 */
16 children: (props: Size) => React.ReactNode;
17 /**
18 * Optional custom CSS class name to attach to root AutoSizer element.
19 * This is an advanced property and is not typically necessary.
20 */
21 className?: string | undefined;
22 /**
23 * Height passed to child for initial render; useful for server-side rendering.
24 * This value will be overridden with an accurate height after mounting.
25 */
26 defaultHeight?: number | undefined;
27 /**
28 * Width passed to child for initial render; useful for server-side rendering.
29 * This value will be overridden with an accurate width after mounting.
30 */
31 defaultWidth?: number | undefined;
32 /** Disable dynamic :height property */
33 disableHeight?: boolean | undefined;
34 /** Disable dynamic :width property */
35 disableWidth?: boolean | undefined;
36 /** Nonce of the inlined stylesheet for Content Security Policy */
37 nonce?: string | undefined;
38 /** Callback to be invoked on-resize: ({ height, width }) */
39 onResize?: ((info: Size) => any) | undefined;
40 /**
41 * Optional custom inline style to attach to root AutoSizer element.
42 * This is an advanced property and is not typically necessary.
43 */
44 style?: React.CSSProperties | undefined;
45 /**
46 * PLEASE NOTE
47 * The [key: string]: any; line is here on purpose
48 * This is due to the need of force re-render of PureComponent
49 * Check the following link if you want to know more
50 * https://github.com/bvaughn/react-virtualized#pass-thru-props
51 */
52 [key: string]: any;
53};
54/**
55 * Decorator component that automatically adjusts the width and height of a single child.
56 * Child component should not be declared as a child but should rather be specified by a `ChildComponent` property.
57 * All other properties will be passed through to the child component.
58 */
59export class AutoSizer extends PureComponent<AutoSizerProps, Size> {
60 static defaultProps: {
61 onResize: () => void;
62 disableHeight: false;
63 disableWidth: false;
64 style: {};
65 };
66
67 constructor(props: AutoSizerProps);
68
69 componentDidMount(): void;
70
71 componentWillUnmount(): void;
72
73 render(): JSX.Element;
74}
75
76export default AutoSizer;