You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.6 KiB
113 lines
2.6 KiB
5 years ago
|
import { placements } from 'rc-tooltip/lib/placements';
|
||
4 years ago
|
import { BuildInPlacements } from 'rc-trigger';
|
||
8 years ago
|
|
||
8 years ago
|
const autoAdjustOverflowEnabled = {
|
||
9 years ago
|
adjustX: 1,
|
||
|
adjustY: 1,
|
||
|
};
|
||
|
|
||
8 years ago
|
const autoAdjustOverflowDisabled = {
|
||
|
adjustX: 0,
|
||
|
adjustY: 0,
|
||
|
};
|
||
|
|
||
9 years ago
|
const targetOffset = [0, 0];
|
||
|
|
||
8 years ago
|
export interface AdjustOverflow {
|
||
|
adjustX?: 0 | 1;
|
||
|
adjustY?: 0 | 1;
|
||
|
}
|
||
|
|
||
8 years ago
|
export interface PlacementsConfig {
|
||
8 years ago
|
arrowWidth?: number;
|
||
|
horizontalArrowShift?: number;
|
||
|
verticalArrowShift?: number;
|
||
|
arrowPointAtCenter?: boolean;
|
||
6 years ago
|
autoAdjustOverflow?: boolean | AdjustOverflow;
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
export function getOverflowOptions(autoAdjustOverflow?: boolean | AdjustOverflow) {
|
||
8 years ago
|
if (typeof autoAdjustOverflow === 'boolean') {
|
||
|
return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled;
|
||
8 years ago
|
}
|
||
9 years ago
|
return {
|
||
8 years ago
|
...autoAdjustOverflowDisabled,
|
||
|
...autoAdjustOverflow,
|
||
|
};
|
||
|
}
|
||
|
|
||
5 years ago
|
export default function getPlacements(config: PlacementsConfig) {
|
||
6 years ago
|
const {
|
||
3 years ago
|
arrowWidth = 4,
|
||
6 years ago
|
horizontalArrowShift = 16,
|
||
5 years ago
|
verticalArrowShift = 8,
|
||
|
autoAdjustOverflow,
|
||
3 years ago
|
arrowPointAtCenter,
|
||
6 years ago
|
} = config;
|
||
4 years ago
|
const placementMap: BuildInPlacements = {
|
||
9 years ago
|
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],
|
||
|
},
|
||
|
};
|
||
8 years ago
|
Object.keys(placementMap).forEach(key => {
|
||
3 years ago
|
placementMap[key] = arrowPointAtCenter
|
||
6 years ago
|
? {
|
||
|
...placementMap[key],
|
||
|
overflow: getOverflowOptions(autoAdjustOverflow),
|
||
|
targetOffset,
|
||
|
}
|
||
|
: {
|
||
5 years ago
|
...placements[key],
|
||
6 years ago
|
overflow: getOverflowOptions(autoAdjustOverflow),
|
||
|
};
|
||
6 years ago
|
|
||
|
placementMap[key].ignoreShake = true;
|
||
8 years ago
|
});
|
||
|
return placementMap;
|
||
9 years ago
|
}
|