@salutejs/plasma-core 1.135.0-dev.0 → 1.135.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/api/plasma-core.api.md +72 -9
  3. package/components/ModalBase/ModalBase.d.ts +2 -37
  4. package/components/ModalBase/ModalBase.js +48 -98
  5. package/components/ModalBase/ModalBaseContext.d.ts +3 -2
  6. package/components/ModalBase/ModalBaseContext.js +22 -8
  7. package/components/ModalBase/ModalOverlay.d.ts +14 -0
  8. package/components/ModalBase/ModalOverlay.js +108 -0
  9. package/components/ModalBase/hooks.d.ts +5 -0
  10. package/components/ModalBase/hooks.js +69 -0
  11. package/components/ModalBase/index.d.ts +3 -1
  12. package/components/ModalBase/index.js +23 -1
  13. package/components/ModalBase/types.d.ts +42 -0
  14. package/components/ModalBase/types.js +5 -0
  15. package/components/PopupBase/PopupBase.d.ts +2 -36
  16. package/components/PopupBase/PopupBase.js +53 -127
  17. package/components/PopupBase/PopupBaseContext.d.ts +1 -9
  18. package/components/PopupBase/PopupBaseContext.js +2 -2
  19. package/components/PopupBase/PopupBaseRoot.d.ts +9 -0
  20. package/components/PopupBase/PopupBaseRoot.js +109 -0
  21. package/components/PopupBase/hooks.d.ts +7 -0
  22. package/components/PopupBase/hooks.js +105 -0
  23. package/components/PopupBase/index.d.ts +3 -2
  24. package/components/PopupBase/index.js +29 -1
  25. package/components/PopupBase/types.d.ts +62 -0
  26. package/components/PopupBase/types.js +5 -0
  27. package/components/PopupBase/utils.d.ts +1 -0
  28. package/components/PopupBase/utils.js +72 -0
  29. package/es/components/ModalBase/ModalBase.js +45 -89
  30. package/es/components/ModalBase/ModalBaseContext.js +17 -6
  31. package/es/components/ModalBase/ModalOverlay.js +82 -0
  32. package/es/components/ModalBase/hooks.js +55 -0
  33. package/es/components/ModalBase/index.js +3 -1
  34. package/es/components/ModalBase/types.js +2 -0
  35. package/es/components/PopupBase/PopupBase.js +52 -127
  36. package/es/components/PopupBase/PopupBaseContext.js +2 -2
  37. package/es/components/PopupBase/PopupBaseRoot.js +83 -0
  38. package/es/components/PopupBase/hooks.js +89 -0
  39. package/es/components/PopupBase/index.js +3 -1
  40. package/es/components/PopupBase/types.js +1 -0
  41. package/es/components/PopupBase/utils.js +62 -0
  42. package/package.json +2 -2
  43. package/temp/plasma-core.api.md +1501 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ # v1.135.0 (Thu Oct 19 2023)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - Release 19.10.2023 [#815](https://github.com/salute-developers/plasma/pull/815) ([@Yeti-or](https://github.com/Yeti-or) [@kayman233](https://github.com/kayman233) [@TitanKuzmich](https://github.com/TitanKuzmich) [@Yakutoc](https://github.com/Yakutoc) nikita.belyanskiy@south.rt.ru [@neretin-trike](https://github.com/neretin-trike))
6
+ - feat(plasma-core): animation with other API ([@kayman233](https://github.com/kayman233))
7
+ - feat(plasma-ui): add placement for Confirm ([@kayman233](https://github.com/kayman233))
8
+ - feat(plasma-new-hope/b2c/web/core): Add Popover to new hope ([@TitanKuzmich](https://github.com/TitanKuzmich))
9
+
10
+ #### 🐛 Bug Fix
11
+
12
+ - fix(plasma-core, plasma-ui): remove withAnimation from PopupBase ([@kayman233](https://github.com/kayman233))
13
+ - fix(plasma-core, plasma-ui): minor refactoring and types fix ([@kayman233](https://github.com/kayman233))
14
+ - feat(plasma-core, plasma-ui): add animation for PopupBase etc ([@kayman233](https://github.com/kayman233))
15
+ - docs(plasma-core/hope/web/b2c): generate new api ([@TitanKuzmich](https://github.com/TitanKuzmich))
16
+ - docs: generate new api for plasma-core ([@TitanKuzmich](https://github.com/TitanKuzmich))
17
+ - fix(plasma-web-docs): Make button blur prop deprecated ([@TitanKuzmich](https://github.com/TitanKuzmich))
18
+ - fix(plasma-core): refactor in PopupBase/ModalBase ([@kayman233](https://github.com/kayman233))
19
+ - feat(plasma-core, plasma-web, plasma-b2c): ModalBase component ([@kayman233](https://github.com/kayman233))
20
+
21
+ #### Authors: 6
22
+
23
+ - [@kayman233](https://github.com/kayman233)
24
+ - Alex Czech ([@Yakutoc](https://github.com/Yakutoc))
25
+ - Krivonos Aleksandr ([@TitanKuzmich](https://github.com/TitanKuzmich))
26
+ - neretinaa ([@neretin-trike](https://github.com/neretin-trike))
27
+ - Nikita Belyanskiy (nikita.belyanskiy@south.rt.ru)
28
+ - Vasiliy ([@Yeti-or](https://github.com/Yeti-or))
29
+
30
+ ---
31
+
1
32
  # v1.134.0 (Fri Sep 29 2023)
2
33
 
3
34
  #### 🚀 Enhancement
@@ -14,6 +14,7 @@ import { Context } from 'react';
14
14
  import { CSSObject } from 'styled-components';
15
15
  import { CSSProperties } from 'react';
16
16
  import { DefaultTheme } from 'styled-components';
17
+ import { Dispatch } from 'react';
17
18
  import { DraggableData } from 'react-draggable';
18
19
  import { FC } from 'react';
19
20
  import { FlattenInterpolation } from 'styled-components';
@@ -25,6 +26,7 @@ import { MutableRefObject } from 'react';
25
26
  import { default as React_2 } from 'react';
26
27
  import { ReactNode } from 'react';
27
28
  import { RefObject } from 'react';
29
+ import { SetStateAction } from 'react';
28
30
  import { spacing } from '@salutejs/plasma-typo';
29
31
  import { SpacingProps } from '@salutejs/plasma-typo';
30
32
  import { SpacingProps as SpacingProps_2 } from '@salutejs/plasma-typo/lib/cjs/mixins/applySpacing';
@@ -754,21 +756,36 @@ export interface MaxLinesProps {
754
756
  maxLines?: number;
755
757
  }
756
758
 
759
+ // @public (undocumented)
760
+ export type ModalAnimationInfo = PopupAnimationInfo;
761
+
757
762
  // @public
758
763
  export const ModalBase: FC<ModalBaseProps>;
759
764
 
760
765
  // @public (undocumented)
761
- export interface ModalBaseProps extends Omit<PopupBaseProps, 'frame'> {
766
+ export const modalBaseOverlayClass = "modal-base-overlay";
767
+
768
+ // @public (undocumented)
769
+ export interface ModalBaseProps extends PopupBaseProps {
762
770
  closeOnEsc?: boolean;
763
771
  closeOnOverlayClick?: boolean;
764
- focusAfterRef?: React_2.RefObject<HTMLElement>;
765
- initialFocusRef?: React_2.RefObject<HTMLElement>;
772
+ focusAfterRef?: React.RefObject<HTMLElement>;
773
+ initialFocusRef?: React.RefObject<HTMLElement>;
766
774
  onClose?: () => void;
767
775
  onEscKeyDown?: (event: KeyboardEvent) => void;
768
- onOverlayClick?: (event: React_2.MouseEvent<HTMLDivElement>) => void;
776
+ onOverlayClick?: (event: React.MouseEvent<HTMLDivElement>) => void;
769
777
  withBlur?: boolean;
770
778
  }
771
779
 
780
+ // @public (undocumented)
781
+ export type ModalBaseRootProps = PopupRootProps & Pick<ModalBaseProps, 'initialFocusRef' | 'focusAfterRef' | 'onClose'>;
782
+
783
+ // @public
784
+ export const ModalOverlay: FC<ModalOverlayProps>;
785
+
786
+ // @public (undocumented)
787
+ export type ModalOverlayProps = Pick<PopupRootProps, 'id' | 'animationInfo' | 'zIndex'> & Pick<ModalBaseProps, 'withBlur' | 'closeOnOverlayClick' | 'onOverlayClick' | 'onClose'>;
788
+
772
789
  // @public (undocumented)
773
790
  export const monthLongName: (val: number) => string;
774
791
 
@@ -835,6 +852,18 @@ export interface PinProps {
835
852
  // @public @deprecated
836
853
  export const Popup: React_2.NamedExoticComponent<PopupProps & React_2.RefAttributes<HTMLDivElement>>;
837
854
 
855
+ // @public (undocumented)
856
+ export interface PopupAnimationInfo {
857
+ // (undocumented)
858
+ endAnimation: boolean;
859
+ // (undocumented)
860
+ endTransition: boolean;
861
+ // (undocumented)
862
+ setEndAnimation: React.Dispatch<React.SetStateAction<boolean>>;
863
+ // (undocumented)
864
+ setEndTransition: React.Dispatch<React.SetStateAction<boolean>>;
865
+ }
866
+
838
867
  // @public
839
868
  export const PopupBase: React_2.ForwardRefExoticComponent<PopupBaseProps & React_2.RefAttributes<HTMLDivElement>>;
840
869
 
@@ -845,13 +874,14 @@ export const PopupBase: React_2.ForwardRefExoticComponent<PopupBaseProps & React
845
874
  export type PopupBasePlacement = BasicPopupBasePlacement | MixedPopupBasePlacement;
846
875
 
847
876
  // @public (undocumented)
848
- export interface PopupBaseProps extends React_2.HTMLAttributes<HTMLDivElement> {
849
- children?: React_2.ReactNode;
850
- frame?: 'document' | React_2.RefObject<HTMLElement>;
877
+ export interface PopupBaseProps extends React.HTMLAttributes<HTMLDivElement> {
878
+ animationInfo?: PopupAnimationInfo;
879
+ children?: React.ReactNode;
880
+ frame?: 'document' | React.RefObject<HTMLElement>;
851
881
  isOpen: boolean;
852
882
  // (undocumented)
853
- offset?: [number | string, number | string];
854
- overlay?: React_2.ReactNode;
883
+ offset?: [number, number] | [string, string];
884
+ overlay?: React.ReactNode;
855
885
  // (undocumented)
856
886
  placement?: PopupBasePlacement;
857
887
  popupInfo?: PopupInfo;
@@ -863,6 +893,12 @@ export const PopupBaseProvider: React_2.FC<{
863
893
  children: ReactNode;
864
894
  }>;
865
895
 
896
+ // @public
897
+ export const PopupBaseRoot: React_2.ForwardRefExoticComponent<PopupRootProps & React_2.RefAttributes<HTMLDivElement>>;
898
+
899
+ // @public (undocumented)
900
+ export const popupBaseRootClass = "popup-base-root";
901
+
866
902
  // @public (undocumented)
867
903
  export interface PopupContextType {
868
904
  // (undocumented)
@@ -893,6 +929,14 @@ export interface PopupProps extends HTMLAttributes<HTMLDivElement> {
893
929
  trigger: 'hover' | 'click';
894
930
  }
895
931
 
932
+ // @public (undocumented)
933
+ export interface PopupRootProps extends Omit<PopupBaseProps, 'isOpen' | 'overlay'> {
934
+ // (undocumented)
935
+ id: string;
936
+ // (undocumented)
937
+ setVisible: React.Dispatch<React.SetStateAction<boolean>>;
938
+ }
939
+
896
940
  // @public
897
941
  export const Price: React_2.FC<PriceProps>;
898
942
 
@@ -1318,6 +1362,13 @@ export const useForkRef: UseForkRefHook;
1318
1362
  // @public
1319
1363
  export const useIsomorphicLayoutEffect: typeof useEffect;
1320
1364
 
1365
+ // Warning: (ae-forgotten-export) The symbol "ModalHookArgs" needs to be exported by the entry point index.d.ts
1366
+ //
1367
+ // @public (undocumented)
1368
+ export const useModal: ({ id, popupInfo, onEscKeyDown, onClose, closeOnEsc }: ModalHookArgs) => {
1369
+ modalInfo: ModalInfo;
1370
+ };
1371
+
1321
1372
  // @public (undocumented)
1322
1373
  export const usePaginationDots: ({ items, index, visibleItems }: SmartPaginationDotsProps) => {
1323
1374
  sliced: {
@@ -1326,6 +1377,17 @@ export const usePaginationDots: ({ items, index, visibleItems }: SmartPagination
1326
1377
  activeId: string | number;
1327
1378
  };
1328
1379
 
1380
+ // Warning: (ae-forgotten-export) The symbol "PopupHookArgs" needs to be exported by the entry point index.d.ts
1381
+ //
1382
+ // @public (undocumented)
1383
+ export const usePopup: ({ isOpen, id, popupInfo, animationInfo }: PopupHookArgs) => {
1384
+ isVisible: boolean;
1385
+ setVisible: Dispatch<SetStateAction<boolean>>;
1386
+ };
1387
+
1388
+ // @public (undocumented)
1389
+ export const usePopupAnimation: () => PopupAnimationInfo;
1390
+
1329
1391
  // @public (undocumented)
1330
1392
  export const usePopupBaseContext: () => PopupContextType;
1331
1393
 
@@ -1430,6 +1492,7 @@ export interface WithSkeletonProps {
1430
1492
 
1431
1493
  // Warnings were encountered during analysis:
1432
1494
  //
1495
+ // components/ModalBase/hooks.d.ts:4:5 - (ae-forgotten-export) The symbol "ModalInfo" needs to be exported by the entry point index.d.ts
1433
1496
  // components/Toast/Toast.d.ts:4:5 - (ae-forgotten-export) The symbol "ToastRole" needs to be exported by the entry point index.d.ts
1434
1497
  // components/Toast/useToast.d.ts:2:5 - (ae-forgotten-export) The symbol "ShowToast" needs to be exported by the entry point index.d.ts
1435
1498
 
@@ -1,40 +1,5 @@
1
- import React, { FC } from 'react';
2
- import { PopupBaseProps } from '../PopupBase/PopupBase';
3
- export interface ModalBaseProps extends Omit<PopupBaseProps, 'frame'> {
4
- /**
5
- * Нужно ли применять blur для подложки.
6
- */
7
- withBlur?: boolean;
8
- /**
9
- * Закрывать модальное окно при нажатии на ESC(по умолчанию true).
10
- */
11
- closeOnEsc?: boolean;
12
- /**
13
- * Закрывать модальное окно при нажатии вне области модального окна(по умолчанию true),
14
- */
15
- closeOnOverlayClick?: boolean;
16
- /**
17
- * Обработчик клика при нажатии на ESC(если не передан, то при нажатии используется onClose).
18
- */
19
- onEscKeyDown?: (event: KeyboardEvent) => void;
20
- /**
21
- * Обработчик клика при нажатии вне области модального окна(если не передан, то при нажатии используется onClose).
22
- */
23
- onOverlayClick?: (event: React.MouseEvent<HTMLDivElement>) => void;
24
- /**
25
- * Первый элемент для фокуса внутри модального окна.
26
- */
27
- initialFocusRef?: React.RefObject<HTMLElement>;
28
- /**
29
- * Элемент для фокуса после закрытия модального окна
30
- * (по умолчанию фокус на последнем перед открытием активном элементе).
31
- */
32
- focusAfterRef?: React.RefObject<HTMLElement>;
33
- /**
34
- * Общий обработчик клика по кнопке "закрыть".
35
- */
36
- onClose?: () => void;
37
- }
1
+ import { FC } from 'react';
2
+ import { ModalBaseProps } from './types';
38
3
  /**
39
4
  * ModalBase.
40
5
  * Управляет показом/скрытием, подложкой и анимацией визуальной части модального окна.
@@ -1,33 +1,29 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.ModalBase = void 0;
9
7
 
10
- var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
8
+ var _react = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react"));
9
+
10
+ var _styledComponents = /*#__PURE__*/require("styled-components");
11
11
 
12
- var _styledComponents = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("styled-components"));
12
+ var _PopupBase = /*#__PURE__*/require("../PopupBase/PopupBase");
13
13
 
14
14
  var _hooks = /*#__PURE__*/require("../../hooks");
15
15
 
16
- var _PopupBaseContext = /*#__PURE__*/require("../PopupBase/PopupBaseContext");
16
+ var _ModalOverlay = /*#__PURE__*/require("./ModalOverlay");
17
17
 
18
- var _PopupBase = /*#__PURE__*/require("../PopupBase/PopupBase");
19
-
20
- var _ModalBaseContext = /*#__PURE__*/require("./ModalBaseContext");
18
+ var _hooks2 = /*#__PURE__*/require("./hooks");
21
19
 
22
20
  var _collectPackageInfo = /*#__PURE__*/require("../../collectPackageInfo");
23
21
 
24
22
  var _NoScroll;
25
23
 
26
- var _excluded = ["id", "isOpen", "placement", "onClose", "onOverlayClick", "onEscKeyDown", "closeOnEsc", "closeOnOverlayClick", "withBlur", "initialFocusRef", "focusAfterRef", "children"];
27
-
28
- 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); }
24
+ var _excluded = ["id", "animationInfo", "onClose", "onOverlayClick", "onEscKeyDown", "closeOnEsc", "closeOnOverlayClick", "withBlur", "initialFocusRef", "focusAfterRef", "zIndex", "popupInfo", "children"];
29
25
 
30
- 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; }
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
27
 
32
28
  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); }
33
29
 
@@ -36,105 +32,59 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
36
32
  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; }
37
33
 
38
34
  (0, _collectPackageInfo.collectPackageInfo)('ModalBase/ModalBase');
39
-
40
- // TODO: новый отдельный оверлей #778
41
- var StyledOverlay = /*#__PURE__*/_styledComponents["default"].div.withConfig({
42
- componentId: "plasma__sc-urf4on-0"
43
- })(["position:absolute;width:100%;height:100%;top:0;left:0;", " ", ";background-color:", ";backdrop-filter:var(--backdrop-filter);cursor:", ";"], function (_ref) {
44
- var zIndex = _ref.zIndex;
45
- return (0, _styledComponents.css)(["z-index:", ";"], zIndex || _PopupBase.DEFAULT_Z_INDEX);
46
- }, function (_ref2) {
47
- var $withBlur = _ref2.$withBlur;
48
- return (0, _styledComponents.css)(["--background-color:", ";--backdrop-filter:", ";"], $withBlur ? 'var(--plasma-modal-blur-overlay-color)' : 'var(--plasma-modal-overlay-color)', $withBlur ? 'blur(1rem)' : 'none');
49
- }, function (_ref3) {
50
- var transparent = _ref3.transparent;
51
- return transparent ? 'transparent' : 'var(--background-color)';
52
- }, function (_ref4) {
53
- var clickable = _ref4.clickable;
54
- return clickable ? 'pointer' : 'default';
55
- });
56
-
57
35
  var NoScroll = /*#__PURE__*/(0, _styledComponents.createGlobalStyle)(["body{overflow-y:hidden;}"]);
58
- var ESCAPE_KEYCODE = 27;
59
36
  /**
60
37
  * ModalBase.
61
38
  * Управляет показом/скрытием, подложкой и анимацией визуальной части модального окна.
62
39
  */
63
40
 
64
- var ModalBase = function ModalBase(_ref5) {
65
- var id = _ref5.id,
66
- isOpen = _ref5.isOpen,
67
- placement = _ref5.placement,
68
- onClose = _ref5.onClose,
69
- onOverlayClick = _ref5.onOverlayClick,
70
- onEscKeyDown = _ref5.onEscKeyDown,
71
- _ref5$closeOnEsc = _ref5.closeOnEsc,
72
- closeOnEsc = _ref5$closeOnEsc === void 0 ? true : _ref5$closeOnEsc,
73
- _ref5$closeOnOverlayC = _ref5.closeOnOverlayClick,
74
- closeOnOverlayClick = _ref5$closeOnOverlayC === void 0 ? true : _ref5$closeOnOverlayC,
75
- withBlur = _ref5.withBlur,
76
- initialFocusRef = _ref5.initialFocusRef,
77
- focusAfterRef = _ref5.focusAfterRef,
78
- children = _ref5.children,
79
- rest = _objectWithoutProperties(_ref5, _excluded);
41
+ var ModalBase = function ModalBase(_ref) {
42
+ var id = _ref.id,
43
+ animationInfo = _ref.animationInfo,
44
+ onClose = _ref.onClose,
45
+ onOverlayClick = _ref.onOverlayClick,
46
+ onEscKeyDown = _ref.onEscKeyDown,
47
+ _ref$closeOnEsc = _ref.closeOnEsc,
48
+ closeOnEsc = _ref$closeOnEsc === void 0 ? true : _ref$closeOnEsc,
49
+ _ref$closeOnOverlayCl = _ref.closeOnOverlayClick,
50
+ closeOnOverlayClick = _ref$closeOnOverlayCl === void 0 ? true : _ref$closeOnOverlayCl,
51
+ withBlur = _ref.withBlur,
52
+ initialFocusRef = _ref.initialFocusRef,
53
+ focusAfterRef = _ref.focusAfterRef,
54
+ zIndex = _ref.zIndex,
55
+ popupInfo = _ref.popupInfo,
56
+ children = _ref.children,
57
+ rest = _objectWithoutProperties(_ref, _excluded);
80
58
 
59
+ var trapRef = (0, _hooks.useFocusTrap)(true, initialFocusRef, focusAfterRef);
81
60
  var uniqId = (0, _hooks.useUniqId)();
82
61
  var innerId = id || uniqId;
83
- var popupController = (0, _PopupBaseContext.usePopupBaseContext)();
84
- var trapRef = (0, _hooks.useFocusTrap)(true, initialFocusRef, focusAfterRef);
85
- var onOverlayKeyDown = (0, _react.useCallback)(function (event) {
86
- if (!closeOnOverlayClick) {
87
- return;
88
- }
89
-
90
- if (onOverlayClick) {
91
- onOverlayClick(event);
92
- return;
93
- }
94
-
95
- if (onClose) {
96
- onClose();
97
- }
98
- }, [closeOnOverlayClick, onOverlayClick, onClose]); // При ESC закрывает текущее окно, если это возможно
99
-
100
- var onKeyDown = (0, _react.useCallback)(function (event) {
101
- if (closeOnEsc && event.keyCode === ESCAPE_KEYCODE && (0, _ModalBaseContext.getIdLastModal)(popupController.items) === innerId) {
102
- if (onEscKeyDown) {
103
- onEscKeyDown(event);
104
- return;
105
- }
106
-
107
- if (onClose) {
108
- onClose();
109
- }
110
- }
111
- }, [onClose, onEscKeyDown, popupController, closeOnEsc]);
112
- (0, _react.useEffect)(function () {
113
- window.addEventListener('keydown', onKeyDown);
114
- return function () {
115
- window.removeEventListener('keydown', onKeyDown);
116
- };
117
- }, [onClose, onEscKeyDown, popupController, closeOnEsc]);
118
- var modalInfo = {
119
- id: innerId,
120
- info: {
121
- isModal: true
122
- }
123
- };
124
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, _NoScroll || (_NoScroll = /*#__PURE__*/_react["default"].createElement(NoScroll, null)), /*#__PURE__*/_react["default"].createElement(_PopupBase.PopupBase, _extends({
62
+
63
+ var _useModal = (0, _hooks2.useModal)({
125
64
  id: innerId,
126
- frame: "document",
127
- isOpen: isOpen,
128
- placement: placement,
65
+ closeOnEsc: closeOnEsc,
66
+ onEscKeyDown: onEscKeyDown,
67
+ onClose: onClose,
68
+ popupInfo: popupInfo
69
+ }),
70
+ modalInfo = _useModal.modalInfo;
71
+
72
+ return /*#__PURE__*/_react["default"].createElement(_PopupBase.PopupBase, _extends({
73
+ id: id,
129
74
  ref: trapRef,
130
75
  popupInfo: modalInfo,
131
- overlay: /*#__PURE__*/_react["default"].createElement(StyledOverlay, {
132
- transparent: (0, _ModalBaseContext.getIdLastModal)(popupController.items) !== innerId,
133
- clickable: closeOnOverlayClick,
134
- onClick: onOverlayKeyDown,
135
- $withBlur: withBlur
76
+ animationInfo: animationInfo,
77
+ zIndex: zIndex,
78
+ overlay: /*#__PURE__*/_react["default"].createElement(_ModalOverlay.ModalOverlay, {
79
+ id: innerId,
80
+ withBlur: withBlur,
81
+ onOverlayClick: onOverlayClick,
82
+ onClose: onClose,
83
+ animationInfo: animationInfo,
84
+ zIndex: zIndex,
85
+ closeOnOverlayClick: closeOnOverlayClick
136
86
  })
137
- }, rest), children));
87
+ }, rest), _NoScroll || (_NoScroll = /*#__PURE__*/_react["default"].createElement(NoScroll, null)), children);
138
88
  };
139
89
 
140
90
  exports.ModalBase = ModalBase;
@@ -1,8 +1,9 @@
1
- import { PopupInfo } from '../PopupBase/PopupBaseContext';
1
+ import { PopupInfo } from '../PopupBase';
2
2
  export interface ModalInfo extends PopupInfo {
3
3
  id: string;
4
4
  info?: {
5
5
  isModal?: true;
6
6
  };
7
7
  }
8
- export declare const getIdLastModal: (items: ModalInfo[]) => string;
8
+ export declare const getIdLastModal: (items: ModalInfo[]) => string | undefined;
9
+ export declare const getIdFirstModal: (items: ModalInfo[]) => string | undefined;
@@ -3,25 +3,39 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getIdLastModal = void 0;
6
+ exports.getIdFirstModal = exports.getIdLastModal = void 0;
7
7
 
8
8
  /**
9
9
  * Взаимодействие с модальными оконами.
10
10
  */
11
- var getLastModal = function getLastModal(items) {
12
- var modals = items.filter(function (item) {
11
+ var getModals = function getModals(items) {
12
+ return items.filter(function (item) {
13
13
  var _item$info;
14
14
 
15
15
  return item === null || item === void 0 ? void 0 : (_item$info = item.info) === null || _item$info === void 0 ? void 0 : _item$info.isModal;
16
16
  });
17
- var lastModal = modals && modals[modals.length - 1];
18
- return lastModal;
19
17
  };
20
18
 
21
19
  var getIdLastModal = function getIdLastModal(items) {
22
- var _getLastModal;
20
+ var modals = getModals(items);
23
21
 
24
- return (_getLastModal = getLastModal(items)) === null || _getLastModal === void 0 ? void 0 : _getLastModal.id;
22
+ if (!modals.length) {
23
+ return;
24
+ }
25
+
26
+ return modals[modals.length - 1].id;
27
+ };
28
+
29
+ exports.getIdLastModal = getIdLastModal;
30
+
31
+ var getIdFirstModal = function getIdFirstModal(items) {
32
+ var modals = getModals(items);
33
+
34
+ if (!modals.length) {
35
+ return;
36
+ }
37
+
38
+ return modals[0].id;
25
39
  };
26
40
 
27
- exports.getIdLastModal = getIdLastModal;
41
+ exports.getIdFirstModal = getIdFirstModal;
@@ -0,0 +1,14 @@
1
+ import { FC } from 'react';
2
+ import { ModalOverlayProps } from './types';
3
+ export declare const modalBaseOverlayClass = "modal-base-overlay";
4
+ export declare const Overlay: import("styled-components").StyledComponent<"div", any, {
5
+ transparent?: boolean | undefined;
6
+ endAnimation?: boolean | undefined;
7
+ $withBlur?: boolean | undefined;
8
+ clickable?: boolean | undefined;
9
+ zIndex?: string | undefined;
10
+ }, never>;
11
+ /**
12
+ * ModalOverlay - подложка для ModalBase.
13
+ */
14
+ export declare const ModalOverlay: FC<ModalOverlayProps>;
@@ -0,0 +1,108 @@
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.ModalOverlay = exports.Overlay = exports.modalBaseOverlayClass = void 0;
9
+
10
+ var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
11
+
12
+ var _styledComponents = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("styled-components"));
13
+
14
+ var _PopupBaseRoot = /*#__PURE__*/require("../PopupBase/PopupBaseRoot");
15
+
16
+ var _PopupBase = /*#__PURE__*/require("../PopupBase");
17
+
18
+ var _ModalBaseContext = /*#__PURE__*/require("./ModalBaseContext");
19
+
20
+ var _collectPackageInfo = /*#__PURE__*/require("../../collectPackageInfo");
21
+
22
+ var _excluded = ["id", "withBlur", "onOverlayClick", "onClose", "animationInfo", "zIndex", "closeOnOverlayClick"];
23
+
24
+ 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); }
25
+
26
+ 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; }
27
+
28
+ 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); }
29
+
30
+ 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; }
31
+
32
+ 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; }
33
+
34
+ (0, _collectPackageInfo.collectPackageInfo)('ModalBase/ModalOverlay');
35
+
36
+ /*
37
+ * Класс компонента ModalBaseOverlay: `modal-base-overlay`
38
+ */
39
+ var modalBaseOverlayClass = 'modal-base-overlay'; // TODO: новый отдельный оверлей #778
40
+
41
+ exports.modalBaseOverlayClass = modalBaseOverlayClass;
42
+
43
+ var Overlay = /*#__PURE__*/_styledComponents["default"].div.withConfig({
44
+ componentId: "plasma__sc-1jo935d-0"
45
+ })(["position:fixed;width:100%;height:100%;top:0;left:0;", " ", ";background-color:", ";backdrop-filter:var(--backdrop-filter);cursor:", ";"], function (_ref) {
46
+ var zIndex = _ref.zIndex;
47
+ return (0, _styledComponents.css)(["z-index:", ";"], zIndex || _PopupBaseRoot.DEFAULT_Z_INDEX);
48
+ }, function (_ref2) {
49
+ var $withBlur = _ref2.$withBlur;
50
+ return (0, _styledComponents.css)(["--background-color:", ";--backdrop-filter:", ";"], $withBlur ? 'var(--plasma-modal-blur-overlay-color)' : 'var(--plasma-modal-overlay-color)', $withBlur ? 'blur(1rem)' : 'none');
51
+ }, function (_ref3) {
52
+ var transparent = _ref3.transparent;
53
+ return transparent ? 'transparent' : 'var(--background-color)';
54
+ }, function (_ref4) {
55
+ var clickable = _ref4.clickable;
56
+ return clickable ? 'pointer' : 'default';
57
+ });
58
+ /**
59
+ * ModalOverlay - подложка для ModalBase.
60
+ */
61
+
62
+
63
+ exports.Overlay = Overlay;
64
+
65
+ var ModalOverlay = function ModalOverlay(_ref5) {
66
+ var id = _ref5.id,
67
+ withBlur = _ref5.withBlur,
68
+ onOverlayClick = _ref5.onOverlayClick,
69
+ onClose = _ref5.onClose,
70
+ animationInfo = _ref5.animationInfo,
71
+ zIndex = _ref5.zIndex,
72
+ _ref5$closeOnOverlayC = _ref5.closeOnOverlayClick,
73
+ closeOnOverlayClick = _ref5$closeOnOverlayC === void 0 ? true : _ref5$closeOnOverlayC,
74
+ rest = _objectWithoutProperties(_ref5, _excluded);
75
+
76
+ var popupController = (0, _PopupBase.usePopupBaseContext)();
77
+ var onModalOverlayKeyDown = (0, _react.useCallback)(function (event) {
78
+ if (!closeOnOverlayClick) {
79
+ return;
80
+ }
81
+
82
+ if (onOverlayClick) {
83
+ onOverlayClick(event);
84
+ return;
85
+ }
86
+
87
+ if (onClose) {
88
+ onClose();
89
+ }
90
+ }, [closeOnOverlayClick, onOverlayClick, onClose]);
91
+ var transparent = (0, _react.useMemo)(function () {
92
+ return (0, _ModalBaseContext.getIdLastModal)(popupController.items) !== id;
93
+ }, [id, popupController.items]);
94
+ var endAnimation = (0, _react.useMemo)(function () {
95
+ return (0, _ModalBaseContext.getIdFirstModal)(popupController.items) === id && (animationInfo === null || animationInfo === void 0 ? void 0 : animationInfo.endAnimation);
96
+ }, [id, popupController.items]);
97
+ return /*#__PURE__*/_react["default"].createElement(Overlay, _extends({
98
+ className: modalBaseOverlayClass,
99
+ transparent: transparent,
100
+ clickable: closeOnOverlayClick,
101
+ endAnimation: endAnimation,
102
+ onClick: onModalOverlayKeyDown,
103
+ zIndex: zIndex,
104
+ $withBlur: withBlur
105
+ }, rest));
106
+ };
107
+
108
+ exports.ModalOverlay = ModalOverlay;
@@ -0,0 +1,5 @@
1
+ import { ModalInfo } from './ModalBaseContext';
2
+ import { ModalHookArgs } from './types';
3
+ export declare const useModal: ({ id, popupInfo, onEscKeyDown, onClose, closeOnEsc }: ModalHookArgs) => {
4
+ modalInfo: ModalInfo;
5
+ };