2021-06-26 01:35:40 +00:00
|
|
|
import type { App, ExtractPropTypes, ImgHTMLAttributes, Plugin } from 'vue';
|
2022-04-14 01:54:45 +00:00
|
|
|
import { defineComponent, computed } from 'vue';
|
2020-12-18 10:02:51 +00:00
|
|
|
import ImageInternal from '../vc-image';
|
2021-06-09 14:30:32 +00:00
|
|
|
import { imageProps } from '../vc-image/src/Image';
|
2022-04-14 01:54:45 +00:00
|
|
|
import defaultLocale from '../locale/en_US';
|
2021-06-19 14:13:13 +00:00
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2022-04-14 01:54:45 +00:00
|
|
|
import PreviewGroup, { icons } from './PreviewGroup';
|
|
|
|
import EyeOutlined from '@ant-design/icons-vue/EyeOutlined';
|
|
|
|
import { getTransitionName } from '../_util/transition';
|
2021-06-09 14:30:32 +00:00
|
|
|
|
|
|
|
export type ImageProps = Partial<
|
2022-03-26 14:52:54 +00:00
|
|
|
ExtractPropTypes<ReturnType<typeof imageProps>> &
|
|
|
|
Omit<ImgHTMLAttributes, 'placeholder' | 'onClick'>
|
2021-06-09 14:30:32 +00:00
|
|
|
>;
|
|
|
|
const Image = defineComponent<ImageProps>({
|
2020-12-18 10:02:51 +00:00
|
|
|
name: 'AImage',
|
|
|
|
inheritAttrs: false,
|
2022-03-26 14:52:54 +00:00
|
|
|
props: imageProps() as any,
|
2021-06-19 14:13:13 +00:00
|
|
|
setup(props, { slots, attrs }) {
|
2022-04-14 01:54:45 +00:00
|
|
|
const { prefixCls, rootPrefixCls, configProvider } = useConfigInject('image', props);
|
|
|
|
|
|
|
|
const mergedPreview = computed(() => {
|
|
|
|
const { preview } = props;
|
|
|
|
|
|
|
|
if (preview === false) {
|
|
|
|
return preview;
|
|
|
|
}
|
|
|
|
const _preview = typeof preview === 'object' ? preview : {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
icons,
|
|
|
|
..._preview,
|
|
|
|
transitionName: getTransitionName(rootPrefixCls.value, 'zoom', _preview.transitionName),
|
|
|
|
maskTransitionName: getTransitionName(
|
|
|
|
rootPrefixCls.value,
|
|
|
|
'fade',
|
|
|
|
_preview.maskTransitionName,
|
|
|
|
),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-12-18 10:02:51 +00:00
|
|
|
return () => {
|
2022-04-14 01:54:45 +00:00
|
|
|
const imageLocale = configProvider.locale?.Image || defaultLocale.Image;
|
2022-04-22 11:18:20 +00:00
|
|
|
const defaultPreviewMask = () => (
|
|
|
|
<div class={`${prefixCls.value}-mask-info`}>
|
|
|
|
<EyeOutlined />
|
|
|
|
{imageLocale?.preview}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
const { previewMask = slots.previewMask || defaultPreviewMask } = props;
|
2021-06-19 14:13:13 +00:00
|
|
|
return (
|
|
|
|
<ImageInternal
|
|
|
|
{...{ ...attrs, ...props, prefixCls: prefixCls.value }}
|
2022-04-14 01:54:45 +00:00
|
|
|
preview={mergedPreview.value}
|
|
|
|
v-slots={{
|
|
|
|
...slots,
|
2022-04-22 11:18:20 +00:00
|
|
|
previewMask: typeof previewMask === 'function' ? previewMask : null,
|
2022-04-14 01:54:45 +00:00
|
|
|
}}
|
2021-06-19 14:13:13 +00:00
|
|
|
></ImageInternal>
|
|
|
|
);
|
2020-12-18 10:02:51 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-09 14:30:32 +00:00
|
|
|
export { imageProps };
|
2020-12-18 10:02:51 +00:00
|
|
|
|
|
|
|
Image.PreviewGroup = PreviewGroup;
|
|
|
|
|
2021-06-23 15:08:16 +00:00
|
|
|
Image.install = function (app: App) {
|
2020-12-18 10:02:51 +00:00
|
|
|
app.component(Image.name, Image);
|
|
|
|
app.component(Image.PreviewGroup.name, Image.PreviewGroup);
|
|
|
|
return app;
|
|
|
|
};
|
|
|
|
|
2021-06-23 13:47:53 +00:00
|
|
|
export { PreviewGroup as ImagePreviewGroup };
|
|
|
|
|
2020-12-18 10:02:51 +00:00
|
|
|
export default Image as typeof Image &
|
|
|
|
Plugin & {
|
|
|
|
readonly PreviewGroup: typeof PreviewGroup;
|
|
|
|
};
|