UNPKG

acud

Version:

acg react 组件库

128 lines • 5.07 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _extends from "@babel/runtime/helpers/esm/extends"; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; // import Trigger from 'rc-trigger'; import Trigger from '@rc-component/trigger'; import classNames from 'classnames'; var getBuiltInPlacements = function getBuiltInPlacements(dropdownMatchSelectWidth, popupOverflow) { // Enable horizontal overflow auto-adjustment when a custom dropdown width is provided var adjustX = typeof dropdownMatchSelectWidth !== 'number' ? 0 : 1; var htmlRegion = popupOverflow === 'scroll' ? 'scroll' : 'visible'; return { bottomLeft: { points: ['tl', 'bl'], offset: [0, 4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: htmlRegion }, bottomRight: { points: ['tr', 'br'], offset: [0, 4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: htmlRegion }, topLeft: { points: ['bl', 'tl'], offset: [0, -4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: htmlRegion }, topRight: { points: ['br', 'tr'], offset: [0, -4], overflow: { adjustX: adjustX, adjustY: 1 }, htmlRegion: htmlRegion } }; }; var SelectTrigger = function SelectTrigger(props, ref) { var prefixCls = props.prefixCls, visible = props.visible, children = props.children, popupElement = props.popupElement, multiple = props.multiple, 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, placement = props.placement, popupOverflow = props.popupOverflow, restProps = __rest(props, ["prefixCls", "visible", "children", "popupElement", "multiple", "containerWidth", "animation", "transitionName", "dropdownStyle", "dropdownClassName", "direction", "dropdownMatchSelectWidth", "dropdownRender", "dropdownAlign", "getPopupContainer", "empty", "getTriggerDOMNode", "placement", "popupOverflow"]); var dropdownPrefixCls = "".concat(prefixCls, "-dropdown"); var popupNode = popupElement; if (dropdownRender) { popupNode = dropdownRender(popupElement); } var builtInPlacements = React.useMemo(function () { return getBuiltInPlacements(dropdownMatchSelectWidth, popupOverflow); }, [dropdownMatchSelectWidth, popupOverflow]); // ===================== 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 = _extends({ minWidth: containerWidth }, dropdownStyle); if (typeof dropdownMatchSelectWidth === 'number') { popupStyle.width = dropdownMatchSelectWidth; } else if (dropdownMatchSelectWidth) { popupStyle.width = containerWidth; } return /*#__PURE__*/React.createElement(Trigger, _extends({}, restProps, { showAction: [], hideAction: [], popupPlacement: placement || (direction === 'rtl' ? 'bottomRight' : 'bottomLeft'), builtinPlacements: builtInPlacements, prefixCls: dropdownPrefixCls, popupTransitionName: mergedTransitionName, popup: /*#__PURE__*/React.createElement("div", { ref: popupRef }, popupNode), popupAlign: dropdownAlign, popupVisible: visible, getPopupContainer: getPopupContainer, popupClassName: classNames(dropdownClassName, _defineProperty(_defineProperty({}, "".concat(dropdownPrefixCls, "-empty"), empty), "".concat(dropdownPrefixCls, "-multiple"), multiple)), popupStyle: popupStyle, getTriggerDOMNode: getTriggerDOMNode }), children); }; var RefSelectTrigger = /*#__PURE__*/React.forwardRef(SelectTrigger); RefSelectTrigger.displayName = 'SelectTrigger'; export default RefSelectTrigger;