2023-02-07 01:57:31 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2023-02-07 02:06:05 +00:00
|
|
|
import type { CSSProperties, ExtractPropTypes } from 'vue';
|
2020-09-16 04:54:54 +00:00
|
|
|
import classNames from '../_util/classNames';
|
2019-03-07 05:26:03 +00:00
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2020-03-07 11:45:13 +00:00
|
|
|
import DefaultEmptyImg from './empty';
|
|
|
|
import SimpleEmptyImg from './simple';
|
2020-08-15 16:21:58 +00:00
|
|
|
import { filterEmpty } from '../_util/props-util';
|
2023-02-07 02:06:05 +00:00
|
|
|
import type { VueNode } from '../_util/type';
|
|
|
|
import { anyType, objectType, withInstall } from '../_util/type';
|
2023-01-27 08:00:17 +00:00
|
|
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
2019-03-07 05:26:03 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
import useStyle from './style';
|
|
|
|
|
2020-08-15 07:33:47 +00:00
|
|
|
const defaultEmptyImg = <DefaultEmptyImg />;
|
|
|
|
const simpleEmptyImg = <SimpleEmptyImg />;
|
2019-03-07 05:26:03 +00:00
|
|
|
|
2021-06-23 13:47:53 +00:00
|
|
|
interface Locale {
|
2020-10-13 09:46:52 +00:00
|
|
|
description?: string;
|
2020-08-15 07:33:47 +00:00
|
|
|
}
|
2019-03-07 05:26:03 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
export const emptyProps = () => ({
|
|
|
|
prefixCls: String,
|
2023-02-07 02:06:05 +00:00
|
|
|
imageStyle: objectType<CSSProperties>(),
|
|
|
|
image: anyType<VueNode>(),
|
|
|
|
description: anyType<VueNode>(),
|
2023-02-07 01:57:31 +00:00
|
|
|
});
|
2020-08-23 08:45:55 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
export type EmptyProps = Partial<ExtractPropTypes<ReturnType<typeof emptyProps>>>;
|
2020-10-01 14:48:33 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
const Empty = defineComponent({
|
|
|
|
name: 'AEmpty',
|
2023-02-07 02:06:05 +00:00
|
|
|
compatConfig: { MODE: 3 },
|
2023-02-07 01:57:31 +00:00
|
|
|
inheritAttrs: false,
|
|
|
|
props: emptyProps(),
|
|
|
|
setup(props, { slots = {}, attrs }) {
|
|
|
|
const { direction, prefixCls: prefixClsRef } = useConfigInject('empty', props);
|
2022-03-12 01:56:32 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
const [wrapSSR, hashId] = useStyle(prefixClsRef);
|
2019-03-07 05:26:03 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
return () => {
|
|
|
|
const prefixCls = prefixClsRef.value;
|
|
|
|
const {
|
2023-02-07 02:06:05 +00:00
|
|
|
image = slots.image?.() || defaultEmptyImg,
|
2023-02-07 01:57:31 +00:00
|
|
|
description = slots.description?.() || undefined,
|
|
|
|
imageStyle,
|
|
|
|
class: className = '',
|
|
|
|
...restProps
|
|
|
|
} = { ...props, ...attrs };
|
2020-08-15 07:33:47 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
return wrapSSR(
|
|
|
|
<LocaleReceiver
|
|
|
|
componentName="Empty"
|
|
|
|
children={(locale: Locale) => {
|
|
|
|
const des = typeof description !== 'undefined' ? description : locale.description;
|
|
|
|
const alt = typeof des === 'string' ? des : 'empty';
|
|
|
|
let imageNode: EmptyProps['image'] = null;
|
2020-08-15 07:33:47 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
if (typeof image === 'string') {
|
|
|
|
imageNode = <img alt={alt} src={image} />;
|
|
|
|
} else {
|
|
|
|
imageNode = image;
|
|
|
|
}
|
2019-03-07 05:26:03 +00:00
|
|
|
|
2023-02-07 01:57:31 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={classNames(prefixCls, className, hashId.value, {
|
|
|
|
[`${prefixCls}-normal`]: image === simpleEmptyImg,
|
|
|
|
[`${prefixCls}-rtl`]: direction.value === 'rtl',
|
|
|
|
})}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
<div class={`${prefixCls}-image`} style={imageStyle}>
|
|
|
|
{imageNode}
|
|
|
|
</div>
|
|
|
|
{des && <p class={`${prefixCls}-description`}>{des}</p>}
|
|
|
|
{slots.default && (
|
|
|
|
<div class={`${prefixCls}-footer`}>{filterEmpty(slots.default())}</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2020-09-16 04:54:54 +00:00
|
|
|
|
2020-08-15 07:33:47 +00:00
|
|
|
Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
|
|
|
|
Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2020-11-01 07:03:33 +00:00
|
|
|
export default withInstall(Empty);
|