mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 11:18:14 +08:00
20d12f8ef2
* chore(deps-dev): bump typescript from 5.1.6 to 5.2.2 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 5.1.6 to 5.2.2. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * bump typedoc * type: fix type * fix: fix * type: fix type --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 栗嘉男 <574980606@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
91 lines
2.4 KiB
TypeScript
91 lines
2.4 KiB
TypeScript
'use client';
|
|
|
|
import * as React from 'react';
|
|
import EyeOutlined from '@ant-design/icons/EyeOutlined';
|
|
import classNames from 'classnames';
|
|
import RcImage from 'rc-image';
|
|
import type { ImageProps } from 'rc-image';
|
|
|
|
import { getTransitionName } from '../_util/motion';
|
|
import { ConfigContext } from '../config-provider';
|
|
import defaultLocale from '../locale/en_US';
|
|
// CSSINJS
|
|
import PreviewGroup, { icons } from './PreviewGroup';
|
|
import useStyle from './style';
|
|
|
|
export interface CompositionImage<P> extends React.FC<P> {
|
|
PreviewGroup: typeof PreviewGroup;
|
|
}
|
|
|
|
const Image: CompositionImage<ImageProps> = (props) => {
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
preview,
|
|
className,
|
|
rootClassName,
|
|
style,
|
|
...otherProps
|
|
} = props;
|
|
const {
|
|
getPrefixCls,
|
|
locale: contextLocale = defaultLocale,
|
|
getPopupContainer: getContextPopupContainer,
|
|
image,
|
|
} = React.useContext(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('image', customizePrefixCls);
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
const imageLocale = contextLocale.Image || defaultLocale.Image;
|
|
// Style
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
const mergedRootClassName = classNames(rootClassName, hashId);
|
|
|
|
const mergedClassName = classNames(className, hashId, image?.className);
|
|
|
|
const mergedPreview = React.useMemo(() => {
|
|
if (preview === false) {
|
|
return preview;
|
|
}
|
|
const _preview = typeof preview === 'object' ? preview : {};
|
|
const { getContainer, ...restPreviewProps } = _preview;
|
|
return {
|
|
mask: (
|
|
<div className={`${prefixCls}-mask-info`}>
|
|
<EyeOutlined />
|
|
{imageLocale?.preview}
|
|
</div>
|
|
),
|
|
icons,
|
|
...restPreviewProps,
|
|
getContainer: getContainer || getContextPopupContainer,
|
|
transitionName: getTransitionName(rootPrefixCls, 'zoom', _preview.transitionName),
|
|
maskTransitionName: getTransitionName(rootPrefixCls, 'fade', _preview.maskTransitionName),
|
|
};
|
|
}, [preview, imageLocale]);
|
|
|
|
const mergedStyle: React.CSSProperties = { ...image?.style, ...style };
|
|
|
|
return wrapSSR(
|
|
<RcImage
|
|
prefixCls={prefixCls}
|
|
preview={mergedPreview}
|
|
rootClassName={mergedRootClassName}
|
|
className={mergedClassName}
|
|
style={mergedStyle}
|
|
{...otherProps}
|
|
/>,
|
|
);
|
|
};
|
|
|
|
export type { ImageProps };
|
|
|
|
Image.PreviewGroup = PreviewGroup;
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
Image.displayName = 'Image';
|
|
}
|
|
|
|
export default Image;
|