placements.js 2.7 KB

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