@@ -20,14 +20,15 @@ type DragCallbackData = {
2020} ;
2121export type ResizeCallbackData = {
2222 node : HTMLElement ,
23- size : { width : number , height : number }
23+ size : { width : number , height : number } ,
24+ handle : ResizeHandle
2425} ;
2526export type Props = {
2627 children : ReactElement < any > ,
2728 className ?: ?string ,
2829 width : number ,
2930 height : number ,
30- handle : ReactElement < any > ,
31+ handle : ReactElement < any > | ( resizeHandle : ResizeHandle ) => ReactElement < any > ,
3132 handleSize : [ number , number ] ,
3233 lockAspectRatio : boolean ,
3334 axis : Axis ,
@@ -183,12 +184,13 @@ export default class Resizable extends React.Component<Props, State> {
183184 const canDragX = ( this . props . axis === 'both' || this . props . axis === 'x' ) && [ 'n' , 's' ] . indexOf ( axis ) === - 1 ;
184185 const canDragY = ( this . props . axis === 'both' || this . props . axis === 'y' ) && [ 'e' , 'w' ] . indexOf ( axis ) === - 1 ;
185186
186- if ( axis [ 0 ] === 'n' ) {
187- deltaY = - deltaY ;
188- }
189- if ( axis [ axis . length - 1 ] === 'w' ) {
187+ // reverse delta if using top or left drag handles
188+ if ( canDragX && axis [ axis . length - 1 ] === 'w' ) {
190189 deltaX = - deltaX ;
191190 }
191+ if ( canDragY && axis [ 0 ] === 'n' ) {
192+ deltaY = - deltaY ;
193+ }
192194
193195 // Update w/h
194196 let width = this . state . width + ( canDragX ? deltaX : 0 ) ;
@@ -217,36 +219,29 @@ export default class Resizable extends React.Component<Props, State> {
217219 const hasCb = typeof this . props [ handlerName ] === 'function' ;
218220 if ( hasCb ) {
219221 if ( typeof e . persist === 'function' ) e . persist ( ) ;
220- this . setState ( newState , ( ) => this . props [ handlerName ] ( e , { node, size : { width, height} } ) ) ;
222+ this . setState ( newState , ( ) => this . props [ handlerName ] ( e , { node, size : { width, height} , handle : axis } ) ) ;
221223 } else {
222224 this . setState ( newState ) ;
223225 }
224226 } ;
225227 }
226228
227- renderResizeHandles ( ) : ReactNode {
228- const { draggableOpts , handle, resizeHandles } = this . props ;
229+ renderResizeHandle ( resizeHandle : ResizeHandle ) : ReactNode {
230+ const { handle} = this . props ;
229231 if ( handle ) {
232+ if ( typeof handle === 'function' ) {
233+ return handle ( resizeHandle ) ;
234+ }
230235 return handle ;
231236 }
232- return resizeHandles . map ( h => (
233- < DraggableCore
234- { ...draggableOpts }
235- key = { `resizableHandle-${ h } ` }
236- onStop = { this . resizeHandler ( 'onResizeStop' , h ) }
237- onStart = { this . resizeHandler ( 'onResizeStart' , h ) }
238- onDrag = { this . resizeHandler ( 'onResize' , h ) }
239- >
240- < span key = { h } className = { `react-resizable-handle react-resizable-handle-${ h } ` } />
241- </ DraggableCore >
242- ) ) ;
237+ return < span className = { `react-resizable-handle react-resizable-handle-${ resizeHandle } ` } /> ;
243238 }
244239
245240 render ( ) : ReactNode {
246241 // eslint-disable-next-line no-unused-vars
247- const { children, width , height , handle , handleSize,
242+ const { children, draggableOpts , width , height , handleSize,
248243 lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
249- onResizeStop, onResizeStart, ...p } = this . props ;
244+ onResizeStop, onResizeStart, resizeHandles , ...p } = this . props ;
250245
251246 const className = p . className ?
252247 `${ p . className } react-resizable` :
@@ -261,7 +256,17 @@ export default class Resizable extends React.Component<Props, State> {
261256 className,
262257 children : [
263258 children . props . children ,
264- this . renderResizeHandles ( )
259+ resizeHandles . map ( h => (
260+ < DraggableCore
261+ { ...draggableOpts }
262+ key = { `resizableHandle-${ h } ` }
263+ onStop = { this . resizeHandler ( 'onResizeStop' , h ) }
264+ onStart = { this . resizeHandler ( 'onResizeStart' , h ) }
265+ onDrag = { this . resizeHandler ( 'onResize' , h ) }
266+ >
267+ { this . renderResizeHandle ( h ) }
268+ </ DraggableCore >
269+ ) )
265270 ]
266271 } ) ;
267272 }
0 commit comments