2016-08-31 13:50:50 +08:00
|
|
|
import { placements } from 'rc-tooltip/lib/placements';
|
|
|
|
|
2016-03-09 17:23:10 +08:00
|
|
|
const autoAdjustOverflow = {
|
|
|
|
adjustX: 1,
|
|
|
|
adjustY: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
const targetOffset = [0, 0];
|
|
|
|
|
2016-07-29 14:45:06 +08:00
|
|
|
export interface GetPlacementsProps {
|
2016-08-31 15:00:13 +08:00
|
|
|
arrowWidth?: number;
|
|
|
|
horizontalArrowShift?: number;
|
|
|
|
verticalArrowShift?: number;
|
|
|
|
arrowPointAtCenter?: boolean;
|
2016-07-29 14:45:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function getPlacements(config: GetPlacementsProps = {}) {
|
2016-08-31 13:50:50 +08:00
|
|
|
if (!config.arrowPointAtCenter) {
|
|
|
|
return placements;
|
|
|
|
}
|
2016-03-09 17:23:10 +08:00
|
|
|
const { arrowWidth = 5, horizontalArrowShift = 16, verticalArrowShift = 12 } = config;
|
|
|
|
return {
|
|
|
|
left: {
|
|
|
|
points: ['cr', 'cl'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [-4, 0],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
right: {
|
|
|
|
points: ['cl', 'cr'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [4, 0],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
top: {
|
|
|
|
points: ['bc', 'tc'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [0, -4],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
bottom: {
|
|
|
|
points: ['tc', 'bc'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [0, 4],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
topLeft: {
|
|
|
|
points: ['bl', 'tc'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [-(horizontalArrowShift + arrowWidth), -4],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
leftTop: {
|
|
|
|
points: ['tr', 'cl'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [-4, -(verticalArrowShift + arrowWidth)],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
topRight: {
|
|
|
|
points: ['br', 'tc'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [horizontalArrowShift + arrowWidth, -4],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
rightTop: {
|
|
|
|
points: ['tl', 'cr'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [4, -(verticalArrowShift + arrowWidth)],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
bottomRight: {
|
|
|
|
points: ['tr', 'bc'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [horizontalArrowShift + arrowWidth, 4],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
rightBottom: {
|
|
|
|
points: ['bl', 'cr'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [4, verticalArrowShift + arrowWidth],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
bottomLeft: {
|
|
|
|
points: ['tl', 'bc'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [-(horizontalArrowShift + arrowWidth), 4],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
leftBottom: {
|
|
|
|
points: ['br', 'cl'],
|
|
|
|
overflow: autoAdjustOverflow,
|
|
|
|
offset: [-4, verticalArrowShift + arrowWidth],
|
|
|
|
targetOffset,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|