forked from digidem/react-dimensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.jsx
60 lines (52 loc) · 1.29 KB
/
example.jsx
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { PropTypes } from 'react'
import ReactDom from 'react-dom'
import Dimensions from './index.jsx'
class MyComponent extends React.Component {
static propTypes = {
containerWidth: PropTypes.number.isRequired,
containerHeight: PropTypes.number.isRequired
}
render () {
return (
<div style={{
backgroundColor: 'LightGreen',
width: this.props.containerWidth,
height: this.props.containerHeight
}}>
{`${this.props.containerWidth}px x ${this.props.containerHeight}px`}
</div>
)
}
}
const EnhancedComponent = Dimensions({elementResize: true, className: 'react-dimensions-wrapper'})(MyComponent)
const div = document.createElement('div')
document.body.appendChild(div)
class Example extends React.Component {
state = {
right: 50
}
handleButtonClick = () => {
this.setState({
right: this.state.right === 50 ? 200 : 50
})
}
render () {
return (
<div>
<button onClick={this.handleButtonClick}>Resize container</button>
<div style={{
position: 'absolute',
top: 50,
right: this.state.right,
bottom: 50,
left: 50
}}>
<EnhancedComponent />
</div>
</div>
)
}
}
ReactDom.render((
<Example />
), div)