2023-11-25 05:25:29 +08:00
|
|
|
import * as React from 'react';
|
2022-06-22 14:57:09 +08:00
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
import LeftOutlined from '@ant-design/icons/LeftOutlined';
|
|
|
|
import RightOutlined from '@ant-design/icons/RightOutlined';
|
2021-01-06 22:23:49 +08:00
|
|
|
import RotateLeftOutlined from '@ant-design/icons/RotateLeftOutlined';
|
|
|
|
import RotateRightOutlined from '@ant-design/icons/RotateRightOutlined';
|
2023-02-10 00:12:18 +08:00
|
|
|
import SwapOutlined from '@ant-design/icons/SwapOutlined';
|
2021-01-06 22:23:49 +08:00
|
|
|
import ZoomInOutlined from '@ant-design/icons/ZoomInOutlined';
|
|
|
|
import ZoomOutOutlined from '@ant-design/icons/ZoomOutOutlined';
|
2023-11-25 05:25:29 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import RcImage from 'rc-image';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { GroupConsumerProps } from 'rc-image/lib/PreviewGroup';
|
2020-11-30 15:54:54 +08:00
|
|
|
|
2023-11-25 05:25:29 +08:00
|
|
|
import { useZIndex } from '../_util/hooks/useZIndex';
|
|
|
|
import { getTransitionName } from '../_util/motion';
|
|
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
2022-03-22 14:11:30 +08:00
|
|
|
import useStyle from './style';
|
|
|
|
|
2021-01-06 22:23:49 +08:00
|
|
|
export const icons = {
|
|
|
|
rotateLeft: <RotateLeftOutlined />,
|
|
|
|
rotateRight: <RotateRightOutlined />,
|
|
|
|
zoomIn: <ZoomInOutlined />,
|
|
|
|
zoomOut: <ZoomOutOutlined />,
|
|
|
|
close: <CloseOutlined />,
|
|
|
|
left: <LeftOutlined />,
|
|
|
|
right: <RightOutlined />,
|
2023-02-10 00:12:18 +08:00
|
|
|
flipX: <SwapOutlined />,
|
|
|
|
flipY: <SwapOutlined rotate={90} />,
|
2021-01-06 22:23:49 +08:00
|
|
|
};
|
|
|
|
|
2020-12-10 08:17:29 +08:00
|
|
|
const InternalPreviewGroup: React.FC<GroupConsumerProps> = ({
|
2020-11-30 15:54:54 +08:00
|
|
|
previewPrefixCls: customizePrefixCls,
|
2021-02-20 22:24:44 +08:00
|
|
|
preview,
|
2024-02-01 17:43:00 +08:00
|
|
|
...otherProps
|
2020-11-30 15:54:54 +08:00
|
|
|
}) => {
|
2022-04-08 18:05:50 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
2022-11-02 13:59:23 +08:00
|
|
|
const prefixCls = getPrefixCls('image', customizePrefixCls);
|
|
|
|
const previewPrefixCls = `${prefixCls}-preview`;
|
2021-02-20 22:24:44 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
|
2023-11-13 10:16:35 +08:00
|
|
|
const rootCls = useCSSVarCls(prefixCls);
|
2023-12-14 14:58:53 +08:00
|
|
|
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
|
2022-03-22 14:11:30 +08:00
|
|
|
|
2023-11-24 16:17:52 +08:00
|
|
|
const [zIndex] = useZIndex(
|
|
|
|
'ImagePreview',
|
|
|
|
typeof preview === 'object' ? preview.zIndex : undefined,
|
|
|
|
);
|
|
|
|
|
2023-11-25 05:25:29 +08:00
|
|
|
const mergedPreview = React.useMemo<GroupConsumerProps['preview']>(() => {
|
2021-02-20 22:24:44 +08:00
|
|
|
if (preview === false) {
|
|
|
|
return preview;
|
|
|
|
}
|
|
|
|
const _preview = typeof preview === 'object' ? preview : {};
|
2023-12-14 14:58:53 +08:00
|
|
|
const mergedRootClassName = classNames(
|
|
|
|
hashId,
|
|
|
|
cssVarCls,
|
|
|
|
rootCls,
|
|
|
|
_preview.rootClassName ?? '',
|
|
|
|
);
|
2021-02-20 22:24:44 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
..._preview,
|
|
|
|
transitionName: getTransitionName(rootPrefixCls, 'zoom', _preview.transitionName),
|
|
|
|
maskTransitionName: getTransitionName(rootPrefixCls, 'fade', _preview.maskTransitionName),
|
2023-03-16 09:53:57 +08:00
|
|
|
rootClassName: mergedRootClassName,
|
2023-11-24 16:17:52 +08:00
|
|
|
zIndex,
|
2021-02-20 22:24:44 +08:00
|
|
|
};
|
|
|
|
}, [preview]);
|
|
|
|
|
2023-11-13 10:16:35 +08:00
|
|
|
return wrapCSSVar(
|
2021-02-20 22:24:44 +08:00
|
|
|
<RcImage.PreviewGroup
|
|
|
|
preview={mergedPreview}
|
2022-11-02 13:59:23 +08:00
|
|
|
previewPrefixCls={previewPrefixCls}
|
2021-02-20 22:24:44 +08:00
|
|
|
icons={icons}
|
2024-02-01 17:43:00 +08:00
|
|
|
{...otherProps}
|
2022-03-22 14:11:30 +08:00
|
|
|
/>,
|
2021-02-20 22:24:44 +08:00
|
|
|
);
|
2020-11-30 15:54:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default InternalPreviewGroup;
|