11'use strict' ;
22var React = require ( 'react' ) ;
3- var Draggable = require ( 'react-draggable' ) ;
4- var PureRenderMixin = require ( 'react/lib/ReactComponentWithPureRenderMixin' ) ;
3+ var DraggableCore = require ( 'react-draggable' ) . DraggableCore ;
54var assign = require ( 'object-assign' ) ;
65var cloneElement = require ( './cloneElement' ) ;
76
87var Resizable = module . exports = React . createClass ( {
98 displayName : 'Resizable' ,
10- mixins : [ PureRenderMixin ] ,
119
1210 propTypes : {
1311 // Require that one and only one child be present.
@@ -31,22 +29,21 @@ var Resizable = module.exports = React.createClass({
3129 } ;
3230 } ,
3331
34- getInitialState : function ( ) {
32+ getInitialState ( ) {
3533 return {
3634 bounds : this . constraintsToBounds ( ) ,
37- initialWidth : this . props . width ,
38- initialHeight : this . props . height
35+ width : this . props . width ,
36+ height : this . props . height
3937 } ;
4038 } ,
4139
42- componentWillReceiveProps : function ( props ) {
40+ componentWillReceiveProps ( props : Object ) {
4341 if ( ! this . state . resizing ) {
4442 this . setState ( {
45- initialWidth : props . width ,
46- initialHeight : props . height ,
43+ width : props . width ,
44+ height : props . height ,
4745 bounds : this . constraintsToBounds ( )
4846 } ) ;
49- this . refs . draggable . resetState ( ) ;
5047 }
5148 } ,
5249
@@ -62,22 +59,25 @@ var Resizable = module.exports = React.createClass({
6259 } ;
6360 } ,
6461
65-
6662 /**
6763 * Wrapper around drag events to provide more useful data.
6864 *
6965 * @param {String } handlerName Handler name to wrap.
7066 * @return {Function } Handler function.
7167 */
72- resizeHandler ( handlerName ) {
68+ resizeHandler ( handlerName : string ) {
7369 var me = this ;
7470 return function ( e , { node, position} ) {
75- me . props [ handlerName ] && me . props [ handlerName ] ( e , { node, size : calcWH ( me . state , position ) } ) ;
71+ let width = me . state . width + position . deltaX , height = me . state . height + position . deltaY ;
72+ console . log ( position ) ;
73+ me . props [ handlerName ] && me . props [ handlerName ] ( e , { node, size : { width, height} } ) ;
7674
7775 if ( handlerName === 'onResizeStart' ) {
7876 me . setState ( { resizing : true } ) ;
7977 } else if ( handlerName === 'onResizeStop' ) {
8078 me . setState ( { resizing : false } ) ;
79+ } else {
80+ me . setState ( { width, height} ) ;
8181 }
8282 } ;
8383 } ,
@@ -92,7 +92,7 @@ var Resizable = module.exports = React.createClass({
9292 return cloneElement ( p . children , assign ( { } , p , {
9393 children : [
9494 p . children . props . children ,
95- < Draggable
95+ < DraggableCore
9696 { ...p . draggableOpts }
9797 ref = "draggable"
9898 onStop = { this . resizeHandler ( 'onResizeStop' ) }
@@ -101,18 +101,8 @@ var Resizable = module.exports = React.createClass({
101101 bounds = { this . state . bounds }
102102 >
103103 < span className = "react-resizable-handle" />
104- </ Draggable >
104+ </ DraggableCore >
105105 ]
106106 } ) ) ;
107107 }
108108} ) ;
109-
110- /**
111- * Parse left and top coordinates.
112- * @param {Number } options.left Left coordinate.
113- * @param {Number } options.top Top coordinate.
114- * @return {Object } Coordinates
115- */
116- function calcWH ( { initialWidth, initialHeight} , { left, top} ) {
117- return { width : initialWidth + left , height : initialHeight + top } ;
118- }
0 commit comments