ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
87 lines • 2.73 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { placements } from '../vc-tooltip/src/placements';
var autoAdjustOverflowEnabled = {
adjustX: 1,
adjustY: 1
};
var autoAdjustOverflowDisabled = {
adjustX: 0,
adjustY: 0
};
var targetOffset = [0, 0];
export function getOverflowOptions(autoAdjustOverflow) {
if (typeof autoAdjustOverflow === 'boolean') {
return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled;
}
return _objectSpread(_objectSpread({}, autoAdjustOverflowDisabled), autoAdjustOverflow);
}
export default function getPlacements(config) {
var _config$arrowWidth = config.arrowWidth,
arrowWidth = _config$arrowWidth === void 0 ? 4 : _config$arrowWidth,
_config$horizontalArr = config.horizontalArrowShift,
horizontalArrowShift = _config$horizontalArr === void 0 ? 16 : _config$horizontalArr,
_config$verticalArrow = config.verticalArrowShift,
verticalArrowShift = _config$verticalArrow === void 0 ? 8 : _config$verticalArrow,
autoAdjustOverflow = config.autoAdjustOverflow,
arrowPointAtCenter = config.arrowPointAtCenter;
var placementMap = {
left: {
points: ['cr', 'cl'],
offset: [-4, 0]
},
right: {
points: ['cl', 'cr'],
offset: [4, 0]
},
top: {
points: ['bc', 'tc'],
offset: [0, -4]
},
bottom: {
points: ['tc', 'bc'],
offset: [0, 4]
},
topLeft: {
points: ['bl', 'tc'],
offset: [-(horizontalArrowShift + arrowWidth), -4]
},
leftTop: {
points: ['tr', 'cl'],
offset: [-4, -(verticalArrowShift + arrowWidth)]
},
topRight: {
points: ['br', 'tc'],
offset: [horizontalArrowShift + arrowWidth, -4]
},
rightTop: {
points: ['tl', 'cr'],
offset: [4, -(verticalArrowShift + arrowWidth)]
},
bottomRight: {
points: ['tr', 'bc'],
offset: [horizontalArrowShift + arrowWidth, 4]
},
rightBottom: {
points: ['bl', 'cr'],
offset: [4, verticalArrowShift + arrowWidth]
},
bottomLeft: {
points: ['tl', 'bc'],
offset: [-(horizontalArrowShift + arrowWidth), 4]
},
leftBottom: {
points: ['br', 'cl'],
offset: [-4, verticalArrowShift + arrowWidth]
}
};
Object.keys(placementMap).forEach(function (key) {
placementMap[key] = arrowPointAtCenter ? _objectSpread(_objectSpread({}, placementMap[key]), {}, {
overflow: getOverflowOptions(autoAdjustOverflow),
targetOffset: targetOffset
}) : _objectSpread(_objectSpread({}, placements[key]), {}, {
overflow: getOverflowOptions(autoAdjustOverflow)
});
placementMap[key].ignoreShake = true;
});
return placementMap;
}