@@ -82,6 +82,7 @@ export interface ResizableProps {
8282 style ?: React . CSSProperties ;
8383 className ?: string ;
8484 grid ?: [ number , number ] ;
85+ gridGap ?: [ number , number ] ;
8586 snap ?: {
8687 x ?: number [ ] ;
8788 y ?: number [ ] ;
@@ -129,7 +130,11 @@ interface State {
129130}
130131
131132const clamp = ( n : number , min : number , max : number ) : number => Math . max ( Math . min ( n , max ) , min ) ;
132- const snap = ( n : number , size : number ) : number => Math . round ( n / size ) * size ;
133+ const snap = ( n : number , size : number , gridGap : number ) : number => {
134+ const v = Math . round ( n / size ) ;
135+
136+ return v * size + gridGap * ( v - 1 ) ;
137+ } ;
133138const hasDirection = ( dir : 'top' | 'right' | 'bottom' | 'left' , target : string ) : boolean =>
134139 new RegExp ( dir , 'i' ) . test ( target ) ;
135140
@@ -242,6 +247,7 @@ const definedProps = [
242247 'style' ,
243248 'className' ,
244249 'grid' ,
250+ 'gridGap' ,
245251 'snap' ,
246252 'bounds' ,
247253 'boundsByDirection' ,
@@ -373,6 +379,7 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
373379 } ,
374380 style : { } ,
375381 grid : [ 1 , 1 ] ,
382+ gridGap : [ 0 , 0 ] ,
376383 lockAspectRatio : false ,
377384 lockAspectRatioExtraWidth : 0 ,
378385 lockAspectRatioExtraHeight : 0 ,
@@ -803,8 +810,8 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
803810 newHeight = newSize . newHeight ;
804811
805812 if ( this . props . grid ) {
806- const newGridWidth = snap ( newWidth , this . props . grid [ 0 ] ) ;
807- const newGridHeight = snap ( newHeight , this . props . grid [ 1 ] ) ;
813+ const newGridWidth = snap ( newWidth , this . props . grid [ 0 ] , this . props . gridGap ? this . props . gridGap [ 0 ] : 0 ) ;
814+ const newGridHeight = snap ( newHeight , this . props . grid [ 1 ] , this . props . gridGap ? this . props . gridGap [ 1 ] : 0 ) ;
808815 const gap = this . props . snapGap || 0 ;
809816 const w = gap === 0 || Math . abs ( newGridWidth - newWidth ) <= gap ? newGridWidth : newWidth ;
810817 const h = gap === 0 || Math . abs ( newGridHeight - newHeight ) <= gap ? newGridHeight : newHeight ;
0 commit comments