choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
170 lines (150 loc) • 5.88 kB
JavaScript
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import React from 'react';
import noop from 'lodash/noop';
import { getProPrefixCls, getConfig } from '../../../es/configure';
import ModalManager from '../modal-manager';
import { open } from '../modal-container/ModalContainer';
import Icon from '../icon';
import { normalizeProps } from './utils';
export default function confirm(props) {
var _normalizeProps = normalizeProps(props),
children = _normalizeProps.children,
_normalizeProps$type = _normalizeProps.type,
type = _normalizeProps$type === void 0 ? 'confirm' : _normalizeProps$type,
_normalizeProps$onOk = _normalizeProps.onOk,
_onOk = _normalizeProps$onOk === void 0 ? noop : _normalizeProps$onOk,
_normalizeProps$onCan = _normalizeProps.onCancel,
_onCancel = _normalizeProps$onCan === void 0 ? noop : _normalizeProps$onCan,
_normalizeProps$onClo = _normalizeProps.onClose,
_onClose = _normalizeProps$onClo === void 0 ? noop : _normalizeProps$onClo,
iconType = _normalizeProps.iconType,
_normalizeProps$autoC = _normalizeProps.autoCenter,
autoCenter = _normalizeProps$autoC === void 0 ? getConfig('modalAutoCenter') : _normalizeProps$autoC,
_normalizeProps$borde = _normalizeProps.border,
border = _normalizeProps$borde === void 0 ? false : _normalizeProps$borde,
_normalizeProps$okCan = _normalizeProps.okCancel,
okCancel = _normalizeProps$okCan === void 0 ? true : _normalizeProps$okCan,
title = _normalizeProps.title,
otherProps = _objectWithoutProperties(_normalizeProps, ["children", "type", "onOk", "onCancel", "onClose", "iconType", "autoCenter", "border", "okCancel", "title"]);
var prefixCls = getProPrefixCls('confirm');
var titleNode = title && React.createElement("div", {
className: "".concat(prefixCls, "-title")
}, title);
var contentNode = children && React.createElement("div", {
className: "".concat(prefixCls, "-content")
}, children);
var iconNode = iconType && React.createElement("td", {
className: "".concat(prefixCls, "-icon ").concat(prefixCls, "-").concat(type)
}, React.createElement(Icon, {
type: iconType
}));
return new Promise(function (resolve) {
open(_objectSpread({
key: ModalManager.getKey(),
className: "".concat(prefixCls, "-wrapper"),
border: border,
destroyOnClose: true,
okCancel: okCancel,
autoCenter: autoCenter,
closable: false,
movable: false,
style: {
width: '4.16rem'
},
children: React.createElement("table", {
className: prefixCls
}, React.createElement("tbody", null, React.createElement("tr", null, iconNode, React.createElement("td", null, titleNode, contentNode)))),
onOk: function () {
var _onOk2 = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee() {
var result;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return _onOk();
case 2:
result = _context.sent;
if (result !== false) {
resolve('ok');
}
return _context.abrupt("return", result);
case 5:
case "end":
return _context.stop();
}
}
}, _callee);
}));
function onOk() {
return _onOk2.apply(this, arguments);
}
return onOk;
}(),
onCancel: function () {
var _onCancel2 = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2() {
var result;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return _onCancel();
case 2:
result = _context2.sent;
if (result !== false) {
resolve('cancel');
}
return _context2.abrupt("return", result);
case 5:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function onCancel() {
return _onCancel2.apply(this, arguments);
}
return onCancel;
}(),
onClose: function () {
var _onClose2 = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee3() {
var result;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return _onClose();
case 2:
result = _context3.sent;
if (result !== false) {
resolve('cancel');
}
return _context3.abrupt("return", result);
case 5:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function onClose() {
return _onClose2.apply(this, arguments);
}
return onClose;
}()
}, otherProps));
});
}
//# sourceMappingURL=confirm.js.map