1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3 | import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
5 | var _excluded = ["prefixCls", "disabled", "visible", "children", "popupElement", "animation", "transitionName", "dropdownStyle", "dropdownClassName", "direction", "placement", "builtinPlacements", "dropdownMatchSelectWidth", "dropdownRender", "dropdownAlign", "getPopupContainer", "empty", "getTriggerDOMNode", "onPopupVisibleChange", "onPopupMouseEnter"];
|
6 | import Trigger from '@rc-component/trigger';
|
7 | import classNames from 'classnames';
|
8 | import * as React from 'react';
|
9 | var getBuiltInPlacements = function getBuiltInPlacements(dropdownMatchSelectWidth) {
|
10 |
|
11 | var adjustX = dropdownMatchSelectWidth === true ? 0 : 1;
|
12 | return {
|
13 | bottomLeft: {
|
14 | points: ['tl', 'bl'],
|
15 | offset: [0, 4],
|
16 | overflow: {
|
17 | adjustX: adjustX,
|
18 | adjustY: 1
|
19 | },
|
20 | htmlRegion: 'scroll'
|
21 | },
|
22 | bottomRight: {
|
23 | points: ['tr', 'br'],
|
24 | offset: [0, 4],
|
25 | overflow: {
|
26 | adjustX: adjustX,
|
27 | adjustY: 1
|
28 | },
|
29 | htmlRegion: 'scroll'
|
30 | },
|
31 | topLeft: {
|
32 | points: ['bl', 'tl'],
|
33 | offset: [0, -4],
|
34 | overflow: {
|
35 | adjustX: adjustX,
|
36 | adjustY: 1
|
37 | },
|
38 | htmlRegion: 'scroll'
|
39 | },
|
40 | topRight: {
|
41 | points: ['br', 'tr'],
|
42 | offset: [0, -4],
|
43 | overflow: {
|
44 | adjustX: adjustX,
|
45 | adjustY: 1
|
46 | },
|
47 | htmlRegion: 'scroll'
|
48 | }
|
49 | };
|
50 | };
|
51 | var SelectTrigger = function SelectTrigger(props, ref) {
|
52 | var prefixCls = props.prefixCls,
|
53 | disabled = props.disabled,
|
54 | visible = props.visible,
|
55 | children = props.children,
|
56 | popupElement = props.popupElement,
|
57 | animation = props.animation,
|
58 | transitionName = props.transitionName,
|
59 | dropdownStyle = props.dropdownStyle,
|
60 | dropdownClassName = props.dropdownClassName,
|
61 | _props$direction = props.direction,
|
62 | direction = _props$direction === void 0 ? 'ltr' : _props$direction,
|
63 | placement = props.placement,
|
64 | builtinPlacements = props.builtinPlacements,
|
65 | dropdownMatchSelectWidth = props.dropdownMatchSelectWidth,
|
66 | dropdownRender = props.dropdownRender,
|
67 | dropdownAlign = props.dropdownAlign,
|
68 | getPopupContainer = props.getPopupContainer,
|
69 | empty = props.empty,
|
70 | getTriggerDOMNode = props.getTriggerDOMNode,
|
71 | onPopupVisibleChange = props.onPopupVisibleChange,
|
72 | onPopupMouseEnter = props.onPopupMouseEnter,
|
73 | restProps = _objectWithoutProperties(props, _excluded);
|
74 | var dropdownPrefixCls = "".concat(prefixCls, "-dropdown");
|
75 | var popupNode = popupElement;
|
76 | if (dropdownRender) {
|
77 | popupNode = dropdownRender(popupElement);
|
78 | }
|
79 | var mergedBuiltinPlacements = React.useMemo(function () {
|
80 | return builtinPlacements || getBuiltInPlacements(dropdownMatchSelectWidth);
|
81 | }, [builtinPlacements, dropdownMatchSelectWidth]);
|
82 |
|
83 |
|
84 | var mergedTransitionName = animation ? "".concat(dropdownPrefixCls, "-").concat(animation) : transitionName;
|
85 |
|
86 |
|
87 | var isNumberPopupWidth = typeof dropdownMatchSelectWidth === 'number';
|
88 | var stretch = React.useMemo(function () {
|
89 | if (isNumberPopupWidth) {
|
90 | return null;
|
91 | }
|
92 | return dropdownMatchSelectWidth === false ? 'minWidth' : 'width';
|
93 | }, [dropdownMatchSelectWidth, isNumberPopupWidth]);
|
94 | var popupStyle = dropdownStyle;
|
95 | if (isNumberPopupWidth) {
|
96 | popupStyle = _objectSpread(_objectSpread({}, popupStyle), {}, {
|
97 | width: dropdownMatchSelectWidth
|
98 | });
|
99 | }
|
100 |
|
101 |
|
102 | var triggerPopupRef = React.useRef(null);
|
103 | React.useImperativeHandle(ref, function () {
|
104 | return {
|
105 | getPopupElement: function getPopupElement() {
|
106 | var _triggerPopupRef$curr;
|
107 | return (_triggerPopupRef$curr = triggerPopupRef.current) === null || _triggerPopupRef$curr === void 0 ? void 0 : _triggerPopupRef$curr.popupElement;
|
108 | }
|
109 | };
|
110 | });
|
111 | return React.createElement(Trigger, _extends({}, restProps, {
|
112 | showAction: onPopupVisibleChange ? ['click'] : [],
|
113 | hideAction: onPopupVisibleChange ? ['click'] : [],
|
114 | popupPlacement: placement || (direction === 'rtl' ? 'bottomRight' : 'bottomLeft'),
|
115 | builtinPlacements: mergedBuiltinPlacements,
|
116 | prefixCls: dropdownPrefixCls,
|
117 | popupTransitionName: mergedTransitionName,
|
118 | popup: React.createElement("div", {
|
119 | onMouseEnter: onPopupMouseEnter
|
120 | }, popupNode),
|
121 | ref: triggerPopupRef,
|
122 | stretch: stretch,
|
123 | popupAlign: dropdownAlign,
|
124 | popupVisible: visible,
|
125 | getPopupContainer: getPopupContainer,
|
126 | popupClassName: classNames(dropdownClassName, _defineProperty({}, "".concat(dropdownPrefixCls, "-empty"), empty)),
|
127 | popupStyle: popupStyle,
|
128 | getTriggerDOMNode: getTriggerDOMNode,
|
129 | onPopupVisibleChange: onPopupVisibleChange
|
130 | }), children);
|
131 | };
|
132 | var RefSelectTrigger = React.forwardRef(SelectTrigger);
|
133 | if (process.env.NODE_ENV !== 'production') {
|
134 | RefSelectTrigger.displayName = 'SelectTrigger';
|
135 | }
|
136 | export default RefSelectTrigger; |
\ | No newline at end of file |