6
6
} from '@dnd-kit/sortable'
7
7
import { CSS } from '@dnd-kit/utilities'
8
8
import { ReactFC } from '@formily/reactive-react'
9
- import React , { createContext , useContext } from 'react'
9
+ import React , { createContext , useContext , useMemo } from 'react'
10
10
11
11
export interface ISortableContainerProps {
12
12
list : any [ ]
@@ -76,7 +76,7 @@ export function SortableElement<T extends React.HTMLAttributes<HTMLElement>>(
76
76
const sortable = useSortable ( {
77
77
id : index + 1 ,
78
78
} )
79
- const { setNodeRef, transform, isDragging } = sortable
79
+ const { setNodeRef, transform, transition , isDragging } = sortable
80
80
if ( transform ) {
81
81
switch ( lockAxis ) {
82
82
case 'x' :
@@ -90,11 +90,38 @@ export function SortableElement<T extends React.HTMLAttributes<HTMLElement>>(
90
90
break
91
91
}
92
92
}
93
- const style = {
94
- ...props . style ,
95
- transform : CSS . Transform . toString ( transform ) ,
96
- zIndex : isDragging ? 999 : 0 ,
97
- }
93
+
94
+ const style = useMemo ( ( ) => {
95
+ const itemStyle : React . CSSProperties = {
96
+ position : 'relative' ,
97
+ touchAction : 'none' ,
98
+ zIndex : 1 ,
99
+ transform : `translate3d(${ transform ?. x || 0 } px, ${
100
+ transform ?. y || 0
101
+ } px, 0)`,
102
+ transition : `${ transform ? 'all 200ms ease' : '' } ` ,
103
+ }
104
+ const dragStyle = {
105
+ transition,
106
+ opacity : '0.8' ,
107
+ transform : `translate3d(${ transform ?. x || 0 } px, ${
108
+ transform ?. y || 0
109
+ } px, 0)`,
110
+ }
111
+
112
+ const computedStyle = isDragging
113
+ ? {
114
+ ...itemStyle ,
115
+ ...dragStyle ,
116
+ ...props . style ,
117
+ }
118
+ : {
119
+ ...itemStyle ,
120
+ ...props . style ,
121
+ }
122
+
123
+ return computedStyle
124
+ } , [ isDragging , transform , transition , props . style ] )
98
125
99
126
return (
100
127
< SortableItemContext . Provider value = { sortable } >
0 commit comments