ant-design/components/empty/index.tsx

98 lines
2.4 KiB
TypeScript
Raw Normal View History

feat: prepend use-client directive for with Next.js App Router (#43573) * fix: prepend use-client directive for with Next.js App Router * Update components/affix/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/badge/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/divider/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/cascader/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/list/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/mentions/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/mentions/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/mentions/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/mentions/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/qrcode/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/spin/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/select/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/spin/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/spin/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/steps/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/time-picker/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/transfer/index.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/tree-select/index.tsx Signed-off-by: lijianan <574980606@qq.com> --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: MadCcc <1075746765@qq.com>
2023-07-15 12:57:03 +08:00
'use client';
2018-12-26 16:01:00 +08:00
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import { useLocale } from '../locale';
import DefaultEmptyImg from './empty';
import SimpleEmptyImg from './simple';
import useStyle from './style';
const defaultEmptyImg = <DefaultEmptyImg />;
const simpleEmptyImg = <SimpleEmptyImg />;
2018-12-26 16:01:00 +08:00
export interface TransferLocale {
description: string;
}
2018-12-26 16:01:00 +08:00
export interface EmptyProps {
prefixCls?: string;
className?: string;
rootClassName?: string;
2018-12-26 16:01:00 +08:00
style?: React.CSSProperties;
/** @since 3.16.0 */
imageStyle?: React.CSSProperties;
image?: React.ReactNode;
description?: React.ReactNode;
2018-12-26 16:01:00 +08:00
children?: React.ReactNode;
}
type CompoundedComponent = React.FC<EmptyProps> & {
PRESENTED_IMAGE_DEFAULT: React.ReactNode;
PRESENTED_IMAGE_SIMPLE: React.ReactNode;
};
const Empty: CompoundedComponent = ({
className,
rootClassName,
prefixCls: customizePrefixCls,
image = defaultEmptyImg,
description,
children,
imageStyle,
style,
...restProps
}) => {
const { getPrefixCls, direction, empty } = React.useContext(ConfigContext);
2018-12-26 16:01:00 +08:00
const prefixCls = getPrefixCls('empty', customizePrefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls);
const [locale] = useLocale('Empty');
const des = typeof description !== 'undefined' ? description : locale?.description;
const alt = typeof des === 'string' ? des : 'empty';
2018-12-26 16:01:00 +08:00
let imageNode: React.ReactNode = null;
if (typeof image === 'string') {
imageNode = <img alt={alt} src={image} />;
} else {
imageNode = image;
}
2018-12-26 16:01:00 +08:00
return wrapSSR(
<div
className={classNames(
hashId,
prefixCls,
empty?.className,
{
[`${prefixCls}-normal`]: image === simpleEmptyImg,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
rootClassName,
)}
style={{ ...empty?.style, ...style }}
{...restProps}
>
<div className={`${prefixCls}-image`} style={imageStyle}>
{imageNode}
</div>
{des && <div className={`${prefixCls}-description`}>{des}</div>}
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
</div>,
);
};
2018-12-26 16:01:00 +08:00
Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
if (process.env.NODE_ENV !== 'production') {
Empty.displayName = 'Empty';
}
2018-12-26 16:01:00 +08:00
export default Empty;