-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplacements.js
88 lines (83 loc) · 2.12 KB
/
placements.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { placements as rcPlacements } from '../vc-tooltip/placements'
const autoAdjustOverflowEnabled = {
adjustX: 1,
adjustY: 1,
}
const autoAdjustOverflowDisabled = {
adjustX: 0,
adjustY: 0,
}
const targetOffset = [0, 0]
export function getOverflowOptions (autoAdjustOverflow) {
if (typeof autoAdjustOverflow === 'boolean') {
return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled
}
return {
...autoAdjustOverflowDisabled,
...autoAdjustOverflow,
}
}
export default function getPlacements (config) {
const { arrowWidth = 5, horizontalArrowShift = 16, verticalArrowShift = 12, autoAdjustOverflow = true } = config
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],
},
}
Object.keys(placementMap).forEach(key => {
placementMap[key] = config.arrowPointAtCenter ? {
...placementMap[key],
overflow: getOverflowOptions(autoAdjustOverflow),
targetOffset,
} : {
...rcPlacements[key],
overflow: getOverflowOptions(autoAdjustOverflow),
}
})
return placementMap
}