index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use client";
  2. import * as React from 'react';
  3. import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
  4. import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
  5. import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
  6. import WarningFilled from "@ant-design/icons/es/icons/WarningFilled";
  7. import classNames from 'classnames';
  8. import { devUseWarning } from '../_util/warning';
  9. import { ConfigContext } from '../config-provider';
  10. import noFound from './noFound';
  11. import serverError from './serverError';
  12. import useStyle from './style';
  13. import unauthorized from './unauthorized';
  14. export const IconMap = {
  15. success: CheckCircleFilled,
  16. error: CloseCircleFilled,
  17. info: ExclamationCircleFilled,
  18. warning: WarningFilled
  19. };
  20. export const ExceptionMap = {
  21. '404': noFound,
  22. '500': serverError,
  23. '403': unauthorized
  24. };
  25. // ExceptionImageMap keys
  26. const ExceptionStatus = Object.keys(ExceptionMap);
  27. const Icon = ({
  28. prefixCls,
  29. icon,
  30. status
  31. }) => {
  32. const className = classNames(`${prefixCls}-icon`);
  33. if (process.env.NODE_ENV !== 'production') {
  34. const warning = devUseWarning('Result');
  35. process.env.NODE_ENV !== "production" ? warning(!(typeof icon === 'string' && icon.length > 2), 'breaking', `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`) : void 0;
  36. }
  37. if (ExceptionStatus.includes(`${status}`)) {
  38. const SVGComponent = ExceptionMap[status];
  39. return /*#__PURE__*/React.createElement("div", {
  40. className: `${className} ${prefixCls}-image`
  41. }, /*#__PURE__*/React.createElement(SVGComponent, null));
  42. }
  43. const iconNode = /*#__PURE__*/React.createElement(IconMap[status]);
  44. if (icon === null || icon === false) {
  45. return null;
  46. }
  47. return /*#__PURE__*/React.createElement("div", {
  48. className: className
  49. }, icon || iconNode);
  50. };
  51. const Extra = ({
  52. prefixCls,
  53. extra
  54. }) => {
  55. if (!extra) {
  56. return null;
  57. }
  58. return /*#__PURE__*/React.createElement("div", {
  59. className: `${prefixCls}-extra`
  60. }, extra);
  61. };
  62. const Result = ({
  63. prefixCls: customizePrefixCls,
  64. className: customizeClassName,
  65. rootClassName,
  66. subTitle,
  67. title,
  68. style,
  69. children,
  70. status = 'info',
  71. icon,
  72. extra
  73. }) => {
  74. const {
  75. getPrefixCls,
  76. direction,
  77. result
  78. } = React.useContext(ConfigContext);
  79. const prefixCls = getPrefixCls('result', customizePrefixCls);
  80. // Style
  81. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
  82. const className = classNames(prefixCls, `${prefixCls}-${status}`, customizeClassName, result === null || result === void 0 ? void 0 : result.className, rootClassName, {
  83. [`${prefixCls}-rtl`]: direction === 'rtl'
  84. }, hashId, cssVarCls);
  85. const mergedStyle = Object.assign(Object.assign({}, result === null || result === void 0 ? void 0 : result.style), style);
  86. return wrapCSSVar(/*#__PURE__*/React.createElement("div", {
  87. className: className,
  88. style: mergedStyle
  89. }, /*#__PURE__*/React.createElement(Icon, {
  90. prefixCls: prefixCls,
  91. status: status,
  92. icon: icon
  93. }), /*#__PURE__*/React.createElement("div", {
  94. className: `${prefixCls}-title`
  95. }, title), subTitle && /*#__PURE__*/React.createElement("div", {
  96. className: `${prefixCls}-subtitle`
  97. }, subTitle), /*#__PURE__*/React.createElement(Extra, {
  98. prefixCls: prefixCls,
  99. extra: extra
  100. }), children && /*#__PURE__*/React.createElement("div", {
  101. className: `${prefixCls}-content`
  102. }, children)));
  103. };
  104. Result.PRESENTED_IMAGE_403 = ExceptionMap['403'];
  105. Result.PRESENTED_IMAGE_404 = ExceptionMap['404'];
  106. Result.PRESENTED_IMAGE_500 = ExceptionMap['500'];
  107. if (process.env.NODE_ENV !== 'production') {
  108. Result.displayName = 'Result';
  109. }
  110. export default Result;