Debian Codegraph @

node/@patternfly/react-core/dist/esm/helpers/resizeObserver.d.ts

raw
1 /**
2 * This function creates a ResizeObserver used to handle resize events for the given containerRef. If ResizeObserver
3 * or the given containerRef are not available, a window resize event listener is used by default.
4 *
5 * Example 1:
6 *
7 * private containerRef = createRef<HTMLDivElement>();
8 * private observer: any = () => {};
9 *
10 * public componentDidMount() {
11 * this.observer = getResizeObserver(this.containerRef.current, this.handleResize, true);
12 * }
13 *
14 * public componentWillUnmount() {
15 * this.observer();
16 * }
17 *
18 * private handleResize = () => {
19 * if (this.containerRef.current && this.containerRef.current.clientWidth) {
20 * this.setState({ width: this.containerRef.current.clientWidth });
21 * }
22 * };
23 *
24 * public render() {
25 * return (
26 * <div ref={this.containerRef} >
27 * <Chart width={this.state.width} ... />
28 * </div>
29 * );
30 * }
31 *
32 * Example 2:
33 *
34 * private inputRef = createRef<HTMLInputElement>();
35 * private observer: any = () => {};
36 *
37 * public componentDidMount() {
38 * this.observer = getResizeObserver(this.inputRef.current, this.handleResize, true);
39 * }
40 *
41 * public componentWillUnmount() {
42 * this.observer();
43 * }
44 *
45 * private handleResize = () => {
46 * if (this.inputRef.current) {
47 * trimLeft(inputRef.current, String(this.props.value));
48 * }
49 * };
50 *
51 * public render() {
52 * return (
53 * <input ref={this.inputRef} ... />
54 * );
55 * }
56 *
57 * Example 3 - With debounced method passed in:
58 *
59 * public componentDidMount() {
60 * this.observer = getResizeObserver(this.inputRef.current, debounce(this.handleResize, 250));
61 * }
62 *
63 * @param {Element} containerRefElement The container reference to observe
64 * @param {Function} handleResize The function to call for resize events
65 * @param {boolean} useRequestAnimationFrame Whether to pass the handleResize function as a callback to requestAnimationFrame. Pass in true when the function passed in is not debounced.
66 * @return {Function} The function used to unobserve resize events
67 */
68 export declare const getResizeObserver: (containerRefElement: Element, handleResize: () => void, useRequestAnimationFrame?: boolean) => () => void;
69 //# sourceMappingURL=resizeObserver.d.ts.map