choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
102 lines (90 loc) • 3.58 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React from 'react';
import classnames from 'classnames';
import isObject from 'lodash/isObject';
import { getPrefixCls, getConfig } from '../configure';
import Icon from '../icon';
import NotFound from './noFound';
import ServerError from './serverError';
import Nnauthorized from './unauthorized';
import warning from '../_util/warning';
var renderStatus = function renderStatus(prefixCls, _ref) {
var _iconMap$get;
var status = _ref.status,
icon = _ref.icon,
statusRenderer = _ref.statusRenderer;
var className = classnames("".concat(prefixCls, "-icon"));
warning(!(typeof icon === 'string' && icon.length > 2), "`icon` is using ReactNode instead of string naming . Please check `".concat(icon, "` at https://choerodon.github.io/choerodon-ui/zh/cmp/general/icon")); // 初始化map
var iconMap = new Map([['403', React.createElement(Nnauthorized, {
key: "403"
})], ['404', React.createElement(NotFound, {
key: "404"
})], ['500', React.createElement(ServerError, {
key: "500"
})], ['success', React.createElement(Icon, {
key: "success",
type: "check_circle"
})], ['error', React.createElement(Icon, {
key: "error",
type: "error"
})], ['info', React.createElement(Icon, {
key: "info",
type: "info"
})], ['warning', React.createElement(Icon, {
key: "warning",
type: "warning"
})]]); // 注入全局的config
var statusRendererAll = _objectSpread({}, getConfig('resultStatusRenderer'), {}, statusRenderer);
if (isObject(statusRendererAll)) {
if (Object.keys(statusRendererAll).length > 0) {
Object.keys(statusRendererAll).forEach(function (item) {
iconMap.set(item, statusRendererAll[item]);
});
}
} // @ts-ignore
if (iconMap.get("".concat(status)) && ((_iconMap$get = iconMap.get("".concat(status))) === null || _iconMap$get === void 0 ? void 0 : _iconMap$get.type) !== Icon) {
return React.createElement("div", {
className: "".concat(className, " ").concat(prefixCls, "-image"),
style: icon || statusRenderer ? {} : "".concat(status) === '500' ? {
width: 400
} : {
width: 800
}
}, icon || iconMap.get("".concat(status)));
}
return React.createElement("div", {
className: "".concat(className)
}, icon || iconMap.get("".concat(status)));
};
var renderExtra = function renderExtra(prefixCls, _ref2) {
var extra = _ref2.extra;
return extra && React.createElement("div", {
className: "".concat(prefixCls, "-extra")
}, extra);
};
var Result = function Result(props) {
var customizePrefixCls = props.prefixCls,
customizeClassName = props.className,
subTitle = props.subTitle,
title = props.title,
style = props.style,
children = props.children,
status = props.status;
var prefixCls = getPrefixCls('result', customizePrefixCls);
var className = classnames(prefixCls, "".concat(prefixCls, "-").concat(status), customizeClassName);
return React.createElement("div", {
className: className,
style: style
}, renderStatus(prefixCls, props), React.createElement("div", {
className: "".concat(prefixCls, "-title")
}, title), subTitle && React.createElement("div", {
className: "".concat(prefixCls, "-subtitle")
}, subTitle), children && React.createElement("div", {
className: "".concat(prefixCls, "-content")
}, children), renderExtra(prefixCls, props));
};
Result.defaultProps = {
status: 'info'
};
export default Result;
//# sourceMappingURL=index.js.map