UNPKG

3.02 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.getOverflowOptions = getOverflowOptions;
9exports["default"] = getPlacements;
10
11var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
13var _placements = require("rc-tooltip/lib/placements");
14
15var autoAdjustOverflowEnabled = {
16 adjustX: 1,
17 adjustY: 1
18};
19var autoAdjustOverflowDisabled = {
20 adjustX: 0,
21 adjustY: 0
22};
23var targetOffset = [0, 0];
24
25function getOverflowOptions(autoAdjustOverflow) {
26 if (typeof autoAdjustOverflow === 'boolean') {
27 return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled;
28 }
29
30 return (0, _extends2["default"])((0, _extends2["default"])({}, autoAdjustOverflowDisabled), autoAdjustOverflow);
31}
32
33function getPlacements(config) {
34 var _config$arrowWidth = config.arrowWidth,
35 arrowWidth = _config$arrowWidth === void 0 ? 5 : _config$arrowWidth,
36 _config$horizontalArr = config.horizontalArrowShift,
37 horizontalArrowShift = _config$horizontalArr === void 0 ? 16 : _config$horizontalArr,
38 _config$verticalArrow = config.verticalArrowShift,
39 verticalArrowShift = _config$verticalArrow === void 0 ? 8 : _config$verticalArrow,
40 autoAdjustOverflow = config.autoAdjustOverflow;
41 var placementMap = {
42 left: {
43 points: ['cr', 'cl'],
44 offset: [-4, 0]
45 },
46 right: {
47 points: ['cl', 'cr'],
48 offset: [4, 0]
49 },
50 top: {
51 points: ['bc', 'tc'],
52 offset: [0, -4]
53 },
54 bottom: {
55 points: ['tc', 'bc'],
56 offset: [0, 4]
57 },
58 topLeft: {
59 points: ['bl', 'tc'],
60 offset: [-(horizontalArrowShift + arrowWidth), -4]
61 },
62 leftTop: {
63 points: ['tr', 'cl'],
64 offset: [-4, -(verticalArrowShift + arrowWidth)]
65 },
66 topRight: {
67 points: ['br', 'tc'],
68 offset: [horizontalArrowShift + arrowWidth, -4]
69 },
70 rightTop: {
71 points: ['tl', 'cr'],
72 offset: [4, -(verticalArrowShift + arrowWidth)]
73 },
74 bottomRight: {
75 points: ['tr', 'bc'],
76 offset: [horizontalArrowShift + arrowWidth, 4]
77 },
78 rightBottom: {
79 points: ['bl', 'cr'],
80 offset: [4, verticalArrowShift + arrowWidth]
81 },
82 bottomLeft: {
83 points: ['tl', 'bc'],
84 offset: [-(horizontalArrowShift + arrowWidth), 4]
85 },
86 leftBottom: {
87 points: ['br', 'cl'],
88 offset: [-4, verticalArrowShift + arrowWidth]
89 }
90 };
91 Object.keys(placementMap).forEach(function (key) {
92 placementMap[key] = config.arrowPointAtCenter ? (0, _extends2["default"])((0, _extends2["default"])({}, placementMap[key]), {
93 overflow: getOverflowOptions(autoAdjustOverflow),
94 targetOffset: targetOffset
95 }) : (0, _extends2["default"])((0, _extends2["default"])({}, _placements.placements[key]), {
96 overflow: getOverflowOptions(autoAdjustOverflow)
97 });
98 placementMap[key].ignoreShake = true;
99 });
100 return placementMap;
101}
\No newline at end of file