UNPKG

1.95 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5var _excluded = ["visible", "mobile"];
6import * as React from 'react';
7import { useState, useEffect } from 'react';
8import isMobile from "rc-util/es/isMobile";
9import Mask from "./Mask";
10import PopupInner from "./PopupInner";
11import MobilePopupInner from "./MobilePopupInner";
12var Popup = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
13 var visible = _ref.visible,
14 mobile = _ref.mobile,
15 props = _objectWithoutProperties(_ref, _excluded);
16
17 var _useState = useState(visible),
18 _useState2 = _slicedToArray(_useState, 2),
19 innerVisible = _useState2[0],
20 serInnerVisible = _useState2[1];
21
22 var _useState3 = useState(false),
23 _useState4 = _slicedToArray(_useState3, 2),
24 inMobile = _useState4[0],
25 setInMobile = _useState4[1];
26
27 var cloneProps = _objectSpread(_objectSpread({}, props), {}, {
28 visible: innerVisible
29 }); // We check mobile in visible changed here.
30 // And this also delay set `innerVisible` to avoid popup component render flash
31
32
33 useEffect(function () {
34 serInnerVisible(visible);
35
36 if (visible && mobile) {
37 setInMobile(isMobile());
38 }
39 }, [visible, mobile]);
40 var popupNode = inMobile ? /*#__PURE__*/React.createElement(MobilePopupInner, _extends({}, cloneProps, {
41 mobile: mobile,
42 ref: ref
43 })) : /*#__PURE__*/React.createElement(PopupInner, _extends({}, cloneProps, {
44 ref: ref
45 })); // We can use fragment directly but this may failed some selector usage. Keep as origin logic
46
47 return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Mask, cloneProps), popupNode);
48});
49Popup.displayName = 'Popup';
50export default Popup;
\No newline at end of file