UNPKG

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