import {useEffect} from 'react'; import * as React from 'react'; import {useSortable} from '@dnd-kit/sortable'; import theme from 'app/utils/theme'; import {Widget} from './types'; import WidgetCard from './widgetCard'; import WidgetWrapper from './widgetWrapper'; const initialStyles: React.ComponentProps['animate'] = { zIndex: 'auto', }; type Props = { widget: Widget; dragId: string; isEditing: boolean; onDelete: () => void; onEdit: () => void; }; function SortableWidget(props: Props) { const {widget, dragId, isEditing, onDelete, onEdit} = props; const { attributes, listeners, setNodeRef, transform, isDragging: currentWidgetDragging, isSorting, } = useSortable({ id: dragId, transition: null, }); useEffect(() => { if (!currentWidgetDragging) { return undefined; } document.body.style.cursor = 'grabbing'; return function cleanup() { document.body.style.cursor = ''; }; }, [currentWidgetDragging]); return ( { if (isEditing && !!transform) { return generatedTransform; } return 'none'; }} transition={{ duration: !currentWidgetDragging ? 0.25 : 0, easings: { type: 'spring', }, }} > ); } export default SortableWidget;