| 1 |
/** |
| 2 |
* @function |
| 3 |
* @memberof Modifiers |
| 4 |
* @argument {Object} data - The data object generated by `update` method |
| 5 |
* @argument {Object} options - Modifiers configuration and options |
| 6 |
* @returns {Object} The data object, properly modified |
| 7 |
*/ |
| 8 |
export default function shift(data) { |
| 9 |
const placement = data.placement; |
| 10 |
const basePlacement = placement.split('-')[0]; |
| 11 |
const shiftvariation = placement.split('-')[1]; |
| 12 |
|
| 13 |
// if shift shiftvariation is specified, run the modifier |
| 14 |
if (shiftvariation) { |
| 15 |
const { reference, popper } = data.offsets; |
| 16 |
const isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1; |
| 17 |
const side = isVertical ? 'left' : 'top'; |
| 18 |
const measurement = isVertical ? 'width' : 'height'; |
| 19 |
|
| 20 |
const shiftOffsets = { |
| 21 |
start: { [side]: reference[side] }, |
| 22 |
end: { |
| 23 |
[side]: reference[side] + reference[measurement] - popper[measurement], |
| 24 |
}, |
| 25 |
}; |
| 26 |
|
| 27 |
data.offsets.popper = { ...popper, ...shiftOffsets[shiftvariation] }; |
| 28 |
} |
| 29 |
|
| 30 |
return data; |
| 31 |
} |