choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
106 lines (93 loc) • 3.83 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React, { useContext } from 'react';
import classnames from 'classnames';
import isObject from 'lodash/isObject';
import Icon from '../icon';
import NotFound from './noFound';
import ServerError from './serverError';
import Nnauthorized from './unauthorized';
import warning from '../_util/warning';
import ConfigContext from '../config-provider/ConfigContext';
var renderStatus = function renderStatus(prefixCls, _ref, resultStatusRenderer) {
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', /*#__PURE__*/React.createElement(Nnauthorized, {
key: "403"
})], ['404', /*#__PURE__*/React.createElement(NotFound, {
key: "404"
})], ['500', /*#__PURE__*/React.createElement(ServerError, {
key: "500"
})], ['success', /*#__PURE__*/React.createElement(Icon, {
key: "success",
type: "check_circle"
})], ['error', /*#__PURE__*/React.createElement(Icon, {
key: "error",
type: "error"
})], ['info', /*#__PURE__*/React.createElement(Icon, {
key: "info",
type: "info"
})], ['warning', /*#__PURE__*/React.createElement(Icon, {
key: "warning",
type: "warning"
})]]); // 注入全局的config
var statusRendererAll = _objectSpread(_objectSpread({}, resultStatusRenderer), statusRenderer);
if (isObject(statusRendererAll)) {
if (Object.keys(statusRendererAll).length > 0) {
Object.keys(statusRendererAll).forEach(function (item) {
iconMap.set(item, statusRendererAll[item]);
});
}
}
var statusIcon = iconMap.get(String(status));
if (statusIcon && statusIcon.type !== Icon) {
return /*#__PURE__*/React.createElement("div", {
className: "".concat(className, " ").concat(prefixCls, "-image"),
style: icon || statusRenderer ? {} : "".concat(status) === '500' ? {
width: 400
} : {
width: 800
}
}, icon || statusIcon);
}
return /*#__PURE__*/React.createElement("div", {
className: "".concat(className)
}, icon || statusIcon);
};
var renderExtra = function renderExtra(prefixCls, _ref2) {
var extra = _ref2.extra;
return extra && /*#__PURE__*/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 _useContext = useContext(ConfigContext),
getPrefixCls = _useContext.getPrefixCls,
getConfig = _useContext.getConfig;
var prefixCls = getPrefixCls('result', customizePrefixCls);
var className = classnames(prefixCls, "".concat(prefixCls, "-").concat(status), customizeClassName);
return /*#__PURE__*/React.createElement("div", {
className: className,
style: style
}, renderStatus(prefixCls, props, getConfig('resultStatusRenderer')), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-title")
}, title), subTitle && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-subtitle")
}, subTitle), children && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-content")
}, children), renderExtra(prefixCls, props));
};
Result.defaultProps = {
status: 'info'
};
export default Result;
//# sourceMappingURL=index.js.map