2020-08-22 22:02:20 +08:00
|
|
|
import * as React from 'react';
|
2020-12-07 17:08:48 +08:00
|
|
|
import { useContext } from 'react';
|
|
|
|
import EyeOutlined from '@ant-design/icons/EyeOutlined';
|
2020-08-22 22:02:20 +08:00
|
|
|
import RcImage, { ImageProps } from 'rc-image';
|
2020-12-07 17:08:48 +08:00
|
|
|
import defaultLocale from '../locale/en_US';
|
2021-01-08 10:14:01 +08:00
|
|
|
import PreviewGroup, { icons } from './PreviewGroup';
|
2020-10-12 10:59:09 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2021-02-20 22:24:44 +08:00
|
|
|
import { getTransitionName } from '../_util/motion';
|
2020-08-22 22:02:20 +08:00
|
|
|
|
2020-11-30 15:54:54 +08:00
|
|
|
export interface CompositionImage<P> extends React.FC<P> {
|
|
|
|
PreviewGroup: typeof PreviewGroup;
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:08:48 +08:00
|
|
|
const Image: CompositionImage<ImageProps> = ({
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
preview,
|
|
|
|
...otherProps
|
|
|
|
}) => {
|
|
|
|
const { getPrefixCls } = useContext(ConfigContext);
|
2020-08-22 22:02:20 +08:00
|
|
|
const prefixCls = getPrefixCls('image', customizePrefixCls);
|
2021-02-20 22:24:44 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
2020-08-22 22:02:20 +08:00
|
|
|
|
2020-12-07 17:08:48 +08:00
|
|
|
const { locale: contextLocale = defaultLocale } = useContext(ConfigContext);
|
|
|
|
const imageLocale = contextLocale.Image || defaultLocale.Image;
|
|
|
|
|
|
|
|
const mergedPreview = React.useMemo(() => {
|
|
|
|
if (preview === false) {
|
|
|
|
return preview;
|
|
|
|
}
|
2021-02-20 22:24:44 +08:00
|
|
|
const _preview = typeof preview === 'object' ? preview : {};
|
2020-12-07 17:08:48 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
mask: (
|
|
|
|
<div className={`${prefixCls}-mask-info`}>
|
|
|
|
<EyeOutlined />
|
|
|
|
{imageLocale?.preview}
|
|
|
|
</div>
|
|
|
|
),
|
2021-01-08 10:14:01 +08:00
|
|
|
icons,
|
2021-02-20 22:24:44 +08:00
|
|
|
..._preview,
|
|
|
|
transitionName: getTransitionName(rootPrefixCls, 'zoom', _preview.transitionName),
|
|
|
|
maskTransitionName: getTransitionName(rootPrefixCls, 'fade', _preview.maskTransitionName),
|
2020-12-07 17:08:48 +08:00
|
|
|
};
|
|
|
|
}, [preview, imageLocale]);
|
|
|
|
|
|
|
|
return <RcImage prefixCls={prefixCls} preview={mergedPreview} {...otherProps} />;
|
2020-08-22 22:02:20 +08:00
|
|
|
};
|
|
|
|
|
2020-11-18 13:48:30 +08:00
|
|
|
export { ImageProps };
|
|
|
|
|
2020-11-30 15:54:54 +08:00
|
|
|
Image.PreviewGroup = PreviewGroup;
|
|
|
|
|
2020-08-22 22:02:20 +08:00
|
|
|
export default Image;
|