|
|
@ -24,35 +24,29 @@ const type = 'DragableBodyRow'; |
|
|
|
|
|
|
|
const DragableBodyRow = ({ index, moveRow, className, style, ...restProps }) => { |
|
|
|
const ref = useRef(); |
|
|
|
const [{ isOver, dropClassName }, drop] = useDrop( |
|
|
|
() => ({ |
|
|
|
accept: type, |
|
|
|
collect: monitor => { |
|
|
|
const { index: dragIndex } = monitor.getItem() || {}; |
|
|
|
if (dragIndex === index) { |
|
|
|
return {}; |
|
|
|
} |
|
|
|
return { |
|
|
|
isOver: monitor.isOver(), |
|
|
|
dropClassName: dragIndex < index ? ' drop-over-downward' : ' drop-over-upward', |
|
|
|
}; |
|
|
|
}, |
|
|
|
drop: item => { |
|
|
|
moveRow(item.index, index); |
|
|
|
}, |
|
|
|
}), |
|
|
|
[index], |
|
|
|
); |
|
|
|
const [, drag] = useDrag( |
|
|
|
() => ({ |
|
|
|
type, |
|
|
|
item: { index }, |
|
|
|
collect: monitor => ({ |
|
|
|
isDragging: monitor.isDragging(), |
|
|
|
}), |
|
|
|
const [{ isOver, dropClassName }, drop] = useDrop({ |
|
|
|
accept: type, |
|
|
|
collect: monitor => { |
|
|
|
const { index: dragIndex } = monitor.getItem() || {}; |
|
|
|
if (dragIndex === index) { |
|
|
|
return {}; |
|
|
|
} |
|
|
|
return { |
|
|
|
isOver: monitor.isOver(), |
|
|
|
dropClassName: dragIndex < index ? ' drop-over-downward' : ' drop-over-upward', |
|
|
|
}; |
|
|
|
}, |
|
|
|
drop: item => { |
|
|
|
moveRow(item.index, index); |
|
|
|
}, |
|
|
|
}); |
|
|
|
const [, drag] = useDrag({ |
|
|
|
type, |
|
|
|
item: { index }, |
|
|
|
collect: monitor => ({ |
|
|
|
isDragging: monitor.isDragging(), |
|
|
|
}), |
|
|
|
[index], |
|
|
|
); |
|
|
|
}); |
|
|
|
drop(drag(ref)); |
|
|
|
|
|
|
|
return ( |
|
|
|