ant-design-vue/components/tooltip/placements.js

97 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-01-12 11:33:27 +08:00
import { placements as rcPlacements } from '../vc-tooltip/placements';
2018-01-11 18:53:51 +08:00
const autoAdjustOverflowEnabled = {
adjustX: 1,
adjustY: 1,
2019-01-12 11:33:27 +08:00
};
2018-01-11 18:53:51 +08:00
const autoAdjustOverflowDisabled = {
adjustX: 0,
adjustY: 0,
2019-01-12 11:33:27 +08:00
};
2018-01-11 18:53:51 +08:00
2019-01-12 11:33:27 +08:00
const targetOffset = [0, 0];
2018-01-11 18:53:51 +08:00
2019-01-12 11:33:27 +08:00
export function getOverflowOptions(autoAdjustOverflow) {
2018-01-11 18:53:51 +08:00
if (typeof autoAdjustOverflow === 'boolean') {
2019-01-12 11:33:27 +08:00
return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled;
2018-01-11 18:53:51 +08:00
}
return {
...autoAdjustOverflowDisabled,
...autoAdjustOverflow,
2019-01-12 11:33:27 +08:00
};
2018-01-11 18:53:51 +08:00
}
2019-01-12 11:33:27 +08:00
export default function getPlacements(config) {
const {
arrowWidth = 5,
horizontalArrowShift = 16,
verticalArrowShift = 12,
autoAdjustOverflow = true,
} = config;
2018-01-11 18:53:51 +08:00
const 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],
},
2019-01-12 11:33:27 +08:00
};
2018-01-11 18:53:51 +08:00
Object.keys(placementMap).forEach(key => {
2019-01-12 11:33:27 +08:00
placementMap[key] = config.arrowPointAtCenter
? {
...placementMap[key],
overflow: getOverflowOptions(autoAdjustOverflow),
targetOffset,
}
: {
...rcPlacements[key],
overflow: getOverflowOptions(autoAdjustOverflow),
};
placementMap[key].ignoreShake = true;
});
return placementMap;
2018-01-11 18:53:51 +08:00
}