@flatbiz/antd
Version:
157 lines (152 loc) • 5.68 kB
JavaScript
/*! @flatjs/forge MIT @flatbiz/antd */
import { classNames } from '@dimjs/utils/class-names/class-names';
import _ExclamationCircleFilled from '@ant-design/icons/es/icons/ExclamationCircleFilled.js';
import { _ as _objectWithoutProperties, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js';
import { hooks } from '@wove/react/hooks';
import { Fragment, useMemo, createElement } from 'react';
import { Dropdown } from 'antd';
import { B as ButtonWrapper } from './button-wrapper-l9FUsrWl.js';
import { d as dialogConfirm } from './dialog-confirm-GTxDQEV0.js';
import { f as fbaUtils } from './fba-utils-Dfbczn1S.js';
import { F as FlexLayout } from './flex-layout-BaDncU_Z.js';
import { jsxs, jsx } from 'react/jsx-runtime';
function parentsHasSticky(node) {
var condition = true;
var result = false;
while (condition) {
if (node.tagName === 'HTML' || node.tagName === 'BODY') {
condition = false;
result = false;
} else {
var _window$getComputedSt = window.getComputedStyle(node),
position = _window$getComputedSt.position;
if (position === 'sticky') {
result = true;
condition = false;
} else {
if (!node || !node.parentNode) {
condition = false;
} else {
node = node.parentNode;
}
}
}
}
return result;
}
var _excluded = ["menuList"],
_excluded2 = ["text", "permission", "needConfirm", "confirmMessage", "hidden", "type", "confirmModalProps"];
/**
* DropdownMenuWrapper
* 升级 antd 5.5.1 后,Dropdown 中 Popconfirm弹框使用存在问题,所以在 @flatbiz/antd@4.2.49版本修改为使用dialogConfirm组件实现二次弹框确认功能
* @param props
* @returns
* ```
* 1. Dropdown默认弹框根节点在组件内部,通过isFixed=true可设置弹框根节点在body下
* ```
*/
var DropdownMenuWrapper = function DropdownMenuWrapper(props) {
var menuList = props.menuList,
dropdownOtherProps = _objectWithoutProperties(props, _excluded);
var clsName = hooks.useId(undefined, 'DropdownMenuWrapper');
var onClick = hooks.useCallbackRef(function (item, event) {
var _item$onClick2;
if (item.needConfirm) {
var _item$onClick;
dialogConfirm.open(_objectSpread2({
title: /*#__PURE__*/jsxs(FlexLayout, {
direction: "horizontal",
fullIndex: 1,
gap: 8,
children: [/*#__PURE__*/jsx(_ExclamationCircleFilled, {
style: {
color: '#faad14'
}
}), /*#__PURE__*/jsx("span", {
children: item.title
})]
}),
content: /*#__PURE__*/jsx(Fragment, {
children: item.confirmMessage
}),
onOk: (_item$onClick = item.onClick) === null || _item$onClick === void 0 ? void 0 : _item$onClick.bind(null, event),
okButtonProps: {
loadingPosition: 'center'
}
}, item.confirmModalProps));
return Promise.resolve();
}
event.stopPropagation();
return (_item$onClick2 = item.onClick) === null || _item$onClick2 === void 0 ? void 0 : _item$onClick2.call(item, event);
});
var target = document.querySelector(".".concat(clsName));
var container = useMemo(function () {
if (props.isFixed || target && parentsHasSticky(target)) {
return undefined;
}
return target;
}, [props.isFixed, target]);
var menuItems = useMemo(function () {
var menuItemsNew = [];
menuList.filter(Boolean).forEach(function (item, index) {
if (!item) return;
var text = item.text,
permission = item.permission,
needConfirm = item.needConfirm,
confirmMessage = item.confirmMessage,
hidden = item.hidden,
type = item.type,
confirmModalProps = item.confirmModalProps,
otherProps = _objectWithoutProperties(item, _excluded2);
if (hidden) return;
if (permission && !fbaUtils.hasPermission(permission)) return;
var buttonType = type || 'link';
var danger = otherProps.color ? false : needConfirm;
menuItemsNew.push({
key: index,
label: /*#__PURE__*/createElement(ButtonWrapper, _objectSpread2(_objectSpread2({
loadingPosition: "center",
size: "small",
danger: danger
}, otherProps), {}, {
style: _objectSpread2({}, otherProps.style),
className: classNames('dmw-item-button', otherProps.className),
type: buttonType,
key: index,
onClick: onClick.bind(null, _objectSpread2(_objectSpread2({}, item), {}, {
needConfirm: needConfirm,
confirmMessage: confirmMessage,
confirmModalProps: confirmModalProps
}))
}), text)
});
});
return menuItemsNew;
}, [menuList, onClick]);
return /*#__PURE__*/jsx("div", {
className: classNames('dropdown-menu-wrapper', clsName),
style: {
position: 'relative'
},
children: /*#__PURE__*/jsx(Dropdown, _objectSpread2(_objectSpread2({
trigger: (dropdownOtherProps === null || dropdownOtherProps === void 0 ? void 0 : dropdownOtherProps.trigger) || ['hover'],
getPopupContainer: container ? function () {
return target;
} : undefined,
arrow: {
pointAtCenter: true
}
}, dropdownOtherProps), {}, {
overlayStyle: _objectSpread2({
zIndex: 9
}, dropdownOtherProps.overlayStyle),
menu: {
items: menuItems
},
rootClassName: "dropdown-menu-wrapper-popup",
children: props.children
}))
});
};
export { DropdownMenuWrapper as D };
//# sourceMappingURL=dropdown-menu-wrapper-ChbwSdIf.js.map