UNPKG

ultra-design

Version:
68 lines (66 loc) 2.13 kB
var getPosition = function getPosition(placement, rect, offset) { var placementPositions = { topLeft: { top: "".concat(rect.top - offset, "px"), left: "".concat(rect.left, "px"), transform: 'translate(0, -100%)' }, top: { top: "".concat(rect.top - offset, "px"), left: "".concat(rect.left + rect.width / 2, "px"), transform: 'translate(-50%, -100%)' }, topRight: { top: "".concat(rect.top - offset, "px"), left: "".concat(rect.left + rect.width, "px"), transform: 'translate(-100%, -100%)' }, rightTop: { top: "".concat(rect.top, "px"), left: "".concat(rect.left + rect.width + offset, "px"), transform: 'translate(0, 0)' }, right: { top: "".concat(rect.top + rect.height / 2, "px"), left: "".concat(rect.left + rect.width + offset, "px"), transform: 'translate(0, -50%)' }, rightBottom: { top: "".concat(rect.top + rect.height, "px"), left: "".concat(rect.left + rect.width + offset, "px"), transform: 'translate(0, -100%)' }, bottomRight: { top: "".concat(rect.bottom + offset, "px"), left: "".concat(rect.left + rect.width, "px"), transform: 'translate(-100%, 0)' }, bottom: { top: "".concat(rect.bottom + offset, "px"), left: "".concat(rect.left + rect.width / 2, "px"), transform: 'translate(-50%, 0)' }, bottomLeft: { top: "".concat(rect.bottom + offset, "px"), left: "".concat(rect.left, "px"), transform: 'translate(0, 0)' }, leftBottom: { top: "".concat(rect.top + rect.height, "px"), left: "".concat(rect.left - offset, "px"), transform: 'translate(-100%, -100%)' }, left: { top: "".concat(rect.top + rect.height / 2, "px"), left: "".concat(rect.left - offset, "px"), transform: 'translate(-100%, -50%)' }, leftTop: { top: "".concat(rect.top, "px"), left: "".concat(rect.left - offset, "px"), transform: 'translate(-100%, 0)' } }; return placementPositions[placement]; }; export { getPosition };