1
1
import { default as React , PropTypes } from 'react' ;
2
2
import { DraggableCore } from 'react-draggable' ;
3
- import assign from 'object-assign' ;
4
3
import cloneElement from './cloneElement' ;
5
4
5
+ type Position = {
6
+ deltaX : number ,
7
+ deltaY : number
8
+ } ;
9
+ type State = {
10
+ aspectRatio : number ,
11
+ resizing : boolean ,
12
+ height : number ,
13
+ width : number ,
14
+ } ;
15
+
6
16
export default class Resizable extends React . Component {
17
+
7
18
static propTypes = {
8
19
//
9
20
// Required Props
@@ -40,8 +51,8 @@ export default class Resizable extends React.Component {
40
51
handleSize : [ 20 , 20 ]
41
52
} ;
42
53
43
- state = {
44
54
bounds : this . constraintsToBounds ( ) ,
55
+ state : State = {
45
56
width : this . props . width ,
46
57
height : this . props . height
47
58
} ;
@@ -74,8 +85,8 @@ export default class Resizable extends React.Component {
74
85
* @param {String } handlerName Handler name to wrap.
75
86
* @return {Function } Handler function.
76
87
*/
77
- resizeHandler ( handlerName : string ) {
78
- return ( e , { node, position} ) => {
88
+ resizeHandler ( handlerName : string ) : Function {
89
+ return ( e , { node, position} : { node : HTMLElement , position : Position } ) => {
79
90
let width = this . state . width + position . deltaX , height = this . state . height + position . deltaY ;
80
91
this . props [ handlerName ] && this . props [ handlerName ] ( e , { node, size : { width, height} } ) ;
81
92
@@ -89,17 +100,18 @@ export default class Resizable extends React.Component {
89
100
} ;
90
101
}
91
102
92
- render ( ) {
103
+ render ( ) : ReactElement {
93
104
let p = this . props ;
94
105
let className = p . className ?
95
106
`${ p . className } react-resizable` :
96
- 'react-resizable'
107
+ 'react-resizable' ;
97
108
98
109
// What we're doing here is getting the child of this element, and cloning it with this element's props.
99
110
// We are then defining its children as:
100
111
// Its original children (resizable's child's children), and
101
112
// A draggable handle.
102
- return cloneElement ( p . children , assign ( { } , p , {
113
+ return cloneElement ( p . children , {
114
+ ...p ,
103
115
className,
104
116
children : [
105
117
p . children . props . children ,
@@ -114,6 +126,6 @@ export default class Resizable extends React.Component {
114
126
< span className = "react-resizable-handle" />
115
127
</ DraggableCore >
116
128
]
117
- } ) ) ;
129
+ } ) ;
118
130
}
119
131
}
0 commit comments