superdesk-ui-framework 3.0.46 → 3.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+
3
+ interface IDimensions {
4
+ width: number;
5
+ }
6
+
7
+ interface IProps {
8
+ children: (props: IDimensions) => JSX.Element;
9
+ }
10
+
11
+ interface IState {
12
+ dimensions: IDimensions | 'not-initialized';
13
+ }
14
+
15
+ export class ResizeObserverComponent extends React.PureComponent<IProps, IState> {
16
+ el: HTMLDivElement | null | undefined;
17
+ observerInstance: any;
18
+
19
+ constructor(props: IProps) {
20
+ super(props);
21
+
22
+ this.state = {
23
+ dimensions: 'not-initialized',
24
+ };
25
+ }
26
+
27
+ componentDidMount() {
28
+ this.observerInstance = new ResizeObserver((entries) => {
29
+ this.setState({
30
+ dimensions: {
31
+ width: Math.floor(entries[0].contentRect.width),
32
+ },
33
+ });
34
+ });
35
+
36
+ this.observerInstance.observe(this.el);
37
+ }
38
+
39
+ componentWillUnmount() {
40
+ this.observerInstance.unobserve(this.el);
41
+ }
42
+
43
+ render() {
44
+ const {dimensions} = this.state;
45
+
46
+ return (
47
+ <div
48
+ ref={(el) => {
49
+ this.el = el;
50
+ }}
51
+ >
52
+ {
53
+ dimensions === 'not-initialized'
54
+ ? null
55
+ : this.props.children(dimensions)
56
+ }
57
+ </div>
58
+ );
59
+ }
60
+ }
@@ -97,6 +97,7 @@ export { MultiSelect } from './components/MultiSelect';
97
97
  export { ResizablePanels } from './components/ResizablePanels';
98
98
  export { WithPopover } from './components/WithPopover';
99
99
  export { Spacer, SpacerBlock } from './components/Spacer';
100
+ export { ResizeObserverComponent } from './components/ResizeObserverComponent';
100
101
  export { DragHandle } from './components/DragHandle';
101
102
 
102
103
  // declare non-typescript exports to prevent errors