@salutejs/plasma-new-hope 0.158.0-dev.0 → 0.158.1-canary.1412.11141453905.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.js +1 -1
- package/cjs/components/Drawer/Drawer.styles.js +3 -0
- package/cjs/components/Drawer/Drawer.styles.js.map +1 -1
- package/cjs/components/Drawer/hooks/useDrawer.js +1 -1
- package/cjs/components/Modal/Modal.css +4 -3
- package/cjs/components/Modal/hooks/useModal.js +1 -1
- package/cjs/components/Notification/NotificationsProvider.css +4 -3
- package/cjs/components/Popup/Popup.js +29 -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 +30 -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 +30 -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 +30 -43
- package/emotion/es/components/Popup/Popup.styles.js +34 -16
- package/emotion/es/components/Popup/PopupContext.js +30 -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.js +1 -1
- package/es/components/Drawer/Drawer.styles.js +3 -0
- package/es/components/Drawer/Drawer.styles.js.map +1 -1
- package/es/components/Drawer/hooks/useDrawer.js +1 -1
- package/es/components/Modal/Modal.css +4 -3
- package/es/components/Modal/hooks/useModal.js +1 -1
- package/es/components/Notification/NotificationsProvider.css +4 -3
- package/es/components/Popup/Popup.js +31 -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 +31 -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 +30 -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 +30 -43
- package/styled-components/es/components/Popup/Popup.styles.js +22 -13
- package/styled-components/es/components/Popup/PopupContext.js +30 -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
@@ -6,14 +6,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.popupRoot = exports.popupConfig = exports.handlePosition = void 0;
|
8
8
|
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
9
|
+
var _reactDom = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react-dom"));
|
9
10
|
var _plasmaCore = /*#__PURE__*/require("@salutejs/plasma-core");
|
10
11
|
var _utils = /*#__PURE__*/require("../../utils");
|
11
12
|
var _Portal = /*#__PURE__*/require("../Portal");
|
12
|
-
var _PopupContext = /*#__PURE__*/require("./PopupContext");
|
13
13
|
var _PopupRoot = /*#__PURE__*/require("./PopupRoot");
|
14
14
|
var _hooks = /*#__PURE__*/require("./hooks");
|
15
15
|
var _Popup = /*#__PURE__*/require("./Popup.tokens");
|
16
|
+
var _Popup2 = /*#__PURE__*/require("./Popup.styles");
|
16
17
|
var _excluded = ["id", "isOpen", "opened", "placement", "offset", "frame", "children", "overlay", "role", "zIndex", "popupInfo", "withAnimation", "className"];
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
17
19
|
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); }
|
18
20
|
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; }
|
19
21
|
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); }
|
@@ -48,8 +50,8 @@ var handlePosition = exports.handlePosition = function handlePosition(placement,
|
|
48
50
|
var bottom;
|
49
51
|
var transform;
|
50
52
|
var placements = placement.split('-');
|
51
|
-
placements.forEach(function (
|
52
|
-
switch (
|
53
|
+
placements.forEach(function (placementValue) {
|
54
|
+
switch (placementValue) {
|
53
55
|
case 'left':
|
54
56
|
left = x;
|
55
57
|
break;
|
@@ -84,7 +86,7 @@ var handlePosition = exports.handlePosition = function handlePosition(placement,
|
|
84
86
|
};
|
85
87
|
|
86
88
|
/**
|
87
|
-
* Базовый
|
89
|
+
* Базовый компонент Popup.
|
88
90
|
*/
|
89
91
|
var popupRoot = exports.popupRoot = function popupRoot(Root) {
|
90
92
|
return /*#__PURE__*/(0, _react.forwardRef)(function (_ref, outerRootRef) {
|
@@ -114,63 +116,49 @@ var popupRoot = exports.popupRoot = function popupRoot(Root) {
|
|
114
116
|
var _usePopup = (0, _hooks.usePopup)({
|
115
117
|
isOpen: innerIsOpen,
|
116
118
|
id: innerId,
|
119
|
+
isGlobalPopup: !frame || frame === 'document',
|
117
120
|
popupInfo: popupInfo,
|
118
121
|
withAnimation: withAnimation
|
119
122
|
}),
|
120
123
|
isVisible = _usePopup.isVisible,
|
121
124
|
animationInfo = _usePopup.animationInfo,
|
122
|
-
setVisible = _usePopup.setVisible
|
125
|
+
setVisible = _usePopup.setVisible,
|
126
|
+
rootId = _usePopup.rootId;
|
123
127
|
var portalRef = (0, _react.useRef)(null);
|
124
128
|
var contentRef = (0, _react.useRef)(null);
|
125
129
|
var innerRef = (0, _plasmaCore.useForkRef)(contentRef, outerRootRef);
|
126
|
-
var _useState = (0, _react.useState)(false),
|
127
|
-
_useState2 = _slicedToArray(_useState, 2),
|
128
|
-
forceRender = _useState2[1];
|
129
|
-
(0, _react.useEffect)(function () {
|
130
|
-
var portal = document.getElementById(_PopupContext.POPUP_PORTAL_ID);
|
131
|
-
if (typeof frame !== 'string' && frame && frame.current) {
|
132
|
-
portal = frame.current;
|
133
|
-
}
|
134
|
-
if (!portal) {
|
135
|
-
portal = document.createElement('div');
|
136
|
-
portal.setAttribute('id', _PopupContext.POPUP_PORTAL_ID);
|
137
|
-
/**
|
138
|
-
* Нужно для того, чтобы во фрейме не происходило скачков контента
|
139
|
-
* при анимации через transform, если есть элемент с шириной/высотой в 100% (Overlay)
|
140
|
-
*/
|
141
|
-
portal.style.width = '0';
|
142
|
-
if (typeof frame === 'string' && frame !== 'document') {
|
143
|
-
var _document$getElementB;
|
144
|
-
(_document$getElementB = document.getElementById(frame)) === null || _document$getElementB === void 0 || _document$getElementB.appendChild(portal);
|
145
|
-
} else {
|
146
|
-
document.body.appendChild(portal);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
portalRef.current = portal;
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Изменение стейта нужно для того, чтобы Popup
|
153
|
-
* отобразился после записи DOM элемента в portalRef.current
|
154
|
-
*/
|
155
|
-
forceRender(true);
|
156
|
-
}, []);
|
157
130
|
if (!isVisible && !innerIsOpen) {
|
158
131
|
return null;
|
159
132
|
}
|
160
133
|
var cls = (0, _utils.cx)(className, animationInfo !== null && animationInfo !== void 0 && animationInfo.endAnimation ? _Popup.classes.endAnimation : '', animationInfo !== null && animationInfo !== void 0 && animationInfo.endTransition ? _Popup.classes.endTransition : '');
|
161
|
-
|
162
|
-
container: portalRef.current
|
163
|
-
}, /*#__PURE__*/_react["default"].createElement(Root, _extends({
|
134
|
+
var rootNode = /*#__PURE__*/_react["default"].createElement(Root, _extends({
|
164
135
|
className: cls
|
165
136
|
}, rest), overlay, /*#__PURE__*/_react["default"].createElement(_PopupRoot.PopupRoot, {
|
166
137
|
id: innerId,
|
167
138
|
ref: innerRef,
|
168
139
|
position: handlePosition(placement, offset),
|
169
|
-
frame: frame,
|
170
140
|
zIndex: zIndex,
|
171
141
|
animationInfo: animationInfo,
|
172
142
|
setVisible: setVisible
|
173
|
-
}, children))
|
143
|
+
}, children));
|
144
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
145
|
+
return /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
146
|
+
container: frame.current
|
147
|
+
}, rootNode);
|
148
|
+
}
|
149
|
+
var withFrameId = typeof frame === 'string' && frame !== 'document';
|
150
|
+
var containerElement = withFrameId && document.getElementById(frame);
|
151
|
+
if (containerElement) {
|
152
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_reactDom["default"].createPortal( /*#__PURE__*/_react["default"].createElement(_Popup2.StyledPortalContainer, {
|
153
|
+
ref: portalRef
|
154
|
+
}, portalRef.current && /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
155
|
+
container: portalRef.current
|
156
|
+
}, rootNode)), containerElement));
|
157
|
+
}
|
158
|
+
var globalPortal = _utils.canUseDOM && document.getElementById(rootId);
|
159
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, globalPortal && /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
160
|
+
container: globalPortal
|
161
|
+
}, rootNode));
|
174
162
|
});
|
175
163
|
};
|
176
164
|
var popupConfig = exports.popupConfig = {
|
@@ -3,34 +3,43 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.StyledPortal = exports.PopupView = exports.PopupRootContainer = void 0;
|
6
|
+
exports.StyledPortalContainer = exports.StyledPortal = exports.PopupView = exports.PopupRootContainer = void 0;
|
7
7
|
var _styledComponents = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("styled-components"));
|
8
8
|
var _utils = /*#__PURE__*/require("./utils");
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
10
10
|
var StyledPortal = exports.StyledPortal = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
11
11
|
componentId: "plasma-new-hope__sc-rkhnjn-0"
|
12
|
-
})([""])
|
13
|
-
var
|
12
|
+
})(["position:fixed;top:0;left:0;right:0;bottom:0;z-index:", ";width:", ";pointer-events:", ";"], _utils.DEFAULT_Z_INDEX, function (_ref) {
|
13
|
+
var hasContent = _ref.hasContent;
|
14
|
+
return hasContent ? 'auto' : '0';
|
15
|
+
}, function (_ref2) {
|
16
|
+
var hasContent = _ref2.hasContent;
|
17
|
+
return hasContent ? 'auto' : 'none';
|
18
|
+
});
|
19
|
+
var StyledPortalContainer = exports.StyledPortalContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
14
20
|
componentId: "plasma-new-hope__sc-rkhnjn-1"
|
21
|
+
})(["width:0;"]);
|
22
|
+
var PopupView = exports.PopupView = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
23
|
+
componentId: "plasma-new-hope__sc-rkhnjn-2"
|
15
24
|
})(["position:relative;max-width:100%;pointer-events:all;"]);
|
16
25
|
var PopupRootContainer = exports.PopupRootContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
17
|
-
componentId: "plasma-new-hope__sc-rkhnjn-
|
18
|
-
})(["position:absolute;z-index:", ";left:", ";right:", ";top:", ";bottom:", ";transform:", ";"], function (
|
19
|
-
var zIndex =
|
26
|
+
componentId: "plasma-new-hope__sc-rkhnjn-3"
|
27
|
+
})(["position:absolute;z-index:", ";left:", ";right:", ";top:", ";bottom:", ";transform:", ";"], function (_ref3) {
|
28
|
+
var zIndex = _ref3.zIndex;
|
20
29
|
return zIndex || _utils.DEFAULT_Z_INDEX;
|
21
|
-
}, function (_ref2) {
|
22
|
-
var position = _ref2.position;
|
23
|
-
return position.left || '';
|
24
|
-
}, function (_ref3) {
|
25
|
-
var position = _ref3.position;
|
26
|
-
return position.right || '';
|
27
30
|
}, function (_ref4) {
|
28
31
|
var position = _ref4.position;
|
29
|
-
return position.
|
32
|
+
return position.left || '';
|
30
33
|
}, function (_ref5) {
|
31
34
|
var position = _ref5.position;
|
32
|
-
return position.
|
35
|
+
return position.right || '';
|
33
36
|
}, function (_ref6) {
|
34
37
|
var position = _ref6.position;
|
38
|
+
return position.top || '';
|
39
|
+
}, function (_ref7) {
|
40
|
+
var position = _ref7.position;
|
41
|
+
return position.bottom || '';
|
42
|
+
}, function (_ref8) {
|
43
|
+
var position = _ref8.position;
|
35
44
|
return position.transform || '';
|
36
45
|
});
|
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.usePopupContext = exports.PopupProvider = exports.POPUP_PORTAL_ID = void 0;
|
8
8
|
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
9
|
+
var _reactDom = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react-dom"));
|
9
10
|
var _ModalContext = /*#__PURE__*/require("../Modal/ModalContext");
|
11
|
+
var _utils = /*#__PURE__*/require("../../utils");
|
12
|
+
var _Popup = /*#__PURE__*/require("./Popup.styles");
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
10
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); }
|
11
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; }
|
12
16
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
@@ -23,9 +27,12 @@ var POPUP_PORTAL_ID = exports.POPUP_PORTAL_ID = 'plasma-popup-root';
|
|
23
27
|
var items = [];
|
24
28
|
var PopupContext = /*#__PURE__*/(0, _react.createContext)({
|
25
29
|
items: items,
|
30
|
+
rootId: POPUP_PORTAL_ID,
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
26
32
|
register: function register(_info) {
|
27
33
|
throw new Error('Function not implemented. Add PopupProvider');
|
28
34
|
},
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
29
36
|
unregister: function unregister(_id) {
|
30
37
|
throw new Error('Function not implemented. Add PopupProvider');
|
31
38
|
}
|
@@ -35,29 +42,46 @@ var usePopupContext = exports.usePopupContext = function usePopupContext() {
|
|
35
42
|
};
|
36
43
|
var PopupProvider = exports.PopupProvider = function PopupProvider(_ref) {
|
37
44
|
var children = _ref.children;
|
38
|
-
var
|
45
|
+
var globalItemsCount = (0, _react.useRef)(0);
|
46
|
+
var prevBodyOverflowY = (0, _react.useRef)(_utils.canUseDOM ? document.body.style.overflowY : '');
|
47
|
+
// eslint-disable-next-line no-shadow
|
39
48
|
var _useState = (0, _react.useState)([]),
|
40
49
|
_useState2 = _slicedToArray(_useState, 2),
|
41
50
|
items = _useState2[0],
|
42
51
|
setItems = _useState2[1];
|
52
|
+
var uuid = (0, _utils.safeUseId)();
|
53
|
+
var rootId = "".concat(POPUP_PORTAL_ID, "-").concat(uuid);
|
43
54
|
var register = function register(info) {
|
55
|
+
if (!_utils.canUseDOM) {
|
56
|
+
return;
|
57
|
+
}
|
44
58
|
setItems(function (prevItems) {
|
45
59
|
var _info$info;
|
46
60
|
if ((_info$info = info.info) !== null && _info$info !== void 0 && _info$info.isModal && !(0, _ModalContext.hasModals)(prevItems)) {
|
47
61
|
prevBodyOverflowY.current = document.body.style.overflowY;
|
48
62
|
document.body.style.overflowY = 'hidden';
|
49
63
|
}
|
64
|
+
if (info.isGlobalPopup) {
|
65
|
+
globalItemsCount.current += 1;
|
66
|
+
}
|
50
67
|
return [].concat(_toConsumableArray(prevItems), [info]);
|
51
68
|
});
|
52
69
|
};
|
53
70
|
var unregister = function unregister(id) {
|
71
|
+
if (!_utils.canUseDOM) {
|
72
|
+
return;
|
73
|
+
}
|
54
74
|
setItems(function (prevItems) {
|
75
|
+
var _prevItems$index;
|
55
76
|
var index = prevItems.findIndex(function (item) {
|
56
77
|
return id === item.id;
|
57
78
|
});
|
58
79
|
if (index === -1) {
|
59
80
|
return prevItems;
|
60
81
|
}
|
82
|
+
if (prevItems !== null && prevItems !== void 0 && (_prevItems$index = prevItems[index]) !== null && _prevItems$index !== void 0 && _prevItems$index.isGlobalPopup) {
|
83
|
+
globalItemsCount.current -= 1;
|
84
|
+
}
|
61
85
|
var prevHasModals = (0, _ModalContext.hasModals)(prevItems);
|
62
86
|
prevItems.splice(index, 1);
|
63
87
|
if (prevHasModals && !(0, _ModalContext.hasModals)(prevItems)) {
|
@@ -70,18 +94,14 @@ var PopupProvider = exports.PopupProvider = function PopupProvider(_ref) {
|
|
70
94
|
};
|
71
95
|
var context = {
|
72
96
|
items: items,
|
97
|
+
rootId: rootId,
|
73
98
|
register: register,
|
74
99
|
unregister: unregister
|
75
100
|
};
|
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
101
|
return /*#__PURE__*/_react["default"].createElement(PopupContext.Provider, {
|
85
102
|
value: context
|
86
|
-
}, children
|
103
|
+
}, children, /*#__PURE__*/_reactDom["default"].createPortal( /*#__PURE__*/_react["default"].createElement(_Popup.StyledPortal, {
|
104
|
+
id: rootId,
|
105
|
+
hasContent: globalItemsCount.current > 0
|
106
|
+
}), document.body));
|
87
107
|
};
|
@@ -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,15 @@ 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
|
+
import ReactDOM from 'react-dom';
|
12
13
|
import { useForkRef, safeUseId } from '@salutejs/plasma-core';
|
13
|
-
import { cx } from '../../utils';
|
14
|
+
import { canUseDOM, cx } from '../../utils';
|
14
15
|
import { Portal } from '../Portal';
|
15
|
-
import { POPUP_PORTAL_ID } from './PopupContext';
|
16
16
|
import { PopupRoot } from './PopupRoot';
|
17
17
|
import { usePopup } from './hooks';
|
18
18
|
import { classes } from './Popup.tokens';
|
19
|
+
import { StyledPortalContainer } from './Popup.styles';
|
19
20
|
export var handlePosition = function handlePosition(placement, offset) {
|
20
21
|
var x = '0rem';
|
21
22
|
var y = '0rem';
|
@@ -39,8 +40,8 @@ export var handlePosition = function handlePosition(placement, offset) {
|
|
39
40
|
var bottom;
|
40
41
|
var transform;
|
41
42
|
var placements = placement.split('-');
|
42
|
-
placements.forEach(function (
|
43
|
-
switch (
|
43
|
+
placements.forEach(function (placementValue) {
|
44
|
+
switch (placementValue) {
|
44
45
|
case 'left':
|
45
46
|
left = x;
|
46
47
|
break;
|
@@ -75,7 +76,7 @@ export var handlePosition = function handlePosition(placement, offset) {
|
|
75
76
|
};
|
76
77
|
|
77
78
|
/**
|
78
|
-
* Базовый
|
79
|
+
* Базовый компонент Popup.
|
79
80
|
*/
|
80
81
|
export var popupRoot = function popupRoot(Root) {
|
81
82
|
return /*#__PURE__*/forwardRef(function (_ref, outerRootRef) {
|
@@ -105,63 +106,49 @@ export var popupRoot = function popupRoot(Root) {
|
|
105
106
|
var _usePopup = usePopup({
|
106
107
|
isOpen: innerIsOpen,
|
107
108
|
id: innerId,
|
109
|
+
isGlobalPopup: !frame || frame === 'document',
|
108
110
|
popupInfo: popupInfo,
|
109
111
|
withAnimation: withAnimation
|
110
112
|
}),
|
111
113
|
isVisible = _usePopup.isVisible,
|
112
114
|
animationInfo = _usePopup.animationInfo,
|
113
|
-
setVisible = _usePopup.setVisible
|
115
|
+
setVisible = _usePopup.setVisible,
|
116
|
+
rootId = _usePopup.rootId;
|
114
117
|
var portalRef = useRef(null);
|
115
118
|
var contentRef = useRef(null);
|
116
119
|
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
120
|
if (!isVisible && !innerIsOpen) {
|
149
121
|
return null;
|
150
122
|
}
|
151
123
|
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({
|
124
|
+
var rootNode = /*#__PURE__*/React.createElement(Root, _extends({
|
155
125
|
className: cls
|
156
126
|
}, rest), overlay, /*#__PURE__*/React.createElement(PopupRoot, {
|
157
127
|
id: innerId,
|
158
128
|
ref: innerRef,
|
159
129
|
position: handlePosition(placement, offset),
|
160
|
-
frame: frame,
|
161
130
|
zIndex: zIndex,
|
162
131
|
animationInfo: animationInfo,
|
163
132
|
setVisible: setVisible
|
164
|
-
}, children))
|
133
|
+
}, children));
|
134
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
135
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
136
|
+
container: frame.current
|
137
|
+
}, rootNode);
|
138
|
+
}
|
139
|
+
var withFrameId = typeof frame === 'string' && frame !== 'document';
|
140
|
+
var containerElement = withFrameId && document.getElementById(frame);
|
141
|
+
if (containerElement) {
|
142
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(StyledPortalContainer, {
|
143
|
+
ref: portalRef
|
144
|
+
}, portalRef.current && /*#__PURE__*/React.createElement(Portal, {
|
145
|
+
container: portalRef.current
|
146
|
+
}, rootNode)), containerElement));
|
147
|
+
}
|
148
|
+
var globalPortal = canUseDOM && document.getElementById(rootId);
|
149
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, globalPortal && /*#__PURE__*/React.createElement(Portal, {
|
150
|
+
container: globalPortal
|
151
|
+
}, rootNode));
|
165
152
|
});
|
166
153
|
};
|
167
154
|
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
|
});
|