SelectTrigger.js
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import * as React from 'react';
import Trigger from 'rc-trigger';
import classNames from 'classnames';
var getBuiltInPlacements = function getBuiltInPlacements(dropdownMatchSelectWidth) {
// Enable horizontal overflow auto-adjustment when a custom dropdown width is provided
var adjustX = typeof dropdownMatchSelectWidth !== 'number' ? 0 : 1;
return {
bottomLeft: {
points: ['tl', 'bl'],
offset: [0, 4],
overflow: {
adjustX: adjustX,
adjustY: 1
}
},
bottomRight: {
points: ['tr', 'br'],
offset: [0, 4],
overflow: {
adjustX: adjustX,
adjustY: 1
}
},
topLeft: {
points: ['bl', 'tl'],
offset: [0, -4],
overflow: {
adjustX: adjustX,
adjustY: 1
}
},
topRight: {
points: ['br', 'tr'],
offset: [0, -4],
overflow: {
adjustX: adjustX,
adjustY: 1
}
}
};
};
var SelectTrigger = function SelectTrigger(props, ref) {
var prefixCls = props.prefixCls,
disabled = props.disabled,
visible = props.visible,
children = props.children,
popupElement = props.popupElement,
containerWidth = props.containerWidth,
animation = props.animation,
transitionName = props.transitionName,
dropdownStyle = props.dropdownStyle,
dropdownClassName = props.dropdownClassName,
_props$direction = props.direction,
direction = _props$direction === void 0 ? 'ltr' : _props$direction,
_props$dropdownMatchS = props.dropdownMatchSelectWidth,
dropdownMatchSelectWidth = _props$dropdownMatchS === void 0 ? true : _props$dropdownMatchS,
dropdownRender = props.dropdownRender,
dropdownAlign = props.dropdownAlign,
getPopupContainer = props.getPopupContainer,
empty = props.empty,
getTriggerDOMNode = props.getTriggerDOMNode,
restProps = _objectWithoutProperties(props, ["prefixCls", "disabled", "visible", "children", "popupElement", "containerWidth", "animation", "transitionName", "dropdownStyle", "dropdownClassName", "direction", "dropdownMatchSelectWidth", "dropdownRender", "dropdownAlign", "getPopupContainer", "empty", "getTriggerDOMNode"]);
var dropdownPrefixCls = "".concat(prefixCls, "-dropdown");
var popupNode = popupElement;
if (dropdownRender) {
popupNode = dropdownRender(popupElement);
}
var builtInPlacements = React.useMemo(function () {
return getBuiltInPlacements(dropdownMatchSelectWidth);
}, [dropdownMatchSelectWidth]); // ===================== Motion ======================
var mergedTransitionName = animation ? "".concat(dropdownPrefixCls, "-").concat(animation) : transitionName; // ======================= Ref =======================
var popupRef = React.useRef(null);
React.useImperativeHandle(ref, function () {
return {
getPopupElement: function getPopupElement() {
return popupRef.current;
}
};
});
var popupStyle = _objectSpread({
minWidth: containerWidth
}, dropdownStyle);
if (typeof dropdownMatchSelectWidth === 'number') {
popupStyle.width = dropdownMatchSelectWidth;
} else if (dropdownMatchSelectWidth) {
popupStyle.width = containerWidth;
}
return React.createElement(Trigger, Object.assign({}, restProps, {
showAction: [],
hideAction: [],
popupPlacement: direction === 'rtl' ? 'bottomRight' : 'bottomLeft',
builtinPlacements: builtInPlacements,
prefixCls: dropdownPrefixCls,
popupTransitionName: mergedTransitionName,
popup: React.createElement("div", {
ref: popupRef
}, popupNode),
popupAlign: dropdownAlign,
popupVisible: visible,
getPopupContainer: getPopupContainer,
popupClassName: classNames(dropdownClassName, _defineProperty({}, "".concat(dropdownPrefixCls, "-empty"), empty)),
popupStyle: popupStyle,
getTriggerDOMNode: getTriggerDOMNode
}), children);
};
var RefSelectTrigger = React.forwardRef(SelectTrigger);
RefSelectTrigger.displayName = 'SelectTrigger';
export default RefSelectTrigger;