@alicloud/console-components
Version:
Alibaba Cloud React Components
114 lines (113 loc) • 6.25 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var react_dom_1 = require("react-dom");
var next_1 = require("@alifd/next");
var drawer_1 = __importDefault(require("../drawer"));
// 快捷调用
function drawerShow(props) {
var onOk = props.onOk, onCancel = props.onCancel, onClose = props.onClose, content = props.content, others = __rest(props, ["onOk", "onCancel", "onClose", "content"]);
var actionRef;
// 合并 customOnOK。 如果返回值为 true 自动关闭 Drawer
// eslint-disable-next-line @typescript-eslint/naming-convention
var customOnOK = function (event) {
var _a, _b, _c;
if (onOk) {
var result = onOk(event);
if (result instanceof Promise) {
(_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.setOKLoading) === null || _a === void 0 ? void 0 : _a.call(actionRef, true);
result.then(function (state) {
var _a, _b, _c;
if (state !== false) {
(_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.setOKLoading) === null || _a === void 0 ? void 0 : _a.call(actionRef, false);
(_b = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _b === void 0 ? void 0 : _b.call(actionRef);
return;
}
(_c = actionRef === null || actionRef === void 0 ? void 0 : actionRef.setOKLoading) === null || _c === void 0 ? void 0 : _c.call(actionRef, false);
}).catch(function () {
// ignore
});
}
if (typeof result === 'boolean' && result) {
(_b = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _b === void 0 ? void 0 : _b.call(actionRef);
}
}
else {
(_c = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _c === void 0 ? void 0 : _c.call(actionRef);
}
};
var customOnCancel = function (event) {
var _a, _b, _c;
if (onCancel) {
var result = onCancel(event);
if (result instanceof Promise) {
(_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.setCancelLoading) === null || _a === void 0 ? void 0 : _a.call(actionRef, true);
result.then(function (state) {
var _a, _b;
if (state !== false) {
(_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.setCancelLoading) === null || _a === void 0 ? void 0 : _a.call(actionRef, false);
(_b = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _b === void 0 ? void 0 : _b.call(actionRef);
}
}).catch(function () {
// ignore
});
}
if (typeof result === 'boolean' && result) {
(_b = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _b === void 0 ? void 0 : _b.call(actionRef);
}
}
else {
(_c = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _c === void 0 ? void 0 : _c.call(actionRef);
}
};
var ConfigModal = next_1.ConfigProvider.config(drawer_1.default, {
componentName: 'Drawer'
});
var container = document.createElement('div');
container.setAttribute('id', 'next-quick-drawer');
document.body.appendChild(container);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
var newContext = next_1.ConfigProvider.getContext();
(0, react_dom_1.render)(react_1.default.createElement(next_1.ConfigProvider, __assign({}, newContext),
react_1.default.createElement(ConfigModal, __assign({}, __assign(__assign({}, others), { visible: true,
// eslint-disable-next-line @typescript-eslint/no-shadow,@typescript-eslint/naming-convention
actionRef: function (show, close, setOKLoading, setCancelLoading) {
actionRef = {
show: show,
close: close,
setOKLoading: setOKLoading,
setCancelLoading: setCancelLoading
};
}, onOk: customOnOK, onCancel: customOnCancel, onClose: onClose !== null && onClose !== void 0 ? onClose : (function () { var _a; return (_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _a === void 0 ? void 0 : _a.call(actionRef); }) })), content)), container);
return {
hide: function () { var _a; return (_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.close) === null || _a === void 0 ? void 0 : _a.call(actionRef); },
show: function () { var _a; return (_a = actionRef === null || actionRef === void 0 ? void 0 : actionRef.show) === null || _a === void 0 ? void 0 : _a.call(actionRef); }
};
}
exports.default = drawerShow;