SelectTrigger.js
4.72 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _rcTrigger = _interopRequireDefault(require("rc-trigger"));
var _classnames = _interopRequireDefault(require("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 = (0, _objectWithoutProperties2.default)(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 = (0, _objectSpread2.default)({
minWidth: containerWidth
}, dropdownStyle);
if (typeof dropdownMatchSelectWidth === 'number') {
popupStyle.width = dropdownMatchSelectWidth;
} else if (dropdownMatchSelectWidth) {
popupStyle.width = containerWidth;
}
return React.createElement(_rcTrigger.default, 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: (0, _classnames.default)(dropdownClassName, (0, _defineProperty2.default)({}, "".concat(dropdownPrefixCls, "-empty"), empty)),
popupStyle: popupStyle,
getTriggerDOMNode: getTriggerDOMNode
}), children);
};
var RefSelectTrigger = React.forwardRef(SelectTrigger);
RefSelectTrigger.displayName = 'SelectTrigger';
var _default = RefSelectTrigger;
exports.default = _default;