PreviewGroup.js 2.63 KB
"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.context = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var React = _interopRequireWildcard(require("react"));

var _Preview = _interopRequireDefault(require("./Preview"));

var context = /*#__PURE__*/React.createContext({
  previewUrls: [],
  setPreviewUrls: function setPreviewUrls() {
    return null;
  },
  setCurrent: function setCurrent() {
    return null;
  },
  setShowPreview: function setShowPreview() {
    return null;
  },
  setMousePosition: function setMousePosition() {
    return null;
  }
});
exports.context = context;
var Provider = context.Provider;

var Group = function Group(_ref) {
  var _ref$previewPrefixCls = _ref.previewPrefixCls,
      previewPrefixCls = _ref$previewPrefixCls === void 0 ? 'rc-image-preview' : _ref$previewPrefixCls,
      children = _ref.children;

  var _React$useState = React.useState([]),
      _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
      previewUrls = _React$useState2[0],
      setPreviewUrls = _React$useState2[1];

  var _React$useState3 = React.useState(),
      _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
      current = _React$useState4[0],
      setCurrent = _React$useState4[1];

  var _React$useState5 = React.useState(false),
      _React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
      isShowPreview = _React$useState6[0],
      setShowPreview = _React$useState6[1];

  var _React$useState7 = React.useState(null),
      _React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2),
      mousePosition = _React$useState8[0],
      setMousePosition = _React$useState8[1];

  var onPreviewClose = function onPreviewClose(e) {
    e.stopPropagation();
    setShowPreview(false);
    setMousePosition(null);
  };

  return /*#__PURE__*/React.createElement(Provider, {
    value: {
      isPreviewGroup: true,
      previewUrls: previewUrls,
      setPreviewUrls: setPreviewUrls,
      setCurrent: setCurrent,
      setShowPreview: setShowPreview,
      setMousePosition: setMousePosition
    }
  }, children, /*#__PURE__*/React.createElement(_Preview.default, {
    "ria-hidden": !isShowPreview,
    visible: isShowPreview,
    prefixCls: previewPrefixCls,
    onClose: onPreviewClose,
    mousePosition: mousePosition,
    src: current
  }));
};

var _default = Group;
exports.default = _default;