@@ -4,6 +4,8 @@ var PropTypes = React.PropTypes;
44var Resizable = require ( './Resizable' ) ;
55
66// An example use of Resizable.
7+ type Size = { width : number , height : number } ;
8+ type ResizeData = { element : Element , size : Size } ;
79var ResizableBox = module . exports = React . createClass ( {
810 displayName : 'ResizableBox' ,
911
@@ -30,28 +32,28 @@ var ResizableBox = module.exports = React.createClass({
3032 } ;
3133 } ,
3234
33- onResize ( event , { element, size} ) {
35+ onResize ( event : Event , { element, size} : ResizeData ) {
3436 var { width, height} = size ;
3537 var widthChanged = width !== this . state . width , heightChanged = height !== this . state . height ;
3638 if ( ! widthChanged && ! heightChanged ) return ;
3739
38- if ( this . props . lockAspectRatio ) {
39- [ width , height ] = this . preserveAspectRatio ( width , height ) ;
40- }
40+ [ width , height ] = this . runConstraints ( width , height ) ;
4141
4242 this . setState ( { width, height} , ( ) => {
43- if ( this . props . onResize ) {
44- this . props . onResize ( event , { element, size : { width, height} } ) ;
45- }
43+ if ( this . props . onResize ) {
44+ this . props . onResize ( event , { element, size : { width, height} } ) ;
45+ }
4646 } ) ;
4747 } ,
4848
4949 // If you do this, be careful of constraints
50- preserveAspectRatio ( width : number , height : number ) {
50+ runConstraints ( width : number , height : number ) {
5151 var [ min , max ] = [ this . props . minConstraints , this . props . maxConstraints ] ;
5252
53- height = width / this . state . aspectRatio ;
54- width = height * this . state . aspectRatio ;
53+ if ( this . props . lockAspectRatio ) {
54+ height = width / this . state . aspectRatio ;
55+ width = height * this . state . aspectRatio ;
56+ }
5557
5658 if ( min ) {
5759 width = Math . max ( min [ 0 ] , width ) ;
0 commit comments