123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- "use client";
- import * as React from 'react';
- import CheckCircleFilled from "@ant-design/icons/es/icons/CheckCircleFilled";
- import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled";
- import ExclamationCircleFilled from "@ant-design/icons/es/icons/ExclamationCircleFilled";
- import WarningFilled from "@ant-design/icons/es/icons/WarningFilled";
- import classNames from 'classnames';
- import { devUseWarning } from '../_util/warning';
- import { ConfigContext } from '../config-provider';
- import noFound from './noFound';
- import serverError from './serverError';
- import useStyle from './style';
- import unauthorized from './unauthorized';
- export const IconMap = {
- success: CheckCircleFilled,
- error: CloseCircleFilled,
- info: ExclamationCircleFilled,
- warning: WarningFilled
- };
- export const ExceptionMap = {
- '404': noFound,
- '500': serverError,
- '403': unauthorized
- };
- // ExceptionImageMap keys
- const ExceptionStatus = Object.keys(ExceptionMap);
- const Icon = ({
- prefixCls,
- icon,
- status
- }) => {
- const className = classNames(`${prefixCls}-icon`);
- if (process.env.NODE_ENV !== 'production') {
- const warning = devUseWarning('Result');
- 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;
- }
- if (ExceptionStatus.includes(`${status}`)) {
- const SVGComponent = ExceptionMap[status];
- return /*#__PURE__*/React.createElement("div", {
- className: `${className} ${prefixCls}-image`
- }, /*#__PURE__*/React.createElement(SVGComponent, null));
- }
- const iconNode = /*#__PURE__*/React.createElement(IconMap[status]);
- if (icon === null || icon === false) {
- return null;
- }
- return /*#__PURE__*/React.createElement("div", {
- className: className
- }, icon || iconNode);
- };
- const Extra = ({
- prefixCls,
- extra
- }) => {
- if (!extra) {
- return null;
- }
- return /*#__PURE__*/React.createElement("div", {
- className: `${prefixCls}-extra`
- }, extra);
- };
- const Result = ({
- prefixCls: customizePrefixCls,
- className: customizeClassName,
- rootClassName,
- subTitle,
- title,
- style,
- children,
- status = 'info',
- icon,
- extra
- }) => {
- const {
- getPrefixCls,
- direction,
- result
- } = React.useContext(ConfigContext);
- const prefixCls = getPrefixCls('result', customizePrefixCls);
- // Style
- const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
- const className = classNames(prefixCls, `${prefixCls}-${status}`, customizeClassName, result === null || result === void 0 ? void 0 : result.className, rootClassName, {
- [`${prefixCls}-rtl`]: direction === 'rtl'
- }, hashId, cssVarCls);
- const mergedStyle = Object.assign(Object.assign({}, result === null || result === void 0 ? void 0 : result.style), style);
- return wrapCSSVar(/*#__PURE__*/React.createElement("div", {
- className: className,
- style: mergedStyle
- }, /*#__PURE__*/React.createElement(Icon, {
- prefixCls: prefixCls,
- status: status,
- icon: icon
- }), /*#__PURE__*/React.createElement("div", {
- className: `${prefixCls}-title`
- }, title), subTitle && /*#__PURE__*/React.createElement("div", {
- className: `${prefixCls}-subtitle`
- }, subTitle), /*#__PURE__*/React.createElement(Extra, {
- prefixCls: prefixCls,
- extra: extra
- }), children && /*#__PURE__*/React.createElement("div", {
- className: `${prefixCls}-content`
- }, children)));
- };
- Result.PRESENTED_IMAGE_403 = ExceptionMap['403'];
- Result.PRESENTED_IMAGE_404 = ExceptionMap['404'];
- Result.PRESENTED_IMAGE_500 = ExceptionMap['500'];
- if (process.env.NODE_ENV !== 'production') {
- Result.displayName = 'Result';
- }
- export default Result;
|