function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } 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;