You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.6 KiB
95 lines
3.6 KiB
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled';
|
|
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
|
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
|
|
import WarningFilled from '@ant-design/icons/WarningFilled';
|
|
import { ConfigConsumer } from '../config-provider';
|
|
import devWarning from '../_util/devWarning';
|
|
import noFound from './noFound';
|
|
import serverError from './serverError';
|
|
import unauthorized from './unauthorized';
|
|
export var IconMap = {
|
|
success: CheckCircleFilled,
|
|
error: CloseCircleFilled,
|
|
info: ExclamationCircleFilled,
|
|
warning: WarningFilled
|
|
};
|
|
export var ExceptionMap = {
|
|
'404': noFound,
|
|
'500': serverError,
|
|
'403': unauthorized
|
|
}; // ExceptionImageMap keys
|
|
|
|
var ExceptionStatus = Object.keys(ExceptionMap);
|
|
/**
|
|
* render icon
|
|
* if ExceptionStatus includes ,render svg image
|
|
* else render iconNode
|
|
* @param prefixCls
|
|
* @param {status, icon}
|
|
*/
|
|
|
|
var renderIcon = function renderIcon(prefixCls, _ref) {
|
|
var status = _ref.status,
|
|
icon = _ref.icon;
|
|
var className = classNames("".concat(prefixCls, "-icon"));
|
|
devWarning(!(typeof icon === 'string' && icon.length > 2), 'Result', "`icon` is using ReactNode instead of string naming in v4. Please check `".concat(icon, "` at https://ant.design/components/icon"));
|
|
|
|
if (ExceptionStatus.includes("".concat(status))) {
|
|
var SVGComponent = ExceptionMap[status];
|
|
return /*#__PURE__*/React.createElement("div", {
|
|
className: "".concat(className, " ").concat(prefixCls, "-image")
|
|
}, /*#__PURE__*/React.createElement(SVGComponent, null));
|
|
}
|
|
|
|
var iconNode = /*#__PURE__*/React.createElement(IconMap[status]);
|
|
return /*#__PURE__*/React.createElement("div", {
|
|
className: className
|
|
}, icon || iconNode);
|
|
};
|
|
|
|
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) {
|
|
return /*#__PURE__*/React.createElement(ConfigConsumer, null, function (_ref3) {
|
|
var getPrefixCls = _ref3.getPrefixCls,
|
|
direction = _ref3.direction;
|
|
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, _defineProperty({}, "".concat(prefixCls, "-rtl"), direction === 'rtl'));
|
|
return /*#__PURE__*/React.createElement("div", {
|
|
className: className,
|
|
style: style
|
|
}, renderIcon(prefixCls, props), /*#__PURE__*/React.createElement("div", {
|
|
className: "".concat(prefixCls, "-title")
|
|
}, title), subTitle && /*#__PURE__*/React.createElement("div", {
|
|
className: "".concat(prefixCls, "-subtitle")
|
|
}, subTitle), renderExtra(prefixCls, props), children && /*#__PURE__*/React.createElement("div", {
|
|
className: "".concat(prefixCls, "-content")
|
|
}, children));
|
|
});
|
|
};
|
|
|
|
Result.defaultProps = {
|
|
status: 'info'
|
|
}; // eslint-disable-next-line prefer-destructuring
|
|
|
|
Result.PRESENTED_IMAGE_403 = ExceptionMap[403]; // eslint-disable-next-line prefer-destructuring
|
|
|
|
Result.PRESENTED_IMAGE_404 = ExceptionMap[404]; // eslint-disable-next-line prefer-destructuring
|
|
|
|
Result.PRESENTED_IMAGE_500 = ExceptionMap[500];
|
|
export default Result; |