index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  2. import Trigger from '@rc-component/trigger';
  3. import classNames from 'classnames';
  4. import * as React from 'react';
  5. import { getRealPlacement } from "../utils/uiUtil";
  6. import PickerContext from "../PickerInput/context";
  7. var BUILT_IN_PLACEMENTS = {
  8. bottomLeft: {
  9. points: ['tl', 'bl'],
  10. offset: [0, 4],
  11. overflow: {
  12. adjustX: 1,
  13. adjustY: 1
  14. }
  15. },
  16. bottomRight: {
  17. points: ['tr', 'br'],
  18. offset: [0, 4],
  19. overflow: {
  20. adjustX: 1,
  21. adjustY: 1
  22. }
  23. },
  24. topLeft: {
  25. points: ['bl', 'tl'],
  26. offset: [0, -4],
  27. overflow: {
  28. adjustX: 0,
  29. adjustY: 1
  30. }
  31. },
  32. topRight: {
  33. points: ['br', 'tr'],
  34. offset: [0, -4],
  35. overflow: {
  36. adjustX: 0,
  37. adjustY: 1
  38. }
  39. }
  40. };
  41. function PickerTrigger(_ref) {
  42. var popupElement = _ref.popupElement,
  43. popupStyle = _ref.popupStyle,
  44. popupClassName = _ref.popupClassName,
  45. popupAlign = _ref.popupAlign,
  46. transitionName = _ref.transitionName,
  47. getPopupContainer = _ref.getPopupContainer,
  48. children = _ref.children,
  49. range = _ref.range,
  50. placement = _ref.placement,
  51. _ref$builtinPlacement = _ref.builtinPlacements,
  52. builtinPlacements = _ref$builtinPlacement === void 0 ? BUILT_IN_PLACEMENTS : _ref$builtinPlacement,
  53. direction = _ref.direction,
  54. visible = _ref.visible,
  55. onClose = _ref.onClose;
  56. var _React$useContext = React.useContext(PickerContext),
  57. prefixCls = _React$useContext.prefixCls;
  58. var dropdownPrefixCls = "".concat(prefixCls, "-dropdown");
  59. var realPlacement = getRealPlacement(placement, direction === 'rtl');
  60. return /*#__PURE__*/React.createElement(Trigger, {
  61. showAction: [],
  62. hideAction: ['click'],
  63. popupPlacement: realPlacement,
  64. builtinPlacements: builtinPlacements,
  65. prefixCls: dropdownPrefixCls,
  66. popupTransitionName: transitionName,
  67. popup: popupElement,
  68. popupAlign: popupAlign,
  69. popupVisible: visible,
  70. popupClassName: classNames(popupClassName, _defineProperty(_defineProperty({}, "".concat(dropdownPrefixCls, "-range"), range), "".concat(dropdownPrefixCls, "-rtl"), direction === 'rtl')),
  71. popupStyle: popupStyle,
  72. stretch: "minWidth",
  73. getPopupContainer: getPopupContainer,
  74. onPopupVisibleChange: function onPopupVisibleChange(nextVisible) {
  75. if (!nextVisible) {
  76. onClose();
  77. }
  78. }
  79. }, children);
  80. }
  81. export default PickerTrigger;