UNPKG

acud

Version:

acg react 组件库

136 lines • 4.8 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import * as React from 'react'; import Dialog from 'rc-dialog'; import FilledError from "acud-icon/es/icons/FilledError"; import OutlinedClose from "acud-icon/es/icons/OutlinedClose"; import FilledSuccess from "acud-icon/es/icons/FilledSuccess"; import FilledWarn from "acud-icon/es/icons/FilledWarn"; import FilledInfo from "acud-icon/es/icons/FilledInfo"; import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import Button from '../button'; import { canUseDocElement } from '../_util/styleChecker'; import { getTransitionName } from '../_util/motion'; var mousePosition; // 100ms 内发生过点击事件,则从点击位置动画展示 var getClickPosition = function getClickPosition(e) { mousePosition = { x: e.pageX, y: e.pageY }; setTimeout(function () { mousePosition = null; }, 100); }; // 只有点击事件支持从鼠标位置动画展开 if (canUseDocElement()) { document.documentElement.addEventListener('click', getClickPosition, true); } // type SizeType = 'small' | 'normal' | 'large' | 'extraLarge'; var SizeType; (function (SizeType) { SizeType["small"] = "sm"; SizeType["normal"] = "md"; SizeType["large"] = "lg"; SizeType["extraLarge"] = "xl"; })(SizeType || (SizeType = {})); ; var DialogType = { sucess: { className: 'sucess', icon: /*#__PURE__*/React.createElement(FilledSuccess, { color: "@S6" }) }, warning: { className: 'warning', icon: /*#__PURE__*/React.createElement(FilledWarn, { color: "@W6" }) }, info: { className: 'info', icon: /*#__PURE__*/React.createElement(FilledInfo, { color: "@B6" }) }, error: { className: 'error', icon: /*#__PURE__*/React.createElement(FilledError, { color: "@E6" }) } }; var DialogBox = function DialogBox(props) { var _React$useContext = React.useContext(ConfigContext), getPopupContainer = _React$useContext.getPopupContainer, getPrefixCls = _React$useContext.getPrefixCls; var prefixCls = getPrefixCls('dialogbox'); var rootPrefixCls = getPrefixCls(); var handleCancel = function handleCancel(e) { var _a; var onCancel = props.onCancel; if (((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.className) === "".concat(prefixCls, "-wrap")) { return; } onCancel === null || onCancel === void 0 ? void 0 : onCancel(e); }; var handleOk = function handleOk(e) { var onOk = props.onOk; onOk === null || onOk === void 0 ? void 0 : onOk(e); }; var defaultRenderFooter = function defaultRenderFooter() { var okText = props.okText, cancelText = props.cancelText, confirmLoading = props.confirmLoading; return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, { onClick: handleCancel, type: "default" }, cancelText || '取消'), /*#__PURE__*/React.createElement(Button, { onClick: handleOk, loading: confirmLoading, type: "primary" }, okText || '确定')); }; var closeIconToRender = /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-close-x") }, /*#__PURE__*/React.createElement(OutlinedClose, { className: "".concat(prefixCls, "-close-icon") })); var visible = props.visible, size = props.size, className = props.className, title = props.title, content = props.content, type = props.type, footer = props.footer; return /*#__PURE__*/React.createElement(Dialog, _extends({}, props, { footer: footer || defaultRenderFooter(), title: "", width: 400, className: classNames(className, "".concat(prefixCls, "-").concat(SizeType[size])), getContainer: getPopupContainer, prefixCls: prefixCls, visible: visible, mousePosition: mousePosition, onClose: handleCancel, transitionName: getTransitionName(rootPrefixCls, 'zoom'), maskTransitionName: getTransitionName(rootPrefixCls, 'fade'), closeIcon: closeIconToRender }), /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-content-con") }, /*#__PURE__*/React.createElement("div", { className: classNames((DialogType[type] || 'warning').className, "".concat(prefixCls, "-content-icon")) }, DialogType[type].icon), /*#__PURE__*/React.createElement("div", null, title && /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-content-title") }, title), /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-content-text") }, content)))); }; DialogBox.defaultProps = { size: 'small', visible: false, confirmLoading: false, type: 'warning' }; export default DialogBox;