UNPKG

choerodon-ui

Version:

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

135 lines (120 loc) 4.58 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 _createSuper from "@babel/runtime/helpers/createSuper"; import React, { Component } from 'react'; import { ModalManager } from 'choerodon-ui/shared'; import Button from '../button'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { getConfirmLocale } from './locale'; import Dialog from '../rc-components/dialog'; import ConfigContext from '../config-provider/ConfigContext'; 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 /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, _extends({ disabled: disableCancel || confirmLoading, onClick: _this.handleCancel, funcType: funcType }, cancelButtonProps), cancelText || locale.cancelText), /*#__PURE__*/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() { ModalManager.registerMousePosition(); } }, { 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$movable = _this$props2.movable, movable = _this$props2$movable === void 0 ? getConfig('modalMovable') : _this$props2$movable, _this$props2$center = _this$props2.center, center = _this$props2$center === void 0 ? getConfig('modalAutoCenter') : _this$props2$center, _this$props2$maskClos = _this$props2.maskClosable, maskClosable = _this$props2$maskClos === void 0 ? getConfig('modalMaskClosable') : _this$props2$maskClos, _this$props2$keyboard = _this$props2.keyboard, keyboard = _this$props2$keyboard === void 0 ? getConfig('modalKeyboard') : _this$props2$keyboard; var prefixCls = getPrefixCls('modal', customizePrefixCls); var defaultFooter = /*#__PURE__*/React.createElement(LocaleReceiver, { componentName: "Modal", defaultLocale: getConfirmLocale() }, this.renderFooter); return /*#__PURE__*/React.createElement(Dialog, _extends({}, this.props, { movable: movable, maskClosable: maskClosable, center: center, keyboard: keyboard, prefixCls: prefixCls, footer: footer === undefined ? defaultFooter : footer, visible: visible, mousePosition: ModalManager.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', okButtonDisabled: false, cancelButtonDisabled: false, center: false }; //# sourceMappingURL=Modal.js.map