UNPKG

@ttk/component

Version:

ttk组件库

239 lines (191 loc) 6.63 kB
import React__default, { PureComponent } from 'react'; import 'react-dom'; import { Modal } from 'antd'; import { _ as _defineProperty } from '../defineProperty-847730aa.js'; import classNames from 'classnames'; import { _ as _extends } from '../extends-b1af4ff7.js'; import { _ as _objectWithoutProperties } from '../objectWithoutProperties-0c3c7796.js'; import { _ as _inherits, a as _getPrototypeOf, b as _possibleConstructorReturn, c as _classCallCheck, d as _createClass } from '../getPrototypeOf-b95655c5.js'; import localeWrapper from '../localeWrapper'; import Drag from '../drag'; import '../_commonjsHelpers-471920d6.js'; function info(props) { return new Promise(function (resolve, reject) { var handleOk = function handleOk() { resolve(true); }; var handleCancel = function handleCancel() { resolve(false); }; props.onOk = handleOk; props.onCancel = handleCancel; Modal.info(props); }); } function error(props) { return new Promise(function (resolve, reject) { var handleOk = function handleOk() { resolve(true); }; var handleCancel = function handleCancel() { resolve(false); }; props.onOk = handleOk; props.onCancel = handleCancel; Modal.error(props); }); } function success(props) { return new Promise(function (resolve, reject) { var handleOk = function handleOk() { resolve(true); }; var handleCancel = function handleCancel() { resolve(false); }; props.onOk = handleOk; props.onCancel = handleCancel; Modal.success(props); }); } function warning(props) { return new Promise(function (resolve, reject) { var handleOk = function handleOk() { resolve(true); }; var handleCancel = function handleCancel() { resolve(false); }; props.onOk = handleOk; props.onCancel = handleCancel; Modal.warning(props); }); } function confirm(props) { return new Promise(function (resolve, reject) { var handleOk = function handleOk() { resolve(true); }; var handleCancel = function handleCancel() { resolve(false); }; var className = classNames(_defineProperty({ 'mk-confirm': true }, props.className, !!props.className)); if (!props.onOk) { props.onOk = handleOk; } if (!props.width) { props.width = 325; } if (props.flag) { props.className = className + ' modalTitle'; props.onCancel = handleCancel; } else { props.className = className; props.onCancel = handleCancel; } props.okText = props.okText || '确定'; props.cancelText = props.cancelText || '取消'; Modal.confirm(props); }); } var _excluded = ["children", "title", "allowDrag"]; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var DragTitle = /*#__PURE__*/function (_PureComponent) { _inherits(DragTitle, _PureComponent); var _super = _createSuper(DragTitle); function DragTitle() { var _this; _classCallCheck(this, DragTitle); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _this.updateTransform = function (transformStr) { _this.modalDom.style.transform = transformStr; }; return _this; } _createClass(DragTitle, [{ key: "componentDidMount", value: function componentDidMount() { var modalObj = document.getElementsByClassName("ant-modal"); if (modalObj) { var modalCount = modalObj.length; if (modalCount == 1) { this.modalDom = document.getElementsByClassName("ant-modal" //modal的class是ant-modal )[0]; } else if (modalCount > 1) { this.modalDom = document.getElementsByClassName("ant-modal" //modal的class是ant-modal )[modalCount - 1]; } } } }, { key: "render", value: function render() { var title = this.props.title; if (typeof title == 'string') { return /*#__PURE__*/React__default.createElement(Drag, { updateTransform: this.updateTransform }, /*#__PURE__*/React__default.createElement("div", { title: title }, title)); } else { return /*#__PURE__*/React__default.createElement(Drag, { updateTransform: this.updateTransform }, /*#__PURE__*/React__default.createElement("div", null, title)); } } }]); return DragTitle; }(PureComponent); var ModalComponent = /*#__PURE__*/function (_PureComponent2) { _inherits(ModalComponent, _PureComponent2); var _super2 = _createSuper(ModalComponent); function ModalComponent() { _classCallCheck(this, ModalComponent); return _super2.apply(this, arguments); } _createClass(ModalComponent, [{ key: "render", value: function render() { var _this$props = this.props, children = _this$props.children, title = _this$props.title, allowDrag = _this$props.allowDrag, otherProps = _objectWithoutProperties(_this$props, _excluded); var className = classNames({ 'mk-modal': true }); allowDrag = allowDrag === false ? false : true; if (allowDrag) { title = /*#__PURE__*/React__default.createElement(DragTitle, { title: title }); } return localeWrapper( /*#__PURE__*/React__default.createElement(Modal, _extends({ visible: true, title: title, className: className }, otherProps, { children: children }))); } }]); return ModalComponent; }(PureComponent); var m = window.__Modal; if (!m) { m = ModalComponent; window.__Modal = m; } m.info = info; m.success = success; m.error = error; m.warning = warning; m.confirm = confirm; var m$1 = m; export { DragTitle, m$1 as default };