Skip to content

Commit

Permalink
feat(LayerManager): add type to layer (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
n-parpibaeva authored Sep 19, 2023
1 parent bafed78 commit 3fb7de9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function Modal({
onOutsideClick,
onClose,
contentRefs: [contentRef],
type: 'modal',
});

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function Popup({
onClose,
contentRefs: [anchorRef, containerRef],
enabled: !disableLayer,
type: 'popup',
});

const {attributes, styles, setPopperRef, setArrowRef} = usePopper({
Expand Down
9 changes: 9 additions & 0 deletions src/components/utils/LayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand All @@ -69,7 +74,11 @@ class LayerManager {
componentId: 'LayerManager',
eventId: 'layerschange',
meta: {
/**
* @deprecated use layers
*/
layersCount: this.getLayersCount(),
layers: this.getLayers(),
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/utils/useLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function useLayer({
onClose,
contentRefs,
enabled = true,
type,
}: LayerProps) {
const layerConfigRef = React.useRef<LayerConfig>({
disableEscapeKeyDown,
Expand All @@ -29,6 +30,7 @@ export function useLayer({
onOutsideClick,
onClose,
contentRefs,
type,
});

React.useEffect(() => {
Expand Down

0 comments on commit 3fb7de9

Please sign in to comment.