UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

202 lines (177 loc) 6.07 kB
import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import Button from '../button'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { getConfirmLocale } from './locale'; import Dialog from '../rc-components/dialog'; import addEventListener from '../_util/addEventListener'; import ConfigContext from '../config-provider/ConfigContext'; var mousePosition; var mousePositionEventBinded; var Modal = /*#__PURE__*/ function (_Component) { _inherits(Modal, _Component); var _super = _createSuper(Modal); function Modal() { var _this; _classCallCheck(this, Modal); _this = _super.apply(this, arguments); _this.handleCancel = function (e) { var onCancel = _this.props.onCancel; if (onCancel) { onCancel(e); } }; _this.handleOk = function (e) { var onOk = _this.props.onOk; if (onOk) { onOk(e); } }; _this.renderFooter = function (locale) { var _this$props = _this.props, okText = _this$props.okText, okType = _this$props.okType, cancelText = _this$props.cancelText, confirmLoading = _this$props.confirmLoading, funcType = _this$props.funcType, disableOk = _this$props.disableOk, disableCancel = _this$props.disableCancel, cancelButtonProps = _this$props.cancelButtonProps, okButtonProps = _this$props.okButtonProps; return React.createElement("div", null, React.createElement(Button, _extends({ disabled: disableCancel || confirmLoading, onClick: _this.handleCancel, funcType: funcType }, cancelButtonProps), cancelText || locale.cancelText), React.createElement(Button, _extends({ type: okType, funcType: funcType, disabled: disableOk, loading: confirmLoading, onClick: _this.handleOk }, okButtonProps), okText || locale.okText)); }; return _this; } _createClass(Modal, [{ key: "componentDidMount", value: function componentDidMount() { if (mousePositionEventBinded) { return; } // 只有点击事件支持从鼠标位置动画展开 addEventListener(document.documentElement, 'click', function (e) { mousePosition = { x: e.pageX, y: e.pageY }; // 100ms 内发生过点击事件,则从点击位置动画展示 // 否则直接 zoom 展示 // 这样可以兼容非点击方式展开 setTimeout(function () { return mousePosition = null; }, 100); }); mousePositionEventBinded = true; } }, { key: "render", value: function render() { var _this$context = this.context, getPrefixCls = _this$context.getPrefixCls, getConfig = _this$context.getConfig; var _this$props2 = this.props, footer = _this$props2.footer, visible = _this$props2.visible, customizePrefixCls = _this$props2.prefixCls, _this$props2$keyboard = _this$props2.keyboard, keyboard = _this$props2$keyboard === void 0 ? getConfig('modalKeyboard') : _this$props2$keyboard; var prefixCls = getPrefixCls('modal', customizePrefixCls); var defaultFooter = React.createElement(LocaleReceiver, { componentName: "Modal", defaultLocale: getConfirmLocale() }, this.renderFooter); return React.createElement(Dialog, _extends({}, this.props, { keyboard: keyboard, prefixCls: prefixCls, footer: footer === undefined ? defaultFooter : footer, visible: visible, mousePosition: mousePosition, onClose: this.handleCancel })); } }], [{ key: "contextType", get: function get() { return ConfigContext; } }]); return Modal; }(Component); export { Modal as default }; Modal.displayName = 'Modal'; Modal.defaultProps = { width: 520, transitionName: 'zoom', maskTransitionName: 'fade', confirmLoading: false, disableOk: false, disableCancel: false, visible: false, okType: 'primary', center: false }; Modal.propTypes = { prefixCls: PropTypes.string, onOk: PropTypes.func, onCancel: PropTypes.func, okText: PropTypes.node, cancelText: PropTypes.node, width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), confirmLoading: PropTypes.bool, visible: PropTypes.bool, align: PropTypes.object, footer: PropTypes.node, title: PropTypes.node, closable: PropTypes.bool, transitionName: PropTypes.string, funcType: PropTypes.string, center: PropTypes.bool, disableOk: PropTypes.bool, disableCancel: PropTypes.bool, keyboard: PropTypes.bool, okType: PropTypes.string, maskTransitionName: PropTypes.string, okButtonProps: PropTypes.object, cancelButtonProps: PropTypes.object }; //# sourceMappingURL=Modal.js.map