1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react';
import { addEvent, removeEvent } from '../../utils/dom';
class RootPanel extends React.Component {
constructor(props, context) {
super(props, context);
this.attachNode = this::this.attachNode;
this.updateHeight = this::this.updateHeight;
this.state = {
height: 0,
};
}
componentDidMount() {
addEvent(window, 'resize', this.updateHeight); // eslint-disable-line no-undef
this.updateHeight();
}
componentWillUnmount() {
removeEvent(window, 'resize', this.updateHeight); // eslint-disable-line no-undef
}
updateHeight() {
const parentNode = this.node.parentNode;
this.setState({
height: parentNode.offsetHeight,
});
}
attachNode(node) {
this.node = node;
}
render() {
const { children, style, ...rest } = this.props;
return (
<div style={{ ...style, height: this.state.height }} {...rest} ref={this.attachNode}>{ children }</div>
);
}
}
export default RootPanel;