UNPKG

2.64 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
16var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
18var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
19
20var React = _interopRequireWildcard(require("react"));
21
22var _isMobile = _interopRequireDefault(require("rc-util/lib/isMobile"));
23
24var _Mask = _interopRequireDefault(require("./Mask"));
25
26var _PopupInner = _interopRequireDefault(require("./PopupInner"));
27
28var _MobilePopupInner = _interopRequireDefault(require("./MobilePopupInner"));
29
30var _excluded = ["visible", "mobile"];
31var Popup = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
32 var visible = _ref.visible,
33 mobile = _ref.mobile,
34 props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
35
36 var _useState = (0, React.useState)(visible),
37 _useState2 = (0, _slicedToArray2.default)(_useState, 2),
38 innerVisible = _useState2[0],
39 serInnerVisible = _useState2[1];
40
41 var _useState3 = (0, React.useState)(false),
42 _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
43 inMobile = _useState4[0],
44 setInMobile = _useState4[1];
45
46 var cloneProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
47 visible: innerVisible
48 }); // We check mobile in visible changed here.
49 // And this also delay set `innerVisible` to avoid popup component render flash
50
51 (0, React.useEffect)(function () {
52 serInnerVisible(visible);
53
54 if (visible && mobile) {
55 setInMobile((0, _isMobile.default)());
56 }
57 }, [visible, mobile]);
58 var popupNode = inMobile ? /*#__PURE__*/React.createElement(_MobilePopupInner.default, (0, _extends2.default)({}, cloneProps, {
59 mobile: mobile,
60 ref: ref
61 })) : /*#__PURE__*/React.createElement(_PopupInner.default, (0, _extends2.default)({}, cloneProps, {
62 ref: ref
63 })); // We can use fragment directly but this may failed some selector usage. Keep as origin logic
64
65 return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Mask.default, cloneProps), popupNode);
66});
67Popup.displayName = 'Popup';
68var _default = Popup;
69exports.default = _default;
\No newline at end of file