-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathDialogPortal.tsx
More file actions
46 lines (40 loc) · 1.27 KB
/
DialogPortal.tsx
File metadata and controls
46 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { PropsWithChildren, useCallback } from 'react';
import { useDialogIsOpen, useOpenedDialogCount } from './hooks';
import { Portal } from '../Portal/Portal';
import { useDialogManager } from '../../context';
export const DialogPortalDestination = () => {
const { dialogManager } = useDialogManager();
const openedDialogCount = useOpenedDialogCount();
return (
<div
className='str-chat__dialog-overlay'
data-str-chat__portal-id={dialogManager.id}
data-testid='str-chat__dialog-overlay'
onClick={() => dialogManager.closeAll()}
style={
{
'--str-chat__dialog-overlay-height': openedDialogCount > 0 ? '100%' : '0',
} as React.CSSProperties
}
/>
);
};
type DialogPortalEntryProps = {
dialogId: string;
};
export const DialogPortalEntry = ({
children,
dialogId,
}: PropsWithChildren<DialogPortalEntryProps>) => {
const { dialogManager } = useDialogManager();
const dialogIsOpen = useDialogIsOpen(dialogId);
const getPortalDestination = useCallback(
() => document.querySelector(`div[data-str-chat__portal-id="${dialogManager.id}"]`),
[dialogManager.id],
);
return (
<Portal getPortalDestination={getPortalDestination} isOpen={dialogIsOpen}>
{children}
</Portal>
);
};