placements.js 2.3 KB

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