From 8227a53791cda2b14d348e53acc2f76b0476ee07 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Tue, 21 Jun 2022 19:17:20 +0800 Subject: [PATCH] style: Code style optimization (#36144) * style: code style optimization * style: code style optimization * style: code style optimization --- components/result/index.tsx | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/components/result/index.tsx b/components/result/index.tsx index dcbf7ead25..a8ec027b32 100644 --- a/components/result/index.tsx +++ b/components/result/index.tsx @@ -1,9 +1,9 @@ -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 classNames from 'classnames'; +import * as React from 'react'; import { ConfigContext } from '../config-provider'; import warning from '../_util/warning'; @@ -49,7 +49,14 @@ const ExceptionStatus = Object.keys(ExceptionMap); * @param prefixCls * @param {status, icon} */ -const renderIcon = (prefixCls: string, { status, icon }: ResultProps) => { + +interface IconProps { + prefixCls: string; + icon: React.ReactNode; + status: ResultStatusType; +} + +const Icon: React.FC = ({ prefixCls, icon, status }) => { const className = classNames(`${prefixCls}-icon`); warning( @@ -73,8 +80,17 @@ const renderIcon = (prefixCls: string, { status, icon }: ResultProps) => { return
{icon || iconNode}
; }; -const renderExtra = (prefixCls: string, { extra }: ResultProps) => - extra &&
{extra}
; +interface ExtraProps { + prefixCls: string; + extra: React.ReactNode; +} + +const Extra: React.FC = ({ prefixCls, extra }) => { + if (!extra) { + return null; + } + return
{extra}
; +}; export interface ResultType extends React.FC { PRESENTED_IMAGE_404: React.FC; @@ -101,10 +117,10 @@ const Result: ResultType = ({ }); return (
- {renderIcon(prefixCls, { status, icon })} +
{title}
{subTitle &&
{subTitle}
} - {renderExtra(prefixCls, { extra })} + {children &&
{children}
}
);