placements.js 3.0 KB

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