UNPKG

2.3 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent } from "../../common";
3export type ResizeEntry = ResizeObserverEntry;
4/** `ResizeSensor` requires a single DOM element child and will error otherwise. */
5export interface ResizeSensorProps {
6 /**
7 * Single child, must be an element and not a string or fragment.
8 */
9 children: JSX.Element;
10 /**
11 * Callback invoked when the wrapped element resizes.
12 *
13 * The `entries` array contains an entry for each observed element. In the
14 * default case (no `observeParents`), the array will contain only one
15 * element: the single child of the `ResizeSensor`.
16 *
17 * Note that this method is called _asynchronously_ after a resize is
18 * detected and typically it will be called no more than once per frame.
19 */
20 onResize: (entries: ResizeObserverEntry[]) => void;
21 /**
22 * If `true`, all parent DOM elements of the container will also be
23 * observed for size changes. The array of entries passed to `onResize`
24 * will now contain an entry for each parent element up to the root of the
25 * document.
26 *
27 * Only enable this prop if a parent element resizes in a way that does
28 * not also cause the child element to resize.
29 *
30 * @default false
31 */
32 observeParents?: boolean;
33 /**
34 * If you attach a `ref` to the child yourself when rendering it, you must pass the
35 * same value here (otherwise, ResizeSensor won't be able to attach its own).
36 */
37 targetRef?: React.RefObject<HTMLElement>;
38}
39/**
40 * Resize sensor component.
41 *
42 * It requires a single DOM element child and will error otherwise.
43 *
44 * @see https://blueprintjs.com/docs/#core/components/resize-sensor
45 **/
46export declare class ResizeSensor extends AbstractPureComponent<ResizeSensorProps> {
47 static displayName: string;
48 private targetRef;
49 private prevElement;
50 private observer;
51 render(): React.ReactNode;
52 componentDidMount(): void;
53 componentDidUpdate(prevProps: ResizeSensorProps): void;
54 componentWillUnmount(): void;
55 /**
56 * Observe the DOM element, if defined and different from the currently
57 * observed element. Pass `force` argument to skip element checks and always
58 * re-observe.
59 */
60 private observeElement;
61}