zent
Version:
一套前端设计语言和基于React的实现
51 lines (50 loc) • 2.93 kB
JavaScript
import { __assign } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import cx from 'classnames';
import { I18nReceiver as Receiver } from '../i18n';
import Dialog from '../dialog';
import Icon from '../icon';
import ActionButton from './ActionButton';
import { TitleIconMap } from './constants';
var openDialog = Dialog.openDialog;
function sweet(config, sweetType) {
var _a;
var _b = config.className, className = _b === void 0 ? '' : _b, _c = config.confirmType, confirmType = _c === void 0 ? 'primary' : _c, _d = config.closeBtn, closeBtn = _d === void 0 ? false : _d, _e = config.maskClosable, maskClosable = _e === void 0 ? false : _e, title = config.title, type = config.type, content = config.content, onConfirm = config.onConfirm, onCancel = config.onCancel, confirmText = config.confirmText, cancelText = config.cancelText, parentComponent = config.parentComponent, onClose = config.onClose;
var close = null;
var renderTitle = function (i18n) {
var icon = TitleIconMap[type];
return (_jsxs("div", __assign({ className: "zent-sweetalert-" + (type ? 'icon-' : '') + "title", "data-zv": '10.0.17' }, { children: [type && _jsx(Icon, { className: "zent-sweetalert-type-icon", type: icon }, void 0), title || i18n.title] }), void 0));
};
var renderButtons = function (i18n) {
var isAlert = sweetType === 'alert';
return (_jsxs("div", __assign({ className: "sweet-" + sweetType + "-actions", "data-zv": '10.0.17' }, { children: [!isAlert && (_jsx(ActionButton, { type: "default", className: "zent-sweetalert-" + sweetType + "-btn-cancel", getClose: function () { return close; }, onClick: onCancel, text: cancelText || i18n.cancel }, "sweetalert-cancel")), _jsx(ActionButton, { type: confirmType, className: "zent-sweetalert-" + sweetType + "-btn-confirm", getClose: function () { return close; }, onClick: onConfirm, text: confirmText || (isAlert ? i18n.ok : i18n.confirm) }, "sweetalert-confirm")] }), void 0));
};
close = openDialog({
closeBtn: closeBtn,
maskClosable: maskClosable,
className: cx("zent-sweetalert-" + sweetType, (_a = {},
_a[className] = !!className,
_a)),
title: _jsx(Receiver, __assign({ componentName: "Sweetalert" }, { children: renderTitle }), void 0),
children: content,
footer: _jsx(Receiver, __assign({ componentName: "Sweetalert" }, { children: renderButtons }), void 0),
parentComponent: parentComponent,
onClose: onClose,
});
return close;
}
export function alert(config) {
if (config === void 0) { config = {}; }
return sweet(config, 'alert');
}
export var info = alert;
export function confirm(config) {
if (config === void 0) { config = {}; }
return sweet(config, 'confirm');
}
export var Sweetalert = {
alert: alert,
info: info,
confirm: confirm,
};
export default Sweetalert;