2018-12-26 16:01:00 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import * as React from 'react';
|
2020-10-02 14:00:02 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2018-12-26 16:01:00 +08:00
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2019-08-02 21:37:26 +08:00
|
|
|
import DefaultEmptyImg from './empty';
|
|
|
|
import SimpleEmptyImg from './simple';
|
|
|
|
|
|
|
|
const defaultEmptyImg = <DefaultEmptyImg />;
|
|
|
|
const simpleEmptyImg = <SimpleEmptyImg />;
|
2018-12-26 16:01:00 +08:00
|
|
|
|
|
|
|
export interface TransferLocale {
|
|
|
|
description: string;
|
|
|
|
}
|
2019-03-18 12:01:38 +08:00
|
|
|
|
2018-12-26 16:01:00 +08:00
|
|
|
export interface EmptyProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
2020-12-28 15:30:18 +08:00
|
|
|
/** @since 3.16.0 */
|
2019-03-20 17:45:35 +08:00
|
|
|
imageStyle?: React.CSSProperties;
|
|
|
|
image?: React.ReactNode;
|
2019-07-16 22:06:58 +08:00
|
|
|
description?: React.ReactNode;
|
2018-12-26 16:01:00 +08:00
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:37:26 +08:00
|
|
|
interface EmptyType extends React.FC<EmptyProps> {
|
|
|
|
PRESENTED_IMAGE_DEFAULT: React.ReactNode;
|
|
|
|
PRESENTED_IMAGE_SIMPLE: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2020-10-02 14:00:02 +08:00
|
|
|
const Empty: EmptyType = ({
|
|
|
|
className,
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
image = defaultEmptyImg,
|
|
|
|
description,
|
|
|
|
children,
|
|
|
|
imageStyle,
|
|
|
|
...restProps
|
|
|
|
}) => {
|
|
|
|
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2020-10-02 14:00:02 +08:00
|
|
|
return (
|
|
|
|
<LocaleReceiver componentName="Empty">
|
2022-10-01 22:17:14 +08:00
|
|
|
{contextLocale => {
|
2020-10-02 14:00:02 +08:00
|
|
|
const prefixCls = getPrefixCls('empty', customizePrefixCls);
|
2022-10-01 22:17:14 +08:00
|
|
|
const des = typeof description !== 'undefined' ? description : contextLocale.description;
|
2020-10-02 14:00:02 +08:00
|
|
|
const alt = typeof des === 'string' ? des : 'empty';
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2020-10-02 14:00:02 +08:00
|
|
|
let imageNode: React.ReactNode = null;
|
2019-03-20 17:45:35 +08:00
|
|
|
|
2020-10-02 14:00:02 +08:00
|
|
|
if (typeof image === 'string') {
|
|
|
|
imageNode = <img alt={alt} src={image} />;
|
|
|
|
} else {
|
|
|
|
imageNode = image;
|
|
|
|
}
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2020-10-02 14:00:02 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
prefixCls,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-normal`]: image === simpleEmptyImg,
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
<div className={`${prefixCls}-image`} style={imageStyle}>
|
|
|
|
{imageNode}
|
|
|
|
</div>
|
2021-01-14 16:29:48 +08:00
|
|
|
{des && <div className={`${prefixCls}-description`}>{des}</div>}
|
2020-10-02 14:00:02 +08:00
|
|
|
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</LocaleReceiver>
|
|
|
|
);
|
|
|
|
};
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2019-03-20 17:45:35 +08:00
|
|
|
Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
|
|
|
|
Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
|
|
|
|
|
2018-12-26 16:01:00 +08:00
|
|
|
export default Empty;
|