@@ -14,28 +14,31 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
1414 absoluteTop : 0 ,
1515 } ;
1616
17- onClick = ( ) => {
17+ onResetClick = ( ) => {
1818 this . setState ( { width : 200 , height : 200 , absoluteWidth : 200 , absoluteHeight : 200 } ) ;
1919 } ;
2020
21+ // On top layout
2122 onResize = ( event , { element, size, handle} ) => {
2223 this . setState ( { width : size . width , height : size . height } ) ;
2324 } ;
25+
26+ // On bottom layout. Used to resize the center element around its flex parent.
2427 onResizeAbsolute = ( event , { element, size, handle} ) => {
2528 this . setState ( ( state ) => {
2629 let newLeft = state . absoluteLeft ;
2730 let newTop = state . absoluteTop ;
2831 const deltaHeight = size . height - state . absoluteHeight ;
2932 const deltaWidth = size . width - state . absoluteWidth ;
3033 if ( handle [ 0 ] === 'n' ) {
31- newTop -= deltaHeight / 2 ;
34+ newTop -= deltaHeight ;
3235 } else if ( handle [ 0 ] === 's' ) {
33- newTop += deltaHeight / 2 ;
36+ newTop += deltaHeight ;
3437 }
3538 if ( handle [ handle . length - 1 ] === 'w' ) {
36- newLeft -= deltaWidth / 2 ;
39+ newLeft -= deltaWidth ;
3740 } else if ( handle [ handle . length - 1 ] === 'e' ) {
38- newLeft += deltaWidth / 2 ;
41+ newLeft += deltaWidth ;
3942 }
4043
4144 return {
@@ -50,11 +53,13 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
5053 render ( ) {
5154 return (
5255 < div >
53- < button onClick = { this . onClick } style = { { 'marginBottom' : '10px' } } > Reset first element's width/height</ button >
56+
57+ < h3 > Statically Positioned Layout</ h3 >
5458 < div className = "layoutRoot" >
5559 < Resizable className = "box" height = { this . state . height } width = { this . state . width } onResize = { this . onResize } resizeHandles = { [ 'sw' , 'se' , 'nw' , 'ne' , 'w' , 'e' , 'n' , 's' ] } >
5660 < div className = "box" style = { { width : this . state . width + 'px' , height : this . state . height + 'px' } } >
5761 < span className = "text" > { "Raw use of <Resizable> element. 200x200, all Resize Handles." } </ span >
62+ < button onClick = { this . onResetClick } style = { { 'marginTop' : '10px' } } > Reset this element's width/height</ button >
5863 </ div >
5964 </ Resizable >
6065 < ResizableBox className = "box" width = { 200 } height = { 200 } >
@@ -66,7 +71,7 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
6671 height = { 200 }
6772 handle = { < span className = "custom-handle custom-handle-se" /> }
6873 handleSize = { [ 8 , 8 ] } >
69- < span className = "text" > { "<ResizableBox> with custom handle in SE corner." } </ span >
74+ < span className = "text" > { "<ResizableBox> with custom overflow style & handle in SE corner." } </ span >
7075 </ ResizableBox >
7176 < ResizableBox
7277 className = "custom-box box"
@@ -83,7 +88,7 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
8388 < ResizableBox className = "box" width = { 200 } height = { 200 } minConstraints = { [ 150 , 150 ] } maxConstraints = { [ 500 , 300 ] } >
8489 < span className = "text" > Resizable box, starting at 200x200. Min size is 150x150, max is 500x300.</ span >
8590 </ ResizableBox >
86- < ResizableBox className = "box box3 " width = { 200 } height = { 200 } minConstraints = { [ 150 , 150 ] } maxConstraints = { [ 500 , 300 ] } >
91+ < ResizableBox className = "box hover-handles " width = { 200 } height = { 200 } minConstraints = { [ 150 , 150 ] } maxConstraints = { [ 500 , 300 ] } >
8792 < span className = "text" > Resizable box with a handle that only appears on hover.</ span >
8893 </ ResizableBox >
8994 < ResizableBox className = "box" width = { 200 } height = { 200 } lockAspectRatio = { true } >
@@ -105,38 +110,41 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
105110 < span className = "text" > Not resizable ("none" axis).</ span >
106111 </ ResizableBox >
107112 </ div >
113+
114+ < h3 > Absolutely Positioned layout</ h3 >
108115 < div className = "layoutRoot absoluteLayout" >
109116 < ResizableBox className = "box absolutely-positioned top-aligned left-aligned" height = { 200 } width = { 200 } resizeHandles = { [ 'se' , 'e' , 's' ] } >
110- < span className = "text" > { " Top-left Aligned" } </ span >
117+ < span className = "text" > Top-left Aligned</ span >
111118 </ ResizableBox >
112119 < ResizableBox className = "box absolutely-positioned bottom-aligned left-aligned" height = { 200 } width = { 200 } resizeHandles = { [ 'ne' , 'e' , 'n' ] } >
113- < span className = "text" > { " Bottom-left Aligned" } </ span >
120+ < span className = "text" > Bottom-left Aligned</ span >
114121 </ ResizableBox >
122+ { /* See implementation of `onResizeAbsolute` for how this can be moved around its container */ }
115123 < Resizable
116- className = "box absolutely-positioned center-aligned "
124+ className = "box absolutely-positioned"
117125 height = { this . state . absoluteHeight }
118126 width = { this . state . absoluteWidth }
119127 onResize = { this . onResizeAbsolute }
120128 resizeHandles = { [ 'sw' , 'se' , 'nw' , 'ne' , 'w' , 'e' , 'n' , 's' ] }
121129 >
122130 < div
123- className = "box"
124131 style = { {
125132 width : this . state . absoluteWidth ,
126133 height : this . state . absoluteHeight ,
127134 margin : `${ this . state . absoluteTop } 0 0 ${ this . state . absoluteLeft } ` ,
128135 } }
129136 >
130- < span className = "text" > { "Raw use of <Resizable> element with controlled position. Resize and reposition in all directions" } </ span >
137+ < span className = "text" > { "Raw use of <Resizable> element with controlled position. Resize and reposition in all directions. " } </ span >
131138 </ div >
132139 </ Resizable >
133140 < ResizableBox className = "box absolutely-positioned top-aligned right-aligned" height = { 200 } width = { 200 } resizeHandles = { [ 'sw' , 'w' , 's' ] } >
134- < span className = "text" > { " Top-right Aligned" } </ span >
141+ < span className = "text" > Top-right Aligned</ span >
135142 </ ResizableBox >
136143 < ResizableBox className = "box absolutely-positioned bottom-aligned right-aligned" height = { 200 } width = { 200 } resizeHandles = { [ 'nw' , 'w' , 'n' ] } >
137- < span className = "text" > { " Bottom-right Aligned" } </ span >
144+ < span className = "text" > Bottom-right Aligned</ span >
138145 </ ResizableBox >
139146 </ div >
147+
140148 </ div >
141149 ) ;
142150 }
0 commit comments