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.
112 lines
2.5 KiB
112 lines
2.5 KiB
3 years ago
|
import { placements } from '../vc-tooltip/src/placements';
|
||
7 years ago
|
|
||
|
const autoAdjustOverflowEnabled = {
|
||
|
adjustX: 1,
|
||
|
adjustY: 1,
|
||
6 years ago
|
};
|
||
7 years ago
|
|
||
|
const autoAdjustOverflowDisabled = {
|
||
|
adjustX: 0,
|
||
|
adjustY: 0,
|
||
6 years ago
|
};
|
||
7 years ago
|
|
||
6 years ago
|
const targetOffset = [0, 0];
|
||
7 years ago
|
|
||
3 years ago
|
export interface AdjustOverflow {
|
||
|
adjustX?: 0 | 1;
|
||
|
adjustY?: 0 | 1;
|
||
|
}
|
||
|
|
||
|
export interface PlacementsConfig {
|
||
4 years ago
|
arrowWidth?: number;
|
||
|
horizontalArrowShift?: number;
|
||
3 years ago
|
verticalArrowShift?: number;
|
||
|
arrowPointAtCenter?: boolean;
|
||
|
autoAdjustOverflow?: boolean | AdjustOverflow;
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
export function getOverflowOptions(autoAdjustOverflow?: boolean | AdjustOverflow) {
|
||
7 years ago
|
if (typeof autoAdjustOverflow === 'boolean') {
|
||
6 years ago
|
return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled;
|
||
7 years ago
|
}
|
||
|
return {
|
||
|
...autoAdjustOverflowDisabled,
|
||
|
...autoAdjustOverflow,
|
||
6 years ago
|
};
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
export default function getPlacements(config: PlacementsConfig) {
|
||
6 years ago
|
const {
|
||
3 years ago
|
arrowWidth = 4,
|
||
6 years ago
|
horizontalArrowShift = 16,
|
||
3 years ago
|
verticalArrowShift = 8,
|
||
|
autoAdjustOverflow,
|
||
3 years ago
|
arrowPointAtCenter,
|
||
6 years ago
|
} = config;
|
||
7 years ago
|
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],
|
||
|
},
|
||
6 years ago
|
};
|
||
7 years ago
|
Object.keys(placementMap).forEach(key => {
|
||
3 years ago
|
placementMap[key] = arrowPointAtCenter
|
||
6 years ago
|
? {
|
||
|
...placementMap[key],
|
||
|
overflow: getOverflowOptions(autoAdjustOverflow),
|
||
|
targetOffset,
|
||
|
}
|
||
|
: {
|
||
3 years ago
|
...placements[key],
|
||
6 years ago
|
overflow: getOverflowOptions(autoAdjustOverflow),
|
||
|
};
|
||
3 years ago
|
|
||
6 years ago
|
placementMap[key].ignoreShake = true;
|
||
|
});
|
||
|
return placementMap;
|
||
7 years ago
|
}
|