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