@salutejs/plasma-new-hope 0.159.0-dev.0 → 0.159.1-canary.1412.11144674561.0
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/components/Drawer/Drawer.css +4 -3
- package/cjs/components/Drawer/Drawer.styles.js +3 -0
- package/cjs/components/Drawer/Drawer.styles.js.map +1 -1
- package/cjs/components/Modal/Modal.css +4 -3
- package/cjs/components/Notification/NotificationsProvider.css +4 -3
- package/cjs/components/Popup/Popup.js +30 -41
- package/cjs/components/Popup/Popup.js.map +1 -1
- package/cjs/components/Popup/Popup.styles.js +55 -27
- package/cjs/components/Popup/Popup.styles.js.map +1 -1
- package/cjs/components/Popup/Popup.styles_1uw5px0.css +4 -0
- package/cjs/components/Popup/PopupContext.css +4 -0
- package/cjs/components/Popup/PopupContext.js +32 -10
- package/cjs/components/Popup/PopupContext.js.map +1 -1
- package/cjs/components/Popup/PopupRoot.js +1 -1
- package/cjs/components/Popup/PopupRoot.js.map +1 -1
- package/cjs/components/Popup/hooks/usePopup.js +6 -3
- package/cjs/components/Popup/hooks/usePopup.js.map +1 -1
- package/cjs/index.css +4 -3
- package/emotion/cjs/components/Popup/Popup.js +29 -41
- package/emotion/cjs/components/Popup/Popup.styles.js +35 -17
- package/emotion/cjs/components/Popup/PopupContext.js +31 -10
- package/emotion/cjs/components/Popup/PopupRoot.js +1 -3
- package/emotion/cjs/components/Popup/hooks/usePopup.js +6 -3
- package/emotion/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +3 -0
- package/emotion/cjs/examples/plasma_b2c/components/Popup/Popup.stories.tsx +3 -0
- package/emotion/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +3 -0
- package/emotion/cjs/examples/plasma_web/components/Popup/Popup.stories.tsx +3 -0
- package/emotion/es/components/Popup/Popup.js +31 -43
- package/emotion/es/components/Popup/Popup.styles.js +34 -16
- package/emotion/es/components/Popup/PopupContext.js +32 -11
- package/emotion/es/components/Popup/PopupRoot.js +1 -3
- package/emotion/es/components/Popup/hooks/usePopup.js +6 -3
- package/emotion/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +3 -0
- package/emotion/es/examples/plasma_b2c/components/Popup/Popup.stories.tsx +3 -0
- package/emotion/es/examples/plasma_web/components/Modal/Modal.stories.tsx +3 -0
- package/emotion/es/examples/plasma_web/components/Popup/Popup.stories.tsx +3 -0
- package/es/components/Drawer/Drawer.css +4 -3
- package/es/components/Drawer/Drawer.styles.js +3 -0
- package/es/components/Drawer/Drawer.styles.js.map +1 -1
- package/es/components/Modal/Modal.css +4 -3
- package/es/components/Notification/NotificationsProvider.css +4 -3
- package/es/components/Popup/Popup.js +32 -43
- package/es/components/Popup/Popup.js.map +1 -1
- package/es/components/Popup/Popup.styles.js +54 -28
- package/es/components/Popup/Popup.styles.js.map +1 -1
- package/es/components/Popup/Popup.styles_1uw5px0.css +4 -0
- package/es/components/Popup/PopupContext.css +4 -0
- package/es/components/Popup/PopupContext.js +33 -11
- package/es/components/Popup/PopupContext.js.map +1 -1
- package/es/components/Popup/PopupRoot.js +1 -1
- package/es/components/Popup/PopupRoot.js.map +1 -1
- package/es/components/Popup/hooks/usePopup.js +6 -3
- package/es/components/Popup/hooks/usePopup.js.map +1 -1
- package/es/index.css +4 -3
- package/package.json +2 -2
- package/styled-components/cjs/components/Popup/Popup.js +29 -41
- package/styled-components/cjs/components/Popup/Popup.styles.js +23 -14
- package/styled-components/cjs/components/Popup/PopupContext.js +31 -10
- package/styled-components/cjs/components/Popup/PopupRoot.js +1 -3
- package/styled-components/cjs/components/Popup/hooks/usePopup.js +6 -3
- package/styled-components/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +3 -0
- package/styled-components/cjs/examples/plasma_b2c/components/Popup/Popup.stories.tsx +3 -0
- package/styled-components/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +3 -0
- package/styled-components/cjs/examples/plasma_web/components/Popup/Popup.stories.tsx +3 -0
- package/styled-components/es/components/Popup/Popup.js +31 -43
- package/styled-components/es/components/Popup/Popup.styles.js +22 -13
- package/styled-components/es/components/Popup/PopupContext.js +32 -11
- package/styled-components/es/components/Popup/PopupRoot.js +1 -3
- package/styled-components/es/components/Popup/hooks/usePopup.js +6 -3
- package/styled-components/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +3 -0
- package/styled-components/es/examples/plasma_b2c/components/Popup/Popup.stories.tsx +3 -0
- package/styled-components/es/examples/plasma_web/components/Modal/Modal.stories.tsx +3 -0
- package/styled-components/es/examples/plasma_web/components/Popup/Popup.stories.tsx +3 -0
- package/types/components/Popup/Popup.d.ts +1 -1
- package/types/components/Popup/Popup.d.ts.map +1 -1
- package/types/components/Popup/Popup.styles.d.ts +4 -1
- package/types/components/Popup/Popup.styles.d.ts.map +1 -1
- package/types/components/Popup/Popup.types.d.ts +3 -0
- package/types/components/Popup/Popup.types.d.ts.map +1 -1
- package/types/components/Popup/PopupContext.d.ts.map +1 -1
- package/types/components/Popup/hooks/usePopup.d.ts +2 -1
- package/types/components/Popup/hooks/usePopup.d.ts.map +1 -1
- package/cjs/components/Popup/Popup.css +0 -3
- package/cjs/components/Popup/Popup.styles_141jyqa.css +0 -3
- package/es/components/Popup/Popup.css +0 -3
- package/es/components/Popup/Popup.styles_141jyqa.css +0 -3
@@ -7,6 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
exports.usePopupContext = exports.PopupProvider = exports.POPUP_PORTAL_ID = void 0;
|
8
8
|
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
9
9
|
var _ModalContext = /*#__PURE__*/require("../Modal/ModalContext");
|
10
|
+
var _utils = /*#__PURE__*/require("../../utils");
|
11
|
+
var _Portal = /*#__PURE__*/require("../Portal");
|
12
|
+
var _Popup = /*#__PURE__*/require("./Popup.styles");
|
10
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
11
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
12
15
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
@@ -23,9 +26,12 @@ var POPUP_PORTAL_ID = exports.POPUP_PORTAL_ID = 'plasma-popup-root';
|
|
23
26
|
var items = [];
|
24
27
|
var PopupContext = /*#__PURE__*/(0, _react.createContext)({
|
25
28
|
items: items,
|
29
|
+
rootId: POPUP_PORTAL_ID,
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
26
31
|
register: function register(_info) {
|
27
32
|
throw new Error('Function not implemented. Add PopupProvider');
|
28
33
|
},
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
29
35
|
unregister: function unregister(_id) {
|
30
36
|
throw new Error('Function not implemented. Add PopupProvider');
|
31
37
|
}
|
@@ -35,29 +41,46 @@ var usePopupContext = exports.usePopupContext = function usePopupContext() {
|
|
35
41
|
};
|
36
42
|
var PopupProvider = exports.PopupProvider = function PopupProvider(_ref) {
|
37
43
|
var children = _ref.children;
|
38
|
-
var
|
44
|
+
var globalItemsCount = (0, _react.useRef)(0);
|
45
|
+
var prevBodyOverflowY = (0, _react.useRef)(_utils.canUseDOM ? document.body.style.overflowY : '');
|
46
|
+
// eslint-disable-next-line no-shadow
|
39
47
|
var _useState = (0, _react.useState)([]),
|
40
48
|
_useState2 = _slicedToArray(_useState, 2),
|
41
49
|
items = _useState2[0],
|
42
50
|
setItems = _useState2[1];
|
51
|
+
var uuid = (0, _utils.safeUseId)();
|
52
|
+
var rootId = "".concat(POPUP_PORTAL_ID, "-").concat(uuid);
|
43
53
|
var register = function register(info) {
|
54
|
+
if (!_utils.canUseDOM) {
|
55
|
+
return;
|
56
|
+
}
|
44
57
|
setItems(function (prevItems) {
|
45
58
|
var _info$info;
|
46
59
|
if ((_info$info = info.info) !== null && _info$info !== void 0 && _info$info.isModal && !(0, _ModalContext.hasModals)(prevItems)) {
|
47
60
|
prevBodyOverflowY.current = document.body.style.overflowY;
|
48
61
|
document.body.style.overflowY = 'hidden';
|
49
62
|
}
|
63
|
+
if (info.isGlobalPopup) {
|
64
|
+
globalItemsCount.current += 1;
|
65
|
+
}
|
50
66
|
return [].concat(_toConsumableArray(prevItems), [info]);
|
51
67
|
});
|
52
68
|
};
|
53
69
|
var unregister = function unregister(id) {
|
70
|
+
if (!_utils.canUseDOM) {
|
71
|
+
return;
|
72
|
+
}
|
54
73
|
setItems(function (prevItems) {
|
74
|
+
var _prevItems$index;
|
55
75
|
var index = prevItems.findIndex(function (item) {
|
56
76
|
return id === item.id;
|
57
77
|
});
|
58
78
|
if (index === -1) {
|
59
79
|
return prevItems;
|
60
80
|
}
|
81
|
+
if (prevItems !== null && prevItems !== void 0 && (_prevItems$index = prevItems[index]) !== null && _prevItems$index !== void 0 && _prevItems$index.isGlobalPopup) {
|
82
|
+
globalItemsCount.current -= 1;
|
83
|
+
}
|
61
84
|
var prevHasModals = (0, _ModalContext.hasModals)(prevItems);
|
62
85
|
prevItems.splice(index, 1);
|
63
86
|
if (prevHasModals && !(0, _ModalContext.hasModals)(prevItems)) {
|
@@ -70,18 +93,16 @@ var PopupProvider = exports.PopupProvider = function PopupProvider(_ref) {
|
|
70
93
|
};
|
71
94
|
var context = {
|
72
95
|
items: items,
|
96
|
+
rootId: rootId,
|
73
97
|
register: register,
|
74
98
|
unregister: unregister
|
75
99
|
};
|
76
|
-
(0, _react.useEffect)(function () {
|
77
|
-
return function () {
|
78
|
-
var portal = document.createElement('div');
|
79
|
-
if (portal && document.body.contains(portal)) {
|
80
|
-
document.body.removeChild(portal);
|
81
|
-
}
|
82
|
-
};
|
83
|
-
}, []);
|
84
100
|
return /*#__PURE__*/_react["default"].createElement(PopupContext.Provider, {
|
85
101
|
value: context
|
86
|
-
}, children
|
102
|
+
}, children, /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
103
|
+
container: document.body
|
104
|
+
}, /*#__PURE__*/_react["default"].createElement(_Popup.StyledPortal, {
|
105
|
+
id: rootId,
|
106
|
+
hasContent: globalItemsCount.current > 0
|
107
|
+
})));
|
87
108
|
};
|
@@ -10,7 +10,7 @@ var _plasmaCore = /*#__PURE__*/require("@salutejs/plasma-core");
|
|
10
10
|
var _PopupContext = /*#__PURE__*/require("./PopupContext");
|
11
11
|
var _Popup = /*#__PURE__*/require("./Popup.styles");
|
12
12
|
var _Popup2 = /*#__PURE__*/require("./Popup.tokens");
|
13
|
-
var _excluded = ["id", "placement", "offset", "
|
13
|
+
var _excluded = ["id", "placement", "offset", "setVisible", "children", "role", "zIndex", "animationInfo"];
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
15
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
16
16
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
@@ -24,13 +24,11 @@ var PopupRoot = exports.PopupRoot = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
24
24
|
var id = _ref.id,
|
25
25
|
placement = _ref.placement,
|
26
26
|
offset = _ref.offset,
|
27
|
-
frame = _ref.frame,
|
28
27
|
setVisible = _ref.setVisible,
|
29
28
|
children = _ref.children,
|
30
29
|
role = _ref.role,
|
31
30
|
zIndex = _ref.zIndex,
|
32
31
|
animationInfo = _ref.animationInfo,
|
33
|
-
className = _ref.className,
|
34
32
|
rest = _objectWithoutProperties(_ref, _excluded);
|
35
33
|
var contentRef = (0, _react.useRef)(null);
|
36
34
|
var innerRef = (0, _plasmaCore.useForkRef)(contentRef, ref);
|
@@ -18,7 +18,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
18
18
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
19
19
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
20
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
21
|
-
// Хук для
|
21
|
+
// Хук для подключения анимации
|
22
22
|
var usePopupAnimation = function usePopupAnimation() {
|
23
23
|
var _useState = (0, _react.useState)(false),
|
24
24
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -40,6 +40,7 @@ var usePopupAnimation = function usePopupAnimation() {
|
|
40
40
|
var usePopup = exports.usePopup = function usePopup(_ref) {
|
41
41
|
var isOpen = _ref.isOpen,
|
42
42
|
id = _ref.id,
|
43
|
+
isGlobalPopup = _ref.isGlobalPopup,
|
43
44
|
popupInfo = _ref.popupInfo,
|
44
45
|
withAnimation = _ref.withAnimation;
|
45
46
|
var _useState5 = (0, _react.useState)(false),
|
@@ -61,7 +62,8 @@ var usePopup = exports.usePopup = function usePopup(_ref) {
|
|
61
62
|
// при первом открытии
|
62
63
|
if (isOpen && !isVisible) {
|
63
64
|
popupController.register(_objectSpread({
|
64
|
-
id: id
|
65
|
+
id: id,
|
66
|
+
isGlobalPopup: isGlobalPopup
|
65
67
|
}, popupInfo));
|
66
68
|
setVisible(true);
|
67
69
|
animationInfo.setEndAnimation(false);
|
@@ -90,6 +92,7 @@ var usePopup = exports.usePopup = function usePopup(_ref) {
|
|
90
92
|
isVisible: isVisible,
|
91
93
|
setVisible: setVisible,
|
92
94
|
animationInfo: animationInfo,
|
93
|
-
withAnimation: withAnimation
|
95
|
+
withAnimation: withAnimation,
|
96
|
+
rootId: popupController.rootId
|
94
97
|
};
|
95
98
|
};
|
@@ -12,6 +12,9 @@ import { Popup, popupClasses, PopupProvider } from './Popup';
|
|
12
12
|
const meta: Meta<typeof Popup> = {
|
13
13
|
title: 'plasma_b2c/Popup',
|
14
14
|
decorators: [WithTheme],
|
15
|
+
parameters: {
|
16
|
+
docs: { story: { inline: false, iframeHeight: '30rem' } },
|
17
|
+
},
|
15
18
|
argTypes: {
|
16
19
|
placement: {
|
17
20
|
options: [
|
@@ -12,6 +12,9 @@ import { Popup, popupClasses, PopupProvider } from './Popup';
|
|
12
12
|
const meta: Meta<typeof Popup> = {
|
13
13
|
title: 'plasma_web/Popup',
|
14
14
|
decorators: [WithTheme],
|
15
|
+
parameters: {
|
16
|
+
docs: { story: { inline: false, iframeHeight: '30rem' } },
|
17
|
+
},
|
15
18
|
argTypes: {
|
16
19
|
placement: {
|
17
20
|
options: [
|
@@ -8,14 +8,14 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
8
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
9
9
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
|
-
import React, { forwardRef,
|
11
|
+
import React, { forwardRef, useRef } from 'react';
|
12
12
|
import { useForkRef, safeUseId } from '@salutejs/plasma-core';
|
13
|
-
import { cx } from '../../utils';
|
13
|
+
import { canUseDOM, cx } from '../../utils';
|
14
14
|
import { Portal } from '../Portal';
|
15
|
-
import { POPUP_PORTAL_ID } from './PopupContext';
|
16
15
|
import { PopupRoot } from './PopupRoot';
|
17
16
|
import { usePopup } from './hooks';
|
18
17
|
import { classes } from './Popup.tokens';
|
18
|
+
import { StyledPortalContainer } from './Popup.styles';
|
19
19
|
export var handlePosition = function handlePosition(placement, offset) {
|
20
20
|
var x = '0rem';
|
21
21
|
var y = '0rem';
|
@@ -39,8 +39,8 @@ export var handlePosition = function handlePosition(placement, offset) {
|
|
39
39
|
var bottom;
|
40
40
|
var transform;
|
41
41
|
var placements = placement.split('-');
|
42
|
-
placements.forEach(function (
|
43
|
-
switch (
|
42
|
+
placements.forEach(function (placementValue) {
|
43
|
+
switch (placementValue) {
|
44
44
|
case 'left':
|
45
45
|
left = x;
|
46
46
|
break;
|
@@ -75,7 +75,7 @@ export var handlePosition = function handlePosition(placement, offset) {
|
|
75
75
|
};
|
76
76
|
|
77
77
|
/**
|
78
|
-
* Базовый
|
78
|
+
* Базовый компонент Popup.
|
79
79
|
*/
|
80
80
|
export var popupRoot = function popupRoot(Root) {
|
81
81
|
return /*#__PURE__*/forwardRef(function (_ref, outerRootRef) {
|
@@ -105,63 +105,51 @@ export var popupRoot = function popupRoot(Root) {
|
|
105
105
|
var _usePopup = usePopup({
|
106
106
|
isOpen: innerIsOpen,
|
107
107
|
id: innerId,
|
108
|
+
isGlobalPopup: !frame || frame === 'document',
|
108
109
|
popupInfo: popupInfo,
|
109
110
|
withAnimation: withAnimation
|
110
111
|
}),
|
111
112
|
isVisible = _usePopup.isVisible,
|
112
113
|
animationInfo = _usePopup.animationInfo,
|
113
|
-
setVisible = _usePopup.setVisible
|
114
|
+
setVisible = _usePopup.setVisible,
|
115
|
+
rootId = _usePopup.rootId;
|
114
116
|
var portalRef = useRef(null);
|
115
117
|
var contentRef = useRef(null);
|
116
118
|
var innerRef = useForkRef(contentRef, outerRootRef);
|
117
|
-
var _useState = useState(false),
|
118
|
-
_useState2 = _slicedToArray(_useState, 2),
|
119
|
-
forceRender = _useState2[1];
|
120
|
-
useEffect(function () {
|
121
|
-
var portal = document.getElementById(POPUP_PORTAL_ID);
|
122
|
-
if (typeof frame !== 'string' && frame && frame.current) {
|
123
|
-
portal = frame.current;
|
124
|
-
}
|
125
|
-
if (!portal) {
|
126
|
-
portal = document.createElement('div');
|
127
|
-
portal.setAttribute('id', POPUP_PORTAL_ID);
|
128
|
-
/**
|
129
|
-
* Нужно для того, чтобы во фрейме не происходило скачков контента
|
130
|
-
* при анимации через transform, если есть элемент с шириной/высотой в 100% (Overlay)
|
131
|
-
*/
|
132
|
-
portal.style.width = '0';
|
133
|
-
if (typeof frame === 'string' && frame !== 'document') {
|
134
|
-
var _document$getElementB;
|
135
|
-
(_document$getElementB = document.getElementById(frame)) === null || _document$getElementB === void 0 || _document$getElementB.appendChild(portal);
|
136
|
-
} else {
|
137
|
-
document.body.appendChild(portal);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
portalRef.current = portal;
|
141
|
-
|
142
|
-
/**
|
143
|
-
* Изменение стейта нужно для того, чтобы Popup
|
144
|
-
* отобразился после записи DOM элемента в portalRef.current
|
145
|
-
*/
|
146
|
-
forceRender(true);
|
147
|
-
}, []);
|
148
119
|
if (!isVisible && !innerIsOpen) {
|
149
120
|
return null;
|
150
121
|
}
|
151
122
|
var cls = cx(className, animationInfo !== null && animationInfo !== void 0 && animationInfo.endAnimation ? classes.endAnimation : '', animationInfo !== null && animationInfo !== void 0 && animationInfo.endTransition ? classes.endTransition : '');
|
152
|
-
|
153
|
-
container: portalRef.current
|
154
|
-
}, /*#__PURE__*/React.createElement(Root, _extends({
|
123
|
+
var rootNode = /*#__PURE__*/React.createElement(Root, _extends({
|
155
124
|
className: cls
|
156
125
|
}, rest), overlay, /*#__PURE__*/React.createElement(PopupRoot, {
|
157
126
|
id: innerId,
|
158
127
|
ref: innerRef,
|
159
128
|
position: handlePosition(placement, offset),
|
160
|
-
frame: frame,
|
161
129
|
zIndex: zIndex,
|
162
130
|
animationInfo: animationInfo,
|
163
131
|
setVisible: setVisible
|
164
|
-
}, children))
|
132
|
+
}, children));
|
133
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
134
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
135
|
+
container: frame.current
|
136
|
+
}, rootNode);
|
137
|
+
}
|
138
|
+
var withFrameId = typeof frame === 'string' && frame !== 'document';
|
139
|
+
var containerElement = withFrameId && document.getElementById(frame);
|
140
|
+
if (containerElement) {
|
141
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
142
|
+
container: containerElement
|
143
|
+
}, /*#__PURE__*/React.createElement(StyledPortalContainer, {
|
144
|
+
ref: portalRef
|
145
|
+
}, portalRef.current && /*#__PURE__*/React.createElement(Portal, {
|
146
|
+
container: portalRef.current
|
147
|
+
}, rootNode)), ' ');
|
148
|
+
}
|
149
|
+
var globalPortal = canUseDOM && document.getElementById(rootId);
|
150
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, globalPortal && /*#__PURE__*/React.createElement(Portal, {
|
151
|
+
container: globalPortal
|
152
|
+
}, rootNode));
|
165
153
|
});
|
166
154
|
};
|
167
155
|
export var popupConfig = {
|
@@ -2,28 +2,37 @@ import styled from 'styled-components';
|
|
2
2
|
import { DEFAULT_Z_INDEX } from './utils';
|
3
3
|
export var StyledPortal = /*#__PURE__*/styled.div.withConfig({
|
4
4
|
componentId: "plasma-new-hope__sc-rkhnjn-0"
|
5
|
-
})([""])
|
6
|
-
|
5
|
+
})(["position:fixed;top:0;left:0;right:0;bottom:0;z-index:", ";width:", ";pointer-events:", ";"], DEFAULT_Z_INDEX, function (_ref) {
|
6
|
+
var hasContent = _ref.hasContent;
|
7
|
+
return hasContent ? 'auto' : '0';
|
8
|
+
}, function (_ref2) {
|
9
|
+
var hasContent = _ref2.hasContent;
|
10
|
+
return hasContent ? 'auto' : 'none';
|
11
|
+
});
|
12
|
+
export var StyledPortalContainer = /*#__PURE__*/styled.div.withConfig({
|
7
13
|
componentId: "plasma-new-hope__sc-rkhnjn-1"
|
14
|
+
})(["width:0;"]);
|
15
|
+
export var PopupView = /*#__PURE__*/styled.div.withConfig({
|
16
|
+
componentId: "plasma-new-hope__sc-rkhnjn-2"
|
8
17
|
})(["position:relative;max-width:100%;pointer-events:all;"]);
|
9
18
|
export var PopupRootContainer = /*#__PURE__*/styled.div.withConfig({
|
10
|
-
componentId: "plasma-new-hope__sc-rkhnjn-
|
11
|
-
})(["position:absolute;z-index:", ";left:", ";right:", ";top:", ";bottom:", ";transform:", ";"], function (
|
12
|
-
var zIndex =
|
19
|
+
componentId: "plasma-new-hope__sc-rkhnjn-3"
|
20
|
+
})(["position:absolute;z-index:", ";left:", ";right:", ";top:", ";bottom:", ";transform:", ";"], function (_ref3) {
|
21
|
+
var zIndex = _ref3.zIndex;
|
13
22
|
return zIndex || DEFAULT_Z_INDEX;
|
14
|
-
}, function (_ref2) {
|
15
|
-
var position = _ref2.position;
|
16
|
-
return position.left || '';
|
17
|
-
}, function (_ref3) {
|
18
|
-
var position = _ref3.position;
|
19
|
-
return position.right || '';
|
20
23
|
}, function (_ref4) {
|
21
24
|
var position = _ref4.position;
|
22
|
-
return position.
|
25
|
+
return position.left || '';
|
23
26
|
}, function (_ref5) {
|
24
27
|
var position = _ref5.position;
|
25
|
-
return position.
|
28
|
+
return position.right || '';
|
26
29
|
}, function (_ref6) {
|
27
30
|
var position = _ref6.position;
|
31
|
+
return position.top || '';
|
32
|
+
}, function (_ref7) {
|
33
|
+
var position = _ref7.position;
|
34
|
+
return position.bottom || '';
|
35
|
+
}, function (_ref8) {
|
36
|
+
var position = _ref8.position;
|
28
37
|
return position.transform || '';
|
29
38
|
});
|
@@ -8,15 +8,21 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
8
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
9
9
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
|
-
import React, { createContext,
|
11
|
+
import React, { createContext, useState, useContext, useRef } from 'react';
|
12
12
|
import { hasModals } from '../Modal/ModalContext';
|
13
|
+
import { canUseDOM, safeUseId } from '../../utils';
|
14
|
+
import { Portal } from '../Portal';
|
15
|
+
import { StyledPortal } from './Popup.styles';
|
13
16
|
export var POPUP_PORTAL_ID = 'plasma-popup-root';
|
14
17
|
var items = [];
|
15
18
|
var PopupContext = /*#__PURE__*/createContext({
|
16
19
|
items: items,
|
20
|
+
rootId: POPUP_PORTAL_ID,
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
17
22
|
register: function register(_info) {
|
18
23
|
throw new Error('Function not implemented. Add PopupProvider');
|
19
24
|
},
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
20
26
|
unregister: function unregister(_id) {
|
21
27
|
throw new Error('Function not implemented. Add PopupProvider');
|
22
28
|
}
|
@@ -26,29 +32,46 @@ export var usePopupContext = function usePopupContext() {
|
|
26
32
|
};
|
27
33
|
export var PopupProvider = function PopupProvider(_ref) {
|
28
34
|
var children = _ref.children;
|
29
|
-
var
|
35
|
+
var globalItemsCount = useRef(0);
|
36
|
+
var prevBodyOverflowY = useRef(canUseDOM ? document.body.style.overflowY : '');
|
37
|
+
// eslint-disable-next-line no-shadow
|
30
38
|
var _useState = useState([]),
|
31
39
|
_useState2 = _slicedToArray(_useState, 2),
|
32
40
|
items = _useState2[0],
|
33
41
|
setItems = _useState2[1];
|
42
|
+
var uuid = safeUseId();
|
43
|
+
var rootId = "".concat(POPUP_PORTAL_ID, "-").concat(uuid);
|
34
44
|
var register = function register(info) {
|
45
|
+
if (!canUseDOM) {
|
46
|
+
return;
|
47
|
+
}
|
35
48
|
setItems(function (prevItems) {
|
36
49
|
var _info$info;
|
37
50
|
if ((_info$info = info.info) !== null && _info$info !== void 0 && _info$info.isModal && !hasModals(prevItems)) {
|
38
51
|
prevBodyOverflowY.current = document.body.style.overflowY;
|
39
52
|
document.body.style.overflowY = 'hidden';
|
40
53
|
}
|
54
|
+
if (info.isGlobalPopup) {
|
55
|
+
globalItemsCount.current += 1;
|
56
|
+
}
|
41
57
|
return [].concat(_toConsumableArray(prevItems), [info]);
|
42
58
|
});
|
43
59
|
};
|
44
60
|
var unregister = function unregister(id) {
|
61
|
+
if (!canUseDOM) {
|
62
|
+
return;
|
63
|
+
}
|
45
64
|
setItems(function (prevItems) {
|
65
|
+
var _prevItems$index;
|
46
66
|
var index = prevItems.findIndex(function (item) {
|
47
67
|
return id === item.id;
|
48
68
|
});
|
49
69
|
if (index === -1) {
|
50
70
|
return prevItems;
|
51
71
|
}
|
72
|
+
if (prevItems !== null && prevItems !== void 0 && (_prevItems$index = prevItems[index]) !== null && _prevItems$index !== void 0 && _prevItems$index.isGlobalPopup) {
|
73
|
+
globalItemsCount.current -= 1;
|
74
|
+
}
|
52
75
|
var prevHasModals = hasModals(prevItems);
|
53
76
|
prevItems.splice(index, 1);
|
54
77
|
if (prevHasModals && !hasModals(prevItems)) {
|
@@ -61,18 +84,16 @@ export var PopupProvider = function PopupProvider(_ref) {
|
|
61
84
|
};
|
62
85
|
var context = {
|
63
86
|
items: items,
|
87
|
+
rootId: rootId,
|
64
88
|
register: register,
|
65
89
|
unregister: unregister
|
66
90
|
};
|
67
|
-
useEffect(function () {
|
68
|
-
return function () {
|
69
|
-
var portal = document.createElement('div');
|
70
|
-
if (portal && document.body.contains(portal)) {
|
71
|
-
document.body.removeChild(portal);
|
72
|
-
}
|
73
|
-
};
|
74
|
-
}, []);
|
75
91
|
return /*#__PURE__*/React.createElement(PopupContext.Provider, {
|
76
92
|
value: context
|
77
|
-
}, children
|
93
|
+
}, children, /*#__PURE__*/React.createElement(Portal, {
|
94
|
+
container: document.body
|
95
|
+
}, /*#__PURE__*/React.createElement(StyledPortal, {
|
96
|
+
id: rootId,
|
97
|
+
hasContent: globalItemsCount.current > 0
|
98
|
+
})));
|
78
99
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
var _excluded = ["id", "placement", "offset", "
|
1
|
+
var _excluded = ["id", "placement", "offset", "setVisible", "children", "role", "zIndex", "animationInfo"];
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
@@ -16,13 +16,11 @@ export var PopupRoot = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
16
16
|
var id = _ref.id,
|
17
17
|
placement = _ref.placement,
|
18
18
|
offset = _ref.offset,
|
19
|
-
frame = _ref.frame,
|
20
19
|
setVisible = _ref.setVisible,
|
21
20
|
children = _ref.children,
|
22
21
|
role = _ref.role,
|
23
22
|
zIndex = _ref.zIndex,
|
24
23
|
animationInfo = _ref.animationInfo,
|
25
|
-
className = _ref.className,
|
26
24
|
rest = _objectWithoutProperties(_ref, _excluded);
|
27
25
|
var contentRef = useRef(null);
|
28
26
|
var innerRef = useForkRef(contentRef, ref);
|
@@ -13,7 +13,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
13
|
import { useEffect, useState } from 'react';
|
14
14
|
import { usePopupContext } from '../PopupContext';
|
15
15
|
|
16
|
-
// Хук для
|
16
|
+
// Хук для подключения анимации
|
17
17
|
var usePopupAnimation = function usePopupAnimation() {
|
18
18
|
var _useState = useState(false),
|
19
19
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -35,6 +35,7 @@ var usePopupAnimation = function usePopupAnimation() {
|
|
35
35
|
export var usePopup = function usePopup(_ref) {
|
36
36
|
var isOpen = _ref.isOpen,
|
37
37
|
id = _ref.id,
|
38
|
+
isGlobalPopup = _ref.isGlobalPopup,
|
38
39
|
popupInfo = _ref.popupInfo,
|
39
40
|
withAnimation = _ref.withAnimation;
|
40
41
|
var _useState5 = useState(false),
|
@@ -56,7 +57,8 @@ export var usePopup = function usePopup(_ref) {
|
|
56
57
|
// при первом открытии
|
57
58
|
if (isOpen && !isVisible) {
|
58
59
|
popupController.register(_objectSpread({
|
59
|
-
id: id
|
60
|
+
id: id,
|
61
|
+
isGlobalPopup: isGlobalPopup
|
60
62
|
}, popupInfo));
|
61
63
|
setVisible(true);
|
62
64
|
animationInfo.setEndAnimation(false);
|
@@ -85,6 +87,7 @@ export var usePopup = function usePopup(_ref) {
|
|
85
87
|
isVisible: isVisible,
|
86
88
|
setVisible: setVisible,
|
87
89
|
animationInfo: animationInfo,
|
88
|
-
withAnimation: withAnimation
|
90
|
+
withAnimation: withAnimation,
|
91
|
+
rootId: popupController.rootId
|
89
92
|
};
|
90
93
|
};
|
@@ -12,6 +12,9 @@ import { Popup, popupClasses, PopupProvider } from './Popup';
|
|
12
12
|
const meta: Meta<typeof Popup> = {
|
13
13
|
title: 'plasma_b2c/Popup',
|
14
14
|
decorators: [WithTheme],
|
15
|
+
parameters: {
|
16
|
+
docs: { story: { inline: false, iframeHeight: '30rem' } },
|
17
|
+
},
|
15
18
|
argTypes: {
|
16
19
|
placement: {
|
17
20
|
options: [
|
@@ -12,6 +12,9 @@ import { Popup, popupClasses, PopupProvider } from './Popup';
|
|
12
12
|
const meta: Meta<typeof Popup> = {
|
13
13
|
title: 'plasma_web/Popup',
|
14
14
|
decorators: [WithTheme],
|
15
|
+
parameters: {
|
16
|
+
docs: { story: { inline: false, iframeHeight: '30rem' } },
|
17
|
+
},
|
15
18
|
argTypes: {
|
16
19
|
placement: {
|
17
20
|
options: [
|
@@ -3,7 +3,7 @@ import { RootProps } from '../../engines/types';
|
|
3
3
|
import type { PopupPlacement, PopupPositionType, PopupProps } from './Popup.types';
|
4
4
|
export declare const handlePosition: (placement: PopupPlacement, offset: [number, number] | [string, string]) => PopupPositionType;
|
5
5
|
/**
|
6
|
-
* Базовый
|
6
|
+
* Базовый компонент Popup.
|
7
7
|
*/
|
8
8
|
export declare const popupRoot: (Root: RootProps<HTMLDivElement, PopupProps>) => React.ForwardRefExoticComponent<PopupProps & React.RefAttributes<HTMLDivElement>>;
|
9
9
|
export declare const popupConfig: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../../../src/components/Popup/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../../../src/components/Popup/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIhD,OAAO,KAAK,EAAuB,cAAc,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAMxG,eAAO,MAAM,cAAc,cACZ,cAAc,UACjB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAC5C,iBA8DF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,SAAU,UAAU,cAAc,EAAE,UAAU,CAAC,sFAuFhE,CAAC;AAEN,eAAO,MAAM,WAAW;;;mBAzFQ,UAAU,cAAc,EAAE,UAAU,CAAC;;;;CAgGpE,CAAC"}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import type { PopupRootContainerProps } from './Popup.types';
|
3
|
-
export declare const StyledPortal: import("@linaria/react").StyledComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> &
|
3
|
+
export declare const StyledPortal: import("@linaria/react").StyledComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
4
|
+
hasContent: boolean;
|
5
|
+
}>;
|
6
|
+
export declare const StyledPortalContainer: import("@linaria/react").StyledComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & Record<never, unknown>>;
|
4
7
|
export declare const PopupView: import("@linaria/react").StyledComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & Record<never, unknown>>;
|
5
8
|
export declare const PopupRootContainer: import("@linaria/react").StyledComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & PopupRootContainerProps>;
|
6
9
|
//# sourceMappingURL=Popup.styles.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Popup.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Popup/Popup.styles.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAG7D,eAAO,MAAM,YAAY,
|
1
|
+
{"version":3,"file":"Popup.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Popup/Popup.styles.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAG7D,eAAO,MAAM,YAAY;gBAA4B,OAAO;EAU3D,CAAC;AAEF,eAAO,MAAM,qBAAqB,qKAEjC,CAAC;AAEF,eAAO,MAAM,SAAS,qKAIrB,CAAC;AAEF,eAAO,MAAM,kBAAkB,sKAQ9B,CAAC"}
|
@@ -4,10 +4,12 @@ export declare type PopupPlacementMixed = 'top-right' | 'top-left' | 'bottom-rig
|
|
4
4
|
export declare type PopupPlacement = PopupPlacementBasic | PopupPlacementMixed;
|
5
5
|
export interface PopupInfo {
|
6
6
|
id: string;
|
7
|
+
isGlobalPopup?: boolean;
|
7
8
|
info?: Record<string, any>;
|
8
9
|
}
|
9
10
|
export interface PopupContextType {
|
10
11
|
items: PopupInfo[];
|
12
|
+
rootId: string;
|
11
13
|
register: (info: PopupInfo) => void;
|
12
14
|
unregister: (id: string) => void;
|
13
15
|
}
|
@@ -72,6 +74,7 @@ export interface PopupRootProps extends Omit<PopupProps, 'opened' | 'isOpen' | '
|
|
72
74
|
export interface PopupHookArgs extends Pick<PopupProps, 'popupInfo' | 'withAnimation'> {
|
73
75
|
id: string;
|
74
76
|
isOpen: boolean;
|
77
|
+
isGlobalPopup?: boolean;
|
75
78
|
}
|
76
79
|
export interface PopupRootContainerProps extends Omit<PopupProps, 'opened' | 'isOpen' | 'overlay'> {
|
77
80
|
endTransition?: boolean;
|