placements.js 2.6 KB

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