UNPKG

@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration

Version:

An optional Pragmatic drag and drop package that enables rapid migration from react-beautiful-dnd to Pragmatic drag and drop

30 lines (29 loc) 532 B
const directionMapping = { horizontal: { rect: { start: 'left', end: 'right' } }, vertical: { rect: { start: 'top', end: 'bottom' } } }; /** * Computes the distance between two `DOMRect` instances. * * This is the shortest distance from the end of one to the start of the next. */ export function getDistance({ a, b, direction }) { const { rect } = directionMapping[direction]; return Math.max(a[rect.start], b[rect.start]) - Math.min(a[rect.end], b[rect.end]); }