mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-18 16:10:59 +08:00

* chore: looper * refactor: merge logic * chore: comment * chore: image semantic * test: fix test case * chore: fix lint * chore: fix lint * chore: show the strcture * chore: desc update
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
import classnames from 'classnames';
|
|
|
|
import type { PreviewConfig } from '..';
|
|
import { useZIndex } from '../../_util/hooks/useZIndex';
|
|
import { getTransitionName } from '../../_util/motion';
|
|
import type { GroupPreviewConfig } from '../PreviewGroup';
|
|
|
|
export default function useMergedPreviewConfig<T extends PreviewConfig | GroupPreviewConfig>(
|
|
previewConfig: T,
|
|
contextPreviewConfig: T,
|
|
prefixCls: string,
|
|
mergedRootClassName: string,
|
|
getContextPopupContainer: PreviewConfig['getContainer'],
|
|
icons: PreviewConfig['icons'],
|
|
defaultCover?: React.ReactNode,
|
|
): T {
|
|
const [zIndex] = useZIndex('ImagePreview', previewConfig?.zIndex);
|
|
|
|
return React.useMemo(() => {
|
|
if (!previewConfig) {
|
|
return previewConfig;
|
|
}
|
|
const {
|
|
cover,
|
|
getContainer,
|
|
closeIcon,
|
|
rootClassName: previewRootClassName,
|
|
} = previewConfig as PreviewConfig;
|
|
const { closeIcon: contextCloseIcon } = contextPreviewConfig ?? {};
|
|
return {
|
|
motionName: getTransitionName(`${prefixCls}-preview`, 'fade'),
|
|
...previewConfig,
|
|
...(defaultCover ? { cover: cover ?? defaultCover } : {}),
|
|
icons,
|
|
getContainer: getContainer ?? getContextPopupContainer,
|
|
zIndex,
|
|
closeIcon: closeIcon ?? contextCloseIcon,
|
|
rootClassName: classnames(mergedRootClassName, previewRootClassName),
|
|
};
|
|
}, [
|
|
previewConfig,
|
|
contextPreviewConfig,
|
|
prefixCls,
|
|
mergedRootClassName,
|
|
getContextPopupContainer,
|
|
defaultCover,
|
|
icons,
|
|
zIndex,
|
|
]);
|
|
}
|