2023-07-15 12:57:03 +08:00
|
|
|
'use client';
|
|
|
|
|
2018-12-26 16:01:00 +08:00
|
|
|
import classNames from 'classnames';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2020-10-02 14:00:02 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-03-21 13:08:43 +08:00
|
|
|
import { useLocale } from '../locale';
|
2019-08-02 21:37:26 +08:00
|
|
|
import DefaultEmptyImg from './empty';
|
|
|
|
import SimpleEmptyImg from './simple';
|
|
|
|
|
2022-04-02 18:17:14 +08:00
|
|
|
import useStyle from './style';
|
|
|
|
|
2019-08-02 21:37:26 +08:00
|
|
|
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;
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName?: string;
|
2018-12-26 16:01:00 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-01 14:33:51 +08:00
|
|
|
type CompoundedComponent = React.FC<EmptyProps> & {
|
2019-08-02 21:37:26 +08:00
|
|
|
PRESENTED_IMAGE_DEFAULT: React.ReactNode;
|
|
|
|
PRESENTED_IMAGE_SIMPLE: React.ReactNode;
|
2022-12-01 14:33:51 +08:00
|
|
|
};
|
2019-08-02 21:37:26 +08:00
|
|
|
|
2022-12-01 14:33:51 +08:00
|
|
|
const Empty: CompoundedComponent = ({
|
2020-10-02 14:00:02 +08:00
|
|
|
className,
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName,
|
2020-10-02 14:00:02 +08:00
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
image = defaultEmptyImg,
|
|
|
|
description,
|
|
|
|
children,
|
|
|
|
imageStyle,
|
2023-06-26 17:10:26 +08:00
|
|
|
style,
|
2020-10-02 14:00:02 +08:00
|
|
|
...restProps
|
|
|
|
}) => {
|
2023-06-26 17:10:26 +08:00
|
|
|
const { getPrefixCls, direction, empty } = React.useContext(ConfigContext);
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2022-04-02 18:17:14 +08:00
|
|
|
const prefixCls = getPrefixCls('empty', customizePrefixCls);
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
|
2023-02-24 10:51:59 +08:00
|
|
|
const [locale] = useLocale('Empty');
|
2023-02-22 18:18:26 +08:00
|
|
|
|
|
|
|
const des = typeof description !== 'undefined' ? description : locale?.description;
|
|
|
|
const alt = typeof des === 'string' ? des : 'empty';
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2023-02-22 18:18:26 +08:00
|
|
|
let imageNode: React.ReactNode = null;
|
2019-03-20 17:45:35 +08:00
|
|
|
|
2023-02-22 18:18:26 +08:00
|
|
|
if (typeof image === 'string') {
|
|
|
|
imageNode = <img alt={alt} src={image} />;
|
|
|
|
} else {
|
|
|
|
imageNode = image;
|
|
|
|
}
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2023-02-22 18:18:26 +08:00
|
|
|
return wrapSSR(
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
hashId,
|
|
|
|
prefixCls,
|
2023-06-26 17:10:26 +08:00
|
|
|
empty?.className,
|
2023-02-22 18:18:26 +08:00
|
|
|
{
|
|
|
|
[`${prefixCls}-normal`]: image === simpleEmptyImg,
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
rootClassName,
|
|
|
|
)}
|
2023-06-26 17:10:26 +08:00
|
|
|
style={{ ...empty?.style, ...style }}
|
2023-02-22 18:18:26 +08:00
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
<div className={`${prefixCls}-image`} style={imageStyle}>
|
|
|
|
{imageNode}
|
|
|
|
</div>
|
|
|
|
{des && <div className={`${prefixCls}-description`}>{des}</div>}
|
|
|
|
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
|
|
|
|
</div>,
|
2020-10-02 14:00:02 +08:00
|
|
|
);
|
|
|
|
};
|
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;
|
|
|
|
|
2023-01-08 21:30:41 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Empty.displayName = 'Empty';
|
|
|
|
}
|
|
|
|
|
2018-12-26 16:01:00 +08:00
|
|
|
export default Empty;
|