未验证 提交 9cd432e5 编写于 作者: A Amour1688 提交者: GitHub

chore: `useContext` in Empty (#26991)

* chore: `useContext` in Empty

* chore: update empty/index.tsx
上级 1aee1670
import * as React from 'react';
import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { ConfigContext } from '../config-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import DefaultEmptyImg from './empty';
import SimpleEmptyImg from './simple';
......@@ -30,59 +30,55 @@ interface EmptyType extends React.FC<EmptyProps> {
PRESENTED_IMAGE_SIMPLE: React.ReactNode;
}
const Empty: EmptyType = (props: EmptyProps) => (
<ConfigConsumer>
{({ getPrefixCls, direction }: ConfigConsumerProps) => {
const {
className,
prefixCls: customizePrefixCls,
image = defaultEmptyImg,
description,
children,
imageStyle,
...restProps
} = props;
const Empty: EmptyType = ({
className,
prefixCls: customizePrefixCls,
image = defaultEmptyImg,
description,
children,
imageStyle,
...restProps
}) => {
const { getPrefixCls, direction } = React.useContext(ConfigContext);
return (
<LocaleReceiver componentName="Empty">
{(locale: TransferLocale) => {
const prefixCls = getPrefixCls('empty', customizePrefixCls);
const des = typeof description !== 'undefined' ? description : locale.description;
const alt = typeof des === 'string' ? des : 'empty';
return (
<LocaleReceiver componentName="Empty">
{(locale: TransferLocale) => {
const prefixCls = getPrefixCls('empty', customizePrefixCls);
const des = typeof description !== 'undefined' ? description : locale.description;
const alt = typeof des === 'string' ? des : 'empty';
let imageNode: React.ReactNode = null;
let imageNode: React.ReactNode = null;
if (typeof image === 'string') {
imageNode = <img alt={alt} src={image} />;
} else {
imageNode = image;
}
if (typeof image === 'string') {
imageNode = <img alt={alt} src={image} />;
} else {
imageNode = image;
}
return (
<div
className={classNames(
prefixCls,
{
[`${prefixCls}-normal`]: image === simpleEmptyImg,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
)}
{...restProps}
>
<div className={`${prefixCls}-image`} style={imageStyle}>
{imageNode}
</div>
{des && <p className={`${prefixCls}-description`}>{des}</p>}
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
</div>
);
}}
</LocaleReceiver>
);
}}
</ConfigConsumer>
);
return (
<div
className={classNames(
prefixCls,
{
[`${prefixCls}-normal`]: image === simpleEmptyImg,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
)}
{...restProps}
>
<div className={`${prefixCls}-image`} style={imageStyle}>
{imageNode}
</div>
{des && <p className={`${prefixCls}-description`}>{des}</p>}
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
</div>
);
}}
</LocaleReceiver>
);
};
Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册