forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
95 lines (83 loc) · 2.89 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { defineComponent } from 'vue';
import type { CSSProperties, PropType } from 'vue';
import classNames from '../_util/classNames';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import DefaultEmptyImg from './empty';
import SimpleEmptyImg from './simple';
import { filterEmpty } from '../_util/props-util';
import PropTypes from '../_util/vue-types';
import type { VueNode } from '../_util/type';
import { withInstall } from '../_util/type';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import useStyle from './style';
const defaultEmptyImg = <DefaultEmptyImg />;
const simpleEmptyImg = <SimpleEmptyImg />;
interface Locale {
description?: string;
}
export interface EmptyProps {
prefixCls?: string;
class?: any;
style?: string | CSSProperties;
imageStyle?: CSSProperties;
image?: VueNode | null;
description?: VueNode;
}
const Empty = defineComponent({
name: 'AEmpty',
setup(props, { slots = {}, attrs }) {
const { direction, prefixCls: prefixClsRef } = useConfigInject('empty', props);
const prefixCls = prefixClsRef.value;
const [wrapSSR, hashId] = useStyle(prefixClsRef);
const {
image = defaultEmptyImg,
description = slots.description?.() || undefined,
imageStyle,
class: className = '',
...restProps
} = { ...props, ...attrs };
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;
if (typeof image === 'string') {
imageNode = <img alt={alt} src={image} />;
} else {
imageNode = image;
}
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>
);
}}
/>,
);
},
});
Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
Empty.inheritAttrs = false;
Empty.props = {
prefixCls: String,
image: PropTypes.any,
description: PropTypes.any,
imageStyle: { type: Object as PropType<CSSProperties>, default: undefined as CSSProperties },
};
export default withInstall(Empty);