From 3fb7de912e144a84a0d169b0be65e6e440c886a0 Mon Sep 17 00:00:00 2001 From: Parpibaeva Nadezhda <27774197+n-parpibaeva@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:12:09 +0200 Subject: [PATCH] feat(LayerManager): add type to layer (#1018) --- src/components/Modal/Modal.tsx | 1 + src/components/Popup/Popup.tsx | 1 + src/components/utils/LayerManager.ts | 9 +++++++++ src/components/utils/useLayer.ts | 2 ++ 4 files changed, 13 insertions(+) diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index f5c46f344c..f490b4a86c 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -95,6 +95,7 @@ export function Modal({ onOutsideClick, onClose, contentRefs: [contentRef], + type: 'modal', }); return ( diff --git a/src/components/Popup/Popup.tsx b/src/components/Popup/Popup.tsx index ea4707fb9d..cac5a944df 100644 --- a/src/components/Popup/Popup.tsx +++ b/src/components/Popup/Popup.tsx @@ -92,6 +92,7 @@ export function Popup({ onClose, contentRefs: [anchorRef, containerRef], enabled: !disableLayer, + type: 'popup', }); const {attributes, styles, setPopperRef, setArrowRef} = usePopper({ diff --git a/src/components/utils/LayerManager.ts b/src/components/utils/LayerManager.ts index e8abfd4038..2e0d276c67 100644 --- a/src/components/utils/LayerManager.ts +++ b/src/components/utils/LayerManager.ts @@ -13,6 +13,7 @@ export interface LayerExtendableProps { onEnterKeyDown?: (event: KeyboardEvent) => void; onOutsideClick?: (event: MouseEvent) => void; onClose?: (event: MouseEvent | KeyboardEvent, reason: LayerCloseReason) => void; + type?: string; } export type ContentElement = @@ -52,6 +53,10 @@ class LayerManager { return this.stack.length; } + getLayers() { + return this.stack.map(({type}) => ({type})); + } + private addListeners() { document.addEventListener('keydown', this.handleDocumentKeyDown); document.addEventListener('click', this.handleDocumentClick, true); @@ -69,7 +74,11 @@ class LayerManager { componentId: 'LayerManager', eventId: 'layerschange', meta: { + /** + * @deprecated use layers + */ layersCount: this.getLayersCount(), + layers: this.getLayers(), }, }); } diff --git a/src/components/utils/useLayer.ts b/src/components/utils/useLayer.ts index 3e0748298d..a107b61b8d 100644 --- a/src/components/utils/useLayer.ts +++ b/src/components/utils/useLayer.ts @@ -20,6 +20,7 @@ export function useLayer({ onClose, contentRefs, enabled = true, + type, }: LayerProps) { const layerConfigRef = React.useRef({ disableEscapeKeyDown, @@ -29,6 +30,7 @@ export function useLayer({ onOutsideClick, onClose, contentRefs, + type, }); React.useEffect(() => {