@salutejs/plasma-core 1.133.0-dev.0 → 1.133.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/plasma-core.api.md +21 -0
- package/components/PopupBase/PopupBase.d.ts +31 -0
- package/components/PopupBase/PopupBase.js +187 -0
- package/components/PopupBase/PopupBaseContext.d.ts +15 -0
- package/components/PopupBase/PopupBaseContext.js +73 -0
- package/components/PopupBase/index.d.ts +2 -0
- package/components/PopupBase/index.js +13 -0
- package/es/components/PopupBase/PopupBase.js +161 -0
- package/es/components/PopupBase/PopupBaseContext.js +53 -0
- package/es/components/PopupBase/index.js +1 -0
- package/es/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +13 -0
- package/package.json +2 -2
package/api/plasma-core.api.md
CHANGED
|
@@ -841,6 +841,27 @@ export interface PopoverProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
841
841
|
// @public @deprecated
|
|
842
842
|
export const Popup: React_2.NamedExoticComponent<PopupProps & React_2.RefAttributes<HTMLDivElement>>;
|
|
843
843
|
|
|
844
|
+
// @public
|
|
845
|
+
export const PopupBase: FC<PopupBaseProps>;
|
|
846
|
+
|
|
847
|
+
// Warning: (ae-forgotten-export) The symbol "BasicPopupBasePlacement" needs to be exported by the entry point index.d.ts
|
|
848
|
+
// Warning: (ae-forgotten-export) The symbol "MixedPopupBasePlacement" needs to be exported by the entry point index.d.ts
|
|
849
|
+
//
|
|
850
|
+
// @public (undocumented)
|
|
851
|
+
export type PopupBasePlacement = BasicPopupBasePlacement | MixedPopupBasePlacement;
|
|
852
|
+
|
|
853
|
+
// @public (undocumented)
|
|
854
|
+
export interface PopupBaseProps extends React_2.HTMLAttributes<HTMLDivElement> {
|
|
855
|
+
children?: React_2.ReactNode;
|
|
856
|
+
frame?: 'document' | React_2.RefObject<HTMLElement>;
|
|
857
|
+
isOpen: boolean;
|
|
858
|
+
// (undocumented)
|
|
859
|
+
offset?: [number | string, number | string];
|
|
860
|
+
// (undocumented)
|
|
861
|
+
placement?: PopupBasePlacement;
|
|
862
|
+
zIndex?: string;
|
|
863
|
+
}
|
|
864
|
+
|
|
844
865
|
// @public (undocumented)
|
|
845
866
|
export interface PopupProps extends HTMLAttributes<HTMLDivElement> {
|
|
846
867
|
children?: ReactNode;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
declare type BasicPopupBasePlacement = 'center' | 'top' | 'bottom' | 'right' | 'left';
|
|
3
|
+
declare type MixedPopupBasePlacement = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
4
|
+
export declare type PopupBasePlacement = BasicPopupBasePlacement | MixedPopupBasePlacement;
|
|
5
|
+
export interface PopupBaseProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
/**
|
|
7
|
+
* Отображение PopupBase.
|
|
8
|
+
*/
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
placement?: PopupBasePlacement;
|
|
11
|
+
offset?: [number | string, number | string];
|
|
12
|
+
/**
|
|
13
|
+
* В каком контейнере позиционируется(по умолчанию document).
|
|
14
|
+
*/
|
|
15
|
+
frame?: 'document' | React.RefObject<HTMLElement>;
|
|
16
|
+
/**
|
|
17
|
+
* Содержимое PopupBase.
|
|
18
|
+
*/
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Значение z-index для PopupBase.
|
|
22
|
+
*/
|
|
23
|
+
zIndex?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const DEFAULT_Z_INDEX = 9000;
|
|
26
|
+
/**
|
|
27
|
+
* Базовый PopupBase.
|
|
28
|
+
* Управляет показом/скрытием и анимацией(?) высплывающего окна.
|
|
29
|
+
*/
|
|
30
|
+
export declare const PopupBase: FC<PopupBaseProps>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.PopupBase = exports.DEFAULT_Z_INDEX = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
|
11
|
+
|
|
12
|
+
var _reactDom = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react-dom"));
|
|
13
|
+
|
|
14
|
+
var _styledComponents = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("styled-components"));
|
|
15
|
+
|
|
16
|
+
var _hooks = /*#__PURE__*/require("../../hooks");
|
|
17
|
+
|
|
18
|
+
var _PopupBaseContext = /*#__PURE__*/require("./PopupBaseContext");
|
|
19
|
+
|
|
20
|
+
var _collectPackageInfo = /*#__PURE__*/require("../../collectPackageInfo");
|
|
21
|
+
|
|
22
|
+
var _excluded = ["id", "isOpen", "placement", "offset", "frame", "children", "role", "zIndex"];
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
|
|
30
|
+
function _extends() { _extends = Object.assign || 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); }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
37
|
+
|
|
38
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
39
|
+
|
|
40
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
41
|
+
|
|
42
|
+
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; }
|
|
43
|
+
|
|
44
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
45
|
+
|
|
46
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
47
|
+
|
|
48
|
+
(0, _collectPackageInfo.collectPackageInfo)('PopupBase/PopupBase');
|
|
49
|
+
var DEFAULT_Z_INDEX = 9000;
|
|
50
|
+
exports.DEFAULT_Z_INDEX = DEFAULT_Z_INDEX;
|
|
51
|
+
|
|
52
|
+
var PopupBaseView = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
53
|
+
componentId: "plasma__sc-1md4coi-0"
|
|
54
|
+
})(["position:relative;max-width:100%;pointer-events:all;"]);
|
|
55
|
+
|
|
56
|
+
var handlePosition = function handlePosition(placement, offset) {
|
|
57
|
+
var x = '0rem';
|
|
58
|
+
var y = '0rem';
|
|
59
|
+
|
|
60
|
+
if (offset) {
|
|
61
|
+
var _offset = _slicedToArray(offset, 2),
|
|
62
|
+
_x = _offset[0],
|
|
63
|
+
_y = _offset[1];
|
|
64
|
+
|
|
65
|
+
x = typeof _x === 'number' ? "".concat(_x, "rem") : _x;
|
|
66
|
+
y = typeof _y === 'number' ? "".concat(_y, "rem") : _y;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!placement || placement === 'center') {
|
|
70
|
+
return (0, _styledComponents.css)(["left:calc(50% + ", ");top:calc(50% - ", ");transform:translate(-50%,-50%);"], x, y);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var left;
|
|
74
|
+
var right;
|
|
75
|
+
var top;
|
|
76
|
+
var bottom;
|
|
77
|
+
var placements = placement.split('-');
|
|
78
|
+
placements.forEach(function (placement) {
|
|
79
|
+
switch (placement) {
|
|
80
|
+
case 'left':
|
|
81
|
+
left = x;
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'right':
|
|
85
|
+
right = x;
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'top':
|
|
89
|
+
top = y;
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case 'bottom':
|
|
93
|
+
bottom = y;
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
default:
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
var isCenteredX = left === undefined && right === undefined;
|
|
101
|
+
var isCenteredY = top === undefined && bottom === undefined;
|
|
102
|
+
return (0, _styledComponents.css)(["left:", ";right:", ";top:", ";bottom:", ";", " ", ""], left, right, top, bottom, isCenteredX && (0, _styledComponents.css)(["left:calc(50% + ", ");transform:translateX(-50%);"], x), isCenteredY && (0, _styledComponents.css)(["top:calc(50% - ", ");transform:translateY(-50%);"], y));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var PopupBaseRoot = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
106
|
+
componentId: "plasma__sc-1md4coi-1"
|
|
107
|
+
})(["", " ", " ", ";"], function (_ref) {
|
|
108
|
+
var frame = _ref.frame;
|
|
109
|
+
return (0, _styledComponents.css)(["position:", ";"], frame === 'document' ? 'fixed' : 'absolute');
|
|
110
|
+
}, function (_ref2) {
|
|
111
|
+
var zIndex = _ref2.zIndex;
|
|
112
|
+
return (0, _styledComponents.css)(["z-index:", ";"], zIndex || DEFAULT_Z_INDEX);
|
|
113
|
+
}, function (_ref3) {
|
|
114
|
+
var placement = _ref3.placement,
|
|
115
|
+
offset = _ref3.offset;
|
|
116
|
+
return handlePosition(placement, offset);
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* Базовый PopupBase.
|
|
120
|
+
* Управляет показом/скрытием и анимацией(?) высплывающего окна.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
var PopupBase = function PopupBase(_ref4) {
|
|
125
|
+
var id = _ref4.id,
|
|
126
|
+
isOpen = _ref4.isOpen,
|
|
127
|
+
placement = _ref4.placement,
|
|
128
|
+
offset = _ref4.offset,
|
|
129
|
+
_ref4$frame = _ref4.frame,
|
|
130
|
+
frame = _ref4$frame === void 0 ? 'document' : _ref4$frame,
|
|
131
|
+
children = _ref4.children,
|
|
132
|
+
role = _ref4.role,
|
|
133
|
+
zIndex = _ref4.zIndex,
|
|
134
|
+
rest = _objectWithoutProperties(_ref4, _excluded);
|
|
135
|
+
|
|
136
|
+
var uniqId = (0, _hooks.useUniqId)();
|
|
137
|
+
var innerId = id || uniqId;
|
|
138
|
+
var portalRef = (0, _react.useRef)(null);
|
|
139
|
+
var controller = (0, _react.useContext)(_PopupBaseContext.PopupBaseContext);
|
|
140
|
+
|
|
141
|
+
var _useState = (0, _react.useState)(false),
|
|
142
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
143
|
+
forceRender = _useState2[1];
|
|
144
|
+
|
|
145
|
+
(0, _react.useEffect)(function () {
|
|
146
|
+
var portal = document.getElementById(_PopupBaseContext.POPOVER_PORTAL_ID);
|
|
147
|
+
|
|
148
|
+
if (frame !== 'document' && frame && frame.current) {
|
|
149
|
+
portal = frame.current;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!portal) {
|
|
153
|
+
portal = document.createElement('div');
|
|
154
|
+
portal.setAttribute('id', _PopupBaseContext.POPOVER_PORTAL_ID);
|
|
155
|
+
document.body.appendChild(portal);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
portalRef.current = portal;
|
|
159
|
+
/**
|
|
160
|
+
* Изменение стейта нужно для того, чтобы PopupBase
|
|
161
|
+
* отобразился после записи DOM элемента в portalRef.current
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
forceRender(true);
|
|
165
|
+
return function () {
|
|
166
|
+
controller.unregister(innerId);
|
|
167
|
+
};
|
|
168
|
+
}, [controller, innerId, zIndex]);
|
|
169
|
+
|
|
170
|
+
if (isOpen) {
|
|
171
|
+
controller.register(innerId);
|
|
172
|
+
} else {
|
|
173
|
+
controller.unregister(innerId);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, portalRef.current && /*#__PURE__*/_reactDom["default"].createPortal( /*#__PURE__*/_react["default"].createElement(PopupBaseRoot, {
|
|
178
|
+
placement: placement,
|
|
179
|
+
frame: frame,
|
|
180
|
+
offset: offset,
|
|
181
|
+
zIndex: zIndex
|
|
182
|
+
}, /*#__PURE__*/_react["default"].createElement(PopupBaseView, _extends({}, rest, {
|
|
183
|
+
role: role
|
|
184
|
+
}), children)), portalRef.current));
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
exports.PopupBase = PopupBase;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Хранилище модальных окон.
|
|
4
|
+
*/
|
|
5
|
+
declare class PopupBaseController {
|
|
6
|
+
items: string[];
|
|
7
|
+
register(id: string): number;
|
|
8
|
+
unregister(id: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const POPOVER_PORTAL_ID = "plasma-popup-root";
|
|
11
|
+
export declare const PopupBaseContext: React.Context<PopupBaseController>;
|
|
12
|
+
export declare const PopupBaseProvider: React.FC<{
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.PopupBaseProvider = exports.PopupBaseContext = exports.POPOVER_PORTAL_ID = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
+
|
|
18
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
19
|
+
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Хранилище модальных окон.
|
|
26
|
+
*/
|
|
27
|
+
var PopupBaseController = /*#__PURE__*/function () {
|
|
28
|
+
function PopupBaseController() {
|
|
29
|
+
_classCallCheck(this, PopupBaseController);
|
|
30
|
+
|
|
31
|
+
_defineProperty(this, "items", []);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_createClass(PopupBaseController, [{
|
|
35
|
+
key: "register",
|
|
36
|
+
value: function register(id) {
|
|
37
|
+
return this.items.push(id);
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "unregister",
|
|
41
|
+
value: function unregister(id) {
|
|
42
|
+
this.items.splice(this.items.indexOf(id), 1);
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
|
|
46
|
+
return PopupBaseController;
|
|
47
|
+
}();
|
|
48
|
+
|
|
49
|
+
var controller = /*#__PURE__*/new PopupBaseController();
|
|
50
|
+
var POPOVER_PORTAL_ID = 'plasma-popup-root';
|
|
51
|
+
exports.POPOVER_PORTAL_ID = POPOVER_PORTAL_ID;
|
|
52
|
+
|
|
53
|
+
var PopupBaseContext = /*#__PURE__*/_react["default"].createContext(controller);
|
|
54
|
+
|
|
55
|
+
exports.PopupBaseContext = PopupBaseContext;
|
|
56
|
+
|
|
57
|
+
var PopupBaseProvider = function PopupBaseProvider(_ref) {
|
|
58
|
+
var children = _ref.children;
|
|
59
|
+
(0, _react.useEffect)(function () {
|
|
60
|
+
return function () {
|
|
61
|
+
var portal = document.createElement('div');
|
|
62
|
+
|
|
63
|
+
if (portal && document.body.contains(portal)) {
|
|
64
|
+
document.body.removeChild(portal);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
return /*#__PURE__*/_react["default"].createElement(PopupBaseContext.Provider, {
|
|
69
|
+
value: controller
|
|
70
|
+
}, children);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
exports.PopupBaseProvider = PopupBaseProvider;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "PopupBase", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _PopupBase.PopupBase;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _PopupBase = /*#__PURE__*/require("./PopupBase");
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
var _excluded = ["id", "isOpen", "placement", "offset", "frame", "children", "role", "zIndex"];
|
|
2
|
+
|
|
3
|
+
function _extends() { _extends = Object.assign || 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); }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
18
|
+
|
|
19
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
+
|
|
21
|
+
import React, { useEffect, useRef, useState, useContext } from 'react';
|
|
22
|
+
import ReactDOM from 'react-dom';
|
|
23
|
+
import styled, { css } from 'styled-components';
|
|
24
|
+
import { useUniqId } from '../../hooks';
|
|
25
|
+
import { PopupBaseContext, POPOVER_PORTAL_ID } from './PopupBaseContext';
|
|
26
|
+
import { collectPackageInfo } from '../../collectPackageInfo';
|
|
27
|
+
collectPackageInfo('PopupBase/PopupBase');
|
|
28
|
+
export var DEFAULT_Z_INDEX = 9000;
|
|
29
|
+
var PopupBaseView = /*#__PURE__*/styled.div.withConfig({
|
|
30
|
+
componentId: "plasma__sc-1md4coi-0"
|
|
31
|
+
})(["position:relative;max-width:100%;pointer-events:all;"]);
|
|
32
|
+
|
|
33
|
+
var handlePosition = function handlePosition(placement, offset) {
|
|
34
|
+
var x = '0rem';
|
|
35
|
+
var y = '0rem';
|
|
36
|
+
|
|
37
|
+
if (offset) {
|
|
38
|
+
var _offset = _slicedToArray(offset, 2),
|
|
39
|
+
_x = _offset[0],
|
|
40
|
+
_y = _offset[1];
|
|
41
|
+
|
|
42
|
+
x = typeof _x === 'number' ? "".concat(_x, "rem") : _x;
|
|
43
|
+
y = typeof _y === 'number' ? "".concat(_y, "rem") : _y;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!placement || placement === 'center') {
|
|
47
|
+
return css(["left:calc(50% + ", ");top:calc(50% - ", ");transform:translate(-50%,-50%);"], x, y);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var left;
|
|
51
|
+
var right;
|
|
52
|
+
var top;
|
|
53
|
+
var bottom;
|
|
54
|
+
var placements = placement.split('-');
|
|
55
|
+
placements.forEach(function (placement) {
|
|
56
|
+
switch (placement) {
|
|
57
|
+
case 'left':
|
|
58
|
+
left = x;
|
|
59
|
+
break;
|
|
60
|
+
|
|
61
|
+
case 'right':
|
|
62
|
+
right = x;
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
case 'top':
|
|
66
|
+
top = y;
|
|
67
|
+
break;
|
|
68
|
+
|
|
69
|
+
case 'bottom':
|
|
70
|
+
bottom = y;
|
|
71
|
+
break;
|
|
72
|
+
|
|
73
|
+
default:
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var isCenteredX = left === undefined && right === undefined;
|
|
78
|
+
var isCenteredY = top === undefined && bottom === undefined;
|
|
79
|
+
return css(["left:", ";right:", ";top:", ";bottom:", ";", " ", ""], left, right, top, bottom, isCenteredX && css(["left:calc(50% + ", ");transform:translateX(-50%);"], x), isCenteredY && css(["top:calc(50% - ", ");transform:translateY(-50%);"], y));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var PopupBaseRoot = /*#__PURE__*/styled.div.withConfig({
|
|
83
|
+
componentId: "plasma__sc-1md4coi-1"
|
|
84
|
+
})(["", " ", " ", ";"], function (_ref) {
|
|
85
|
+
var frame = _ref.frame;
|
|
86
|
+
return css(["position:", ";"], frame === 'document' ? 'fixed' : 'absolute');
|
|
87
|
+
}, function (_ref2) {
|
|
88
|
+
var zIndex = _ref2.zIndex;
|
|
89
|
+
return css(["z-index:", ";"], zIndex || DEFAULT_Z_INDEX);
|
|
90
|
+
}, function (_ref3) {
|
|
91
|
+
var placement = _ref3.placement,
|
|
92
|
+
offset = _ref3.offset;
|
|
93
|
+
return handlePosition(placement, offset);
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Базовый PopupBase.
|
|
97
|
+
* Управляет показом/скрытием и анимацией(?) высплывающего окна.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
export var PopupBase = function PopupBase(_ref4) {
|
|
101
|
+
var id = _ref4.id,
|
|
102
|
+
isOpen = _ref4.isOpen,
|
|
103
|
+
placement = _ref4.placement,
|
|
104
|
+
offset = _ref4.offset,
|
|
105
|
+
_ref4$frame = _ref4.frame,
|
|
106
|
+
frame = _ref4$frame === void 0 ? 'document' : _ref4$frame,
|
|
107
|
+
children = _ref4.children,
|
|
108
|
+
role = _ref4.role,
|
|
109
|
+
zIndex = _ref4.zIndex,
|
|
110
|
+
rest = _objectWithoutProperties(_ref4, _excluded);
|
|
111
|
+
|
|
112
|
+
var uniqId = useUniqId();
|
|
113
|
+
var innerId = id || uniqId;
|
|
114
|
+
var portalRef = useRef(null);
|
|
115
|
+
var controller = useContext(PopupBaseContext);
|
|
116
|
+
|
|
117
|
+
var _useState = useState(false),
|
|
118
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
119
|
+
forceRender = _useState2[1];
|
|
120
|
+
|
|
121
|
+
useEffect(function () {
|
|
122
|
+
var portal = document.getElementById(POPOVER_PORTAL_ID);
|
|
123
|
+
|
|
124
|
+
if (frame !== 'document' && frame && frame.current) {
|
|
125
|
+
portal = frame.current;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!portal) {
|
|
129
|
+
portal = document.createElement('div');
|
|
130
|
+
portal.setAttribute('id', POPOVER_PORTAL_ID);
|
|
131
|
+
document.body.appendChild(portal);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
portalRef.current = portal;
|
|
135
|
+
/**
|
|
136
|
+
* Изменение стейта нужно для того, чтобы PopupBase
|
|
137
|
+
* отобразился после записи DOM элемента в portalRef.current
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
forceRender(true);
|
|
141
|
+
return function () {
|
|
142
|
+
controller.unregister(innerId);
|
|
143
|
+
};
|
|
144
|
+
}, [controller, innerId, zIndex]);
|
|
145
|
+
|
|
146
|
+
if (isOpen) {
|
|
147
|
+
controller.register(innerId);
|
|
148
|
+
} else {
|
|
149
|
+
controller.unregister(innerId);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, portalRef.current && /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(PopupBaseRoot, {
|
|
154
|
+
placement: placement,
|
|
155
|
+
frame: frame,
|
|
156
|
+
offset: offset,
|
|
157
|
+
zIndex: zIndex
|
|
158
|
+
}, /*#__PURE__*/React.createElement(PopupBaseView, _extends({}, rest, {
|
|
159
|
+
role: role
|
|
160
|
+
}), children)), portalRef.current));
|
|
161
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
+
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
|
+
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
6
|
+
|
|
7
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
|
|
9
|
+
import React, { useEffect } from 'react';
|
|
10
|
+
/**
|
|
11
|
+
* Хранилище модальных окон.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
var PopupBaseController = /*#__PURE__*/function () {
|
|
15
|
+
function PopupBaseController() {
|
|
16
|
+
_classCallCheck(this, PopupBaseController);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "items", []);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
_createClass(PopupBaseController, [{
|
|
22
|
+
key: "register",
|
|
23
|
+
value: function register(id) {
|
|
24
|
+
return this.items.push(id);
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "unregister",
|
|
28
|
+
value: function unregister(id) {
|
|
29
|
+
this.items.splice(this.items.indexOf(id), 1);
|
|
30
|
+
}
|
|
31
|
+
}]);
|
|
32
|
+
|
|
33
|
+
return PopupBaseController;
|
|
34
|
+
}();
|
|
35
|
+
|
|
36
|
+
var controller = /*#__PURE__*/new PopupBaseController();
|
|
37
|
+
export var POPOVER_PORTAL_ID = 'plasma-popup-root';
|
|
38
|
+
export var PopupBaseContext = /*#__PURE__*/React.createContext(controller);
|
|
39
|
+
export var PopupBaseProvider = function PopupBaseProvider(_ref) {
|
|
40
|
+
var children = _ref.children;
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
return function () {
|
|
43
|
+
var portal = document.createElement('div');
|
|
44
|
+
|
|
45
|
+
if (portal && document.body.contains(portal)) {
|
|
46
|
+
document.body.removeChild(portal);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
return /*#__PURE__*/React.createElement(PopupBaseContext.Provider, {
|
|
51
|
+
value: controller
|
|
52
|
+
}, children);
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PopupBase } from './PopupBase';
|
package/es/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './components/Image';
|
|
|
8
8
|
export * from './components/Input';
|
|
9
9
|
export * from './components/PaginationDots';
|
|
10
10
|
export * from './components/Popup';
|
|
11
|
+
export * from './components/PopupBase';
|
|
11
12
|
export * from './components/Popover';
|
|
12
13
|
export * from './components/Price';
|
|
13
14
|
export * from './components/RadioGroup';
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './components/Image';
|
|
|
8
8
|
export * from './components/Input';
|
|
9
9
|
export * from './components/PaginationDots';
|
|
10
10
|
export * from './components/Popup';
|
|
11
|
+
export * from './components/PopupBase';
|
|
11
12
|
export * from './components/Popover';
|
|
12
13
|
export * from './components/Price';
|
|
13
14
|
export * from './components/RadioGroup';
|
package/index.js
CHANGED
|
@@ -134,6 +134,19 @@ Object.keys(_Popup).forEach(function (key) {
|
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
var _PopupBase = /*#__PURE__*/require("./components/PopupBase");
|
|
138
|
+
|
|
139
|
+
Object.keys(_PopupBase).forEach(function (key) {
|
|
140
|
+
if (key === "default" || key === "__esModule") return;
|
|
141
|
+
if (key in exports && exports[key] === _PopupBase[key]) return;
|
|
142
|
+
Object.defineProperty(exports, key, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function get() {
|
|
145
|
+
return _PopupBase[key];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
137
150
|
var _Popover = /*#__PURE__*/require("./components/Popover");
|
|
138
151
|
|
|
139
152
|
Object.keys(_Popover).forEach(function (key) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salutejs/plasma-core",
|
|
3
|
-
"version": "1.133.
|
|
3
|
+
"version": "1.133.1-dev.0",
|
|
4
4
|
"description": "Core library for Plasma: Salute Design System",
|
|
5
5
|
"author": "Salute Frontend Team <salute.developers@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"react-draggable": "4.4.3",
|
|
82
82
|
"react-popper": "2.3.0"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "bbfffa12145d1810e6f4eba6b0093aa85e7cc0da"
|
|
85
85
|
}
|