forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
78 lines (68 loc) · 2.26 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
import type { App, ExtractPropTypes, ImgHTMLAttributes, Plugin } from 'vue';
import { defineComponent, computed } from 'vue';
import ImageInternal from '../vc-image';
import { imageProps } from '../vc-image/src/Image';
import defaultLocale from '../locale/en_US';
import useConfigInject from '../_util/hooks/useConfigInject';
import PreviewGroup, { icons } from './PreviewGroup';
import EyeOutlined from '@ant-design/icons-vue/EyeOutlined';
import { getTransitionName } from '../_util/transition';
export type ImageProps = Partial<
ExtractPropTypes<ReturnType<typeof imageProps>> &
Omit<ImgHTMLAttributes, 'placeholder' | 'onClick'>
>;
const Image = defineComponent<ImageProps>({
name: 'AImage',
inheritAttrs: false,
props: imageProps() as any,
setup(props, { slots, attrs }) {
const { prefixCls, rootPrefixCls, configProvider } = useConfigInject('image', props);
const mergedPreview = computed(() => {
const { preview } = props;
const imageLocale = configProvider.locale?.Image || defaultLocale.Image;
if (preview === false) {
return preview;
}
const _preview = typeof preview === 'object' ? preview : {};
return {
mask: slots.previewMask ? (
slots.previewMask()
) : (
<div class={`${prefixCls.value}-mask-info`}>
<EyeOutlined />
{imageLocale?.preview}
</div>
),
icons,
..._preview,
transitionName: getTransitionName(rootPrefixCls.value, 'zoom', _preview.transitionName),
maskTransitionName: getTransitionName(
rootPrefixCls.value,
'fade',
_preview.maskTransitionName,
),
};
});
return () => {
return (
<ImageInternal
{...{ ...attrs, ...props, prefixCls: prefixCls.value }}
preview={mergedPreview.value}
v-slots={slots}
></ImageInternal>
);
};
},
});
export { imageProps };
Image.PreviewGroup = PreviewGroup;
Image.install = function (app: App) {
app.component(Image.name, Image);
app.component(Image.PreviewGroup.name, Image.PreviewGroup);
return app;
};
export { PreviewGroup as ImagePreviewGroup };
export default Image as typeof Image &
Plugin & {
readonly PreviewGroup: typeof PreviewGroup;
};