146 lines
6.5 KiB
JavaScript
146 lines
6.5 KiB
JavaScript
|
"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(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||
|
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; }
|
||
|
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 triggerPopupRef = React.useRef(null);
|
||
|
React.useImperativeHandle(ref, function () {
|
||
|
return {
|
||
|
getPopupElement: function getPopupElement() {
|
||
|
var _triggerPopupRef$curr;
|
||
|
return (_triggerPopupRef$curr = triggerPopupRef.current) === null || _triggerPopupRef$curr === void 0 ? void 0 : _triggerPopupRef$curr.popupElement;
|
||
|
}
|
||
|
};
|
||
|
});
|
||
|
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", {
|
||
|
onMouseEnter: onPopupMouseEnter
|
||
|
}, popupNode),
|
||
|
ref: triggerPopupRef,
|
||
|
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);
|
||
|
if (process.env.NODE_ENV !== 'production') {
|
||
|
RefSelectTrigger.displayName = 'SelectTrigger';
|
||
|
}
|
||
|
var _default = exports.default = RefSelectTrigger;
|