index.js 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use client";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import * as React from 'react';
  11. import EyeOutlined from "@ant-design/icons/es/icons/EyeOutlined";
  12. import classNames from 'classnames';
  13. import RcImage from 'rc-image';
  14. import { useZIndex } from '../_util/hooks/useZIndex';
  15. import { getTransitionName } from '../_util/motion';
  16. import { devUseWarning } from '../_util/warning';
  17. import { useComponentConfig } from '../config-provider/context';
  18. import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
  19. import { useLocale } from '../locale';
  20. import PreviewGroup, { icons } from './PreviewGroup';
  21. import useStyle from './style';
  22. const Image = props => {
  23. const {
  24. prefixCls: customizePrefixCls,
  25. preview,
  26. className,
  27. rootClassName,
  28. style
  29. } = props,
  30. otherProps = __rest(props, ["prefixCls", "preview", "className", "rootClassName", "style"]);
  31. if (process.env.NODE_ENV !== 'production') {
  32. const warning = devUseWarning('Image');
  33. warning.deprecated(!(preview && typeof preview === 'object' && 'destroyOnClose' in preview), 'destroyOnClose', 'destroyOnHidden');
  34. }
  35. const {
  36. getPrefixCls,
  37. getPopupContainer: getContextPopupContainer,
  38. className: contextClassName,
  39. style: contextStyle,
  40. preview: contextPreview
  41. } = useComponentConfig('image');
  42. const [imageLocale] = useLocale('Image');
  43. const prefixCls = getPrefixCls('image', customizePrefixCls);
  44. const rootPrefixCls = getPrefixCls();
  45. // Style
  46. const rootCls = useCSSVarCls(prefixCls);
  47. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
  48. const mergedRootClassName = classNames(rootClassName, hashId, cssVarCls, rootCls);
  49. const mergedClassName = classNames(className, hashId, contextClassName);
  50. const [zIndex] = useZIndex('ImagePreview', typeof preview === 'object' ? preview.zIndex : undefined);
  51. const mergedPreview = React.useMemo(() => {
  52. if (preview === false) {
  53. return preview;
  54. }
  55. const _preview = typeof preview === 'object' ? preview : {};
  56. const {
  57. getContainer,
  58. closeIcon,
  59. rootClassName,
  60. destroyOnClose,
  61. destroyOnHidden
  62. } = _preview,
  63. restPreviewProps = __rest(_preview, ["getContainer", "closeIcon", "rootClassName", "destroyOnClose", "destroyOnHidden"]);
  64. return Object.assign(Object.assign({
  65. mask: (/*#__PURE__*/React.createElement("div", {
  66. className: `${prefixCls}-mask-info`
  67. }, /*#__PURE__*/React.createElement(EyeOutlined, null), imageLocale === null || imageLocale === void 0 ? void 0 : imageLocale.preview)),
  68. icons
  69. }, restPreviewProps), {
  70. // TODO: In the future, destroyOnClose in rc-image needs to be upgrade to destroyOnHidden
  71. destroyOnClose: destroyOnHidden !== null && destroyOnHidden !== void 0 ? destroyOnHidden : destroyOnClose,
  72. rootClassName: classNames(mergedRootClassName, rootClassName),
  73. getContainer: getContainer !== null && getContainer !== void 0 ? getContainer : getContextPopupContainer,
  74. transitionName: getTransitionName(rootPrefixCls, 'zoom', _preview.transitionName),
  75. maskTransitionName: getTransitionName(rootPrefixCls, 'fade', _preview.maskTransitionName),
  76. zIndex,
  77. closeIcon: closeIcon !== null && closeIcon !== void 0 ? closeIcon : contextPreview === null || contextPreview === void 0 ? void 0 : contextPreview.closeIcon
  78. });
  79. }, [preview, imageLocale, contextPreview === null || contextPreview === void 0 ? void 0 : contextPreview.closeIcon]);
  80. const mergedStyle = Object.assign(Object.assign({}, contextStyle), style);
  81. return wrapCSSVar(/*#__PURE__*/React.createElement(RcImage, Object.assign({
  82. prefixCls: prefixCls,
  83. preview: mergedPreview,
  84. rootClassName: mergedRootClassName,
  85. className: mergedClassName,
  86. style: mergedStyle
  87. }, otherProps)));
  88. };
  89. Image.PreviewGroup = PreviewGroup;
  90. if (process.env.NODE_ENV !== 'production') {
  91. Image.displayName = 'Image';
  92. }
  93. export default Image;