"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); 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 _trigger = _interopRequireDefault(require("@rc-component/trigger")); var _classnames = _interopRequireDefault(require("classnames")); var React = _interopRequireWildcard(require("react")); var _excluded = ["prefixCls", "disabled", "visible", "children", "popupElement", "animation", "transitionName", "dropdownStyle", "dropdownClassName", "direction", "placement", "builtinPlacements", "dropdownMatchSelectWidth", "dropdownRender", "dropdownAlign", "getPopupContainer", "empty", "getTriggerDOMNode", "onPopupVisibleChange", "onPopupMouseEnter"]; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var getBuiltInPlacements = function getBuiltInPlacements(dropdownMatchSelectWidth) { // Enable horizontal overflow auto-adjustment when a custom dropdown width is provided var adjustX = dropdownMatchSelectWidth === true ? 0 : 1; return { bottomLeft: { points: ['tl', 'bl'], offset: [0, 4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: 'scroll' }, bottomRight: { points: ['tr', 'br'], offset: [0, 4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: 'scroll' }, topLeft: { points: ['bl', 'tl'], offset: [0, -4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: 'scroll' }, topRight: { points: ['br', 'tr'], offset: [0, -4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: 'scroll' } }; }; var SelectTrigger = function SelectTrigger(props, ref) { var prefixCls = props.prefixCls, disabled = props.disabled, visible = props.visible, children = props.children, popupElement = props.popupElement, animation = props.animation, transitionName = props.transitionName, dropdownStyle = props.dropdownStyle, dropdownClassName = props.dropdownClassName, _props$direction = props.direction, direction = _props$direction === void 0 ? 'ltr' : _props$direction, placement = props.placement, builtinPlacements = props.builtinPlacements, dropdownMatchSelectWidth = props.dropdownMatchSelectWidth, dropdownRender = props.dropdownRender, dropdownAlign = props.dropdownAlign, getPopupContainer = props.getPopupContainer, empty = props.empty, getTriggerDOMNode = props.getTriggerDOMNode, onPopupVisibleChange = props.onPopupVisibleChange, onPopupMouseEnter = props.onPopupMouseEnter, restProps = (0, _objectWithoutProperties2.default)(props, _excluded); var dropdownPrefixCls = "".concat(prefixCls, "-dropdown"); var popupNode = popupElement; if (dropdownRender) { popupNode = dropdownRender(popupElement); } var mergedBuiltinPlacements = React.useMemo(function () { return builtinPlacements || getBuiltInPlacements(dropdownMatchSelectWidth); }, [builtinPlacements, dropdownMatchSelectWidth]); // ===================== Motion ====================== var mergedTransitionName = animation ? "".concat(dropdownPrefixCls, "-").concat(animation) : transitionName; // =================== Popup Width =================== var isNumberPopupWidth = typeof dropdownMatchSelectWidth === 'number'; var stretch = React.useMemo(function () { if (isNumberPopupWidth) { return null; } return dropdownMatchSelectWidth === false ? 'minWidth' : 'width'; }, [dropdownMatchSelectWidth, isNumberPopupWidth]); var popupStyle = dropdownStyle; if (isNumberPopupWidth) { popupStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, popupStyle), {}, { width: dropdownMatchSelectWidth }); } // ======================= Ref ======================= var popupRef = React.useRef(null); React.useImperativeHandle(ref, function () { return { getPopupElement: function getPopupElement() { return popupRef.current; } }; }); return /*#__PURE__*/React.createElement(_trigger.default, (0, _extends2.default)({}, restProps, { showAction: onPopupVisibleChange ? ['click'] : [], hideAction: onPopupVisibleChange ? ['click'] : [], popupPlacement: placement || (direction === 'rtl' ? 'bottomRight' : 'bottomLeft'), builtinPlacements: mergedBuiltinPlacements, prefixCls: dropdownPrefixCls, popupTransitionName: mergedTransitionName, popup: /*#__PURE__*/React.createElement("div", { ref: popupRef, onMouseEnter: onPopupMouseEnter }, popupNode), stretch: stretch, popupAlign: dropdownAlign, popupVisible: visible, getPopupContainer: getPopupContainer, popupClassName: (0, _classnames.default)(dropdownClassName, (0, _defineProperty2.default)({}, "".concat(dropdownPrefixCls, "-empty"), empty)), popupStyle: popupStyle, getTriggerDOMNode: getTriggerDOMNode, onPopupVisibleChange: onPopupVisibleChange }), children); }; var RefSelectTrigger = /*#__PURE__*/React.forwardRef(SelectTrigger); RefSelectTrigger.displayName = 'SelectTrigger'; var _default = RefSelectTrigger; exports.default = _default;