UNPKG

@flatbiz/antd

Version:
120 lines (115 loc) 4.06 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { isString } from '@dimjs/lang/is-string'; import { b as _objectSpread2, a as _slicedToArray } from './_rollupPluginBabelHelpers-BYm17lo8.js'; import { classNames } from '@dimjs/utils/class-names/class-names'; import { hooks } from '@wove/react/hooks'; import { useState } from 'react'; import { createRoot } from 'react-dom/client'; import { theme, Modal } from 'antd'; import { b as bodyAppendDivElement, r as removeBodyChild } from './dom-DJxTwF3J.js'; import { fbaHooks } from './fba-hooks/index.js'; import { jsx, jsxs } from 'react/jsx-runtime'; var ModalRender = function ModalRender(props) { var elementId = props.elementId, className = props.className, divElement = props.divElement, message = props.message, mask = props.mask; var _theme$useToken = theme.useToken(), token = _theme$useToken.token; var colorPrimary = token.colorPrimary; var _useState = useState(true), _useState2 = _slicedToArray(_useState, 2), open = _useState2[0], setOpen = _useState2[1]; var onClose = hooks.useCallbackRef(function () { try { delete window[elementId]; } catch (_error) { // } setOpen(false); }); fbaHooks.useEffectCustom(function () { window[elementId] = onClose; }, [onClose]); var onAfterClose = hooks.useCallbackRef(function () { removeBodyChild("#".concat(elementId)); }); return /*#__PURE__*/jsx(Modal, { maskClosable: false, centered: true, destroyOnClose: true, className: classNames('v-dialog-loading', className), open: open, afterClose: onAfterClose, getContainer: divElement, footer: null, closable: false, style: { '--v-loading-color': colorPrimary }, mask: mask, children: /*#__PURE__*/jsx("div", { className: classNames('v-dialog-loading-content'), children: /*#__PURE__*/jsxs("div", { className: "loader-wrapper", children: [/*#__PURE__*/jsx("div", { className: "loader-inner" }), /*#__PURE__*/jsx("div", { className: "loader-text", children: message || '处理中' })] }) }) }); }; /** * Loading弹框 * ``` * 1. 可嵌套使用 * 2. 为什么不推荐使用 * dialogLoading.open 打开的内容无法适配兼容自定义主题、无法适配兼容旧版浏览器、无法兼容国际化 * 适配兼容旧版浏览器(https://ant-design.antgroup.com/docs/react/compatible-style-cn) * 3. 需要修改默认主题风格的场景,请使用 * const { appDialogLoading } = FbaApp.useDialogLoading(); * appDialogLoading.open({}) * ``` */ var dialogLoading = { open: function open(props) { var _bodyAppendDivElement = bodyAppendDivElement(), divElement = _bodyAppendDivElement.divElement, elementId = _bodyAppendDivElement.elementId; window['__dialog_loading_elementId'] = elementId; var root = createRoot(divElement); root.render(/*#__PURE__*/jsx(ModalRender, _objectSpread2(_objectSpread2({}, props), {}, { divElement: divElement, elementId: elementId, mask: props === null || props === void 0 ? void 0 : props.mask }))); return { close: function close() { var _window$elementId, _window; (_window$elementId = (_window = window)[elementId]) === null || _window$elementId === void 0 || _window$elementId.call(_window); } }; }, /** * ``` * 1. 关闭最新弹框,如果有多个弹框只能关闭最后一个 * 2. 多个弹框主动关闭,只能使用 dialogModal.open()返回值中的close * ``` */ close: function close() { try { var _window$elementId2, _window2; var elementId = window['__dialog_loading_elementId']; if (isString(elementId)) (_window$elementId2 = (_window2 = window)[elementId]) === null || _window$elementId2 === void 0 || _window$elementId2.call(_window2); } catch (_error) { // } } }; export { dialogLoading as d }; //# sourceMappingURL=dialog-loading-DdKI0dnm.js.map