UNPKG

2.86 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2import _createClass from "@babel/runtime/helpers/esm/createClass";
3import _inherits from "@babel/runtime/helpers/esm/inherits";
4import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5import Trigger from 'rc-trigger';
6import * as React from 'react';
7import DropdownMenu from './DropdownMenu';
8var BUILT_IN_PLACEMENTS = {
9 bottomRight: {
10 points: ['tl', 'br'],
11 offset: [0, 4],
12 overflow: {
13 adjustX: 0,
14 adjustY: 1
15 }
16 },
17 bottomLeft: {
18 points: ['tr', 'bl'],
19 offset: [0, 4],
20 overflow: {
21 adjustX: 0,
22 adjustY: 1
23 }
24 },
25 topRight: {
26 points: ['bl', 'tr'],
27 offset: [0, -4],
28 overflow: {
29 adjustX: 0,
30 adjustY: 1
31 }
32 },
33 topLeft: {
34 points: ['br', 'tl'],
35 offset: [0, -4],
36 overflow: {
37 adjustX: 0,
38 adjustY: 1
39 }
40 }
41};
42
43var KeywordTrigger = /*#__PURE__*/function (_React$Component) {
44 _inherits(KeywordTrigger, _React$Component);
45
46 var _super = _createSuper(KeywordTrigger);
47
48 function KeywordTrigger() {
49 var _this;
50
51 _classCallCheck(this, KeywordTrigger);
52
53 _this = _super.apply(this, arguments);
54
55 _this.getDropdownPrefix = function () {
56 return "".concat(_this.props.prefixCls, "-dropdown");
57 };
58
59 _this.getDropdownElement = function () {
60 var options = _this.props.options;
61 return /*#__PURE__*/React.createElement(DropdownMenu, {
62 prefixCls: _this.getDropdownPrefix(),
63 options: options
64 });
65 };
66
67 _this.getDropDownPlacement = function () {
68 var _this$props = _this.props,
69 placement = _this$props.placement,
70 direction = _this$props.direction;
71 var popupPlacement = 'topRight';
72
73 if (direction === 'rtl') {
74 popupPlacement = placement === 'top' ? 'topLeft' : 'bottomLeft';
75 } else {
76 popupPlacement = placement === 'top' ? 'topRight' : 'bottomRight';
77 }
78
79 return popupPlacement;
80 };
81
82 return _this;
83 }
84
85 _createClass(KeywordTrigger, [{
86 key: "render",
87 value: function render() {
88 var _this$props2 = this.props,
89 children = _this$props2.children,
90 visible = _this$props2.visible,
91 transitionName = _this$props2.transitionName,
92 getPopupContainer = _this$props2.getPopupContainer;
93 var popupElement = this.getDropdownElement();
94 return /*#__PURE__*/React.createElement(Trigger, {
95 prefixCls: this.getDropdownPrefix(),
96 popupVisible: visible,
97 popup: popupElement,
98 popupPlacement: this.getDropDownPlacement(),
99 popupTransitionName: transitionName,
100 builtinPlacements: BUILT_IN_PLACEMENTS,
101 getPopupContainer: getPopupContainer
102 }, children);
103 }
104 }]);
105
106 return KeywordTrigger;
107}(React.Component);
108
109export default KeywordTrigger;
\No newline at end of file