I am using the React Beautiful DND library to drag items(square divs) between columns or reordered in the same column. I followed their Egghead video tutorial to change the background color of the div as it's being dragged. When it gets dropped, it switches back to the default color of all other items. I want it to slowly fade(like 1 second maybe) to the default color after it is dropped.
Here is my current code styling for the div as it's being dragged and dropped. I added the transition line, that but is not doing anything.
const MyOrder = styled.div`
background-color: ${(props) =>
props.isDragging ? '#4FB740' : '#193DF4'};
transition: background-color 1s ease;
`;
I have tried adding this code to the onDragEnd
event:
setDroppedOrderID(theOrder.orderNumber);
setTimeout(() => {
setDroppedOrderID('');
}, 2000);
And I made the order div that gets dragged look like this:
<MyOrder
id={orderNumber}
className={`order size-${size} ${
droppedOrderID === orderNumber ? ' dropped' : ''
} ${palletLoc === 'OUTSIDE' ? 'outside' : ''}`}
But it is buggy if someone tries to drag the same item in less than the 2 second time interval.