@@ -221,7 +221,7 @@ export function getItemStyles(
221
221
} ;
222
222
}
223
223
224
- export function getScaleItemStyles ( style : CSSProperties , scale : number ) {
224
+ export function getScaleItemStyles ( style : CSSProperties , scale : number , offset : [ number , number ] = [ 0 , 0 ] ) {
225
225
if ( scale >= 1 ) {
226
226
return {
227
227
transform : `scale(${ scale } )` ,
@@ -231,8 +231,8 @@ export function getScaleItemStyles(style: CSSProperties, scale: number) {
231
231
}
232
232
const width = ( style . width as number ) * ( 1 / scale ) ;
233
233
const height = ( style . height as number ) * ( 1 / scale ) ;
234
- const x = - ( ( ( width as number ) * ( 1 - scale ) ) / 2 ) ;
235
- const y = - ( ( ( height as number ) * ( 1 - scale ) ) / 2 ) ;
234
+ const x = - ( ( ( width as number ) * ( 1 - scale ) ) / 2 ) + offset [ 0 ] ;
235
+ const y = - ( ( ( height as number ) * ( 1 - scale ) ) / 2 ) + offset [ 1 ] ;
236
236
return {
237
237
transform : `translate(${ x } px, ${ y } px) scale(${ scale } )` ,
238
238
width : width ,
@@ -257,7 +257,7 @@ export function renderItem(
257
257
258
258
export function dragPreview (
259
259
itemRender : SortableItemRender < any > ,
260
- options : { props ?: any ; scale ?: number | ( ( ) => number ) } = { }
260
+ options : { props ?: any ; offset ?: [ number , number ] ; scale ?: number | ( ( ) => number ) } = { }
261
261
) : DragPreviewRenderer {
262
262
return ( data , { style } ) => {
263
263
const props = { data, drag : ( ) => undefined , ...options } as any ;
@@ -266,7 +266,11 @@ export function dragPreview(
266
266
< div className = "sortable-drag-preview" style = { style } >
267
267
< div
268
268
className = "sortable-drag-preview-container"
269
- style = { getScaleItemStyles ( style , typeof options . scale == 'function' ? options . scale ( ) : options . scale ) }
269
+ style = { getScaleItemStyles (
270
+ style ,
271
+ typeof options . scale == 'function' ? options . scale ( ) : options . scale ,
272
+ options . offset
273
+ ) }
270
274
>
271
275
{ renderItem ( itemRender , props ) }
272
276
</ div >
0 commit comments