@@ -2,20 +2,36 @@ import type { PropsWithChildren } from 'react';
22import React , { useCallback } from 'react' ;
33import { useDialogIsOpen , useOpenedDialogCount } from './hooks' ;
44import { Portal } from '../Portal/Portal' ;
5- import { useDialogManager } from '../../context' ;
5+ import { useDialogManager , useNearestDialogManagerContext } from '../../context' ;
66
77export const DialogPortalDestination = ( ) => {
8- const { dialogManager } = useDialogManager ( ) ;
9- const openedDialogCount = useOpenedDialogCount ( ) ;
8+ const { dialogManager } = useNearestDialogManagerContext ( ) ?? { } ;
9+ const openedDialogCount = useOpenedDialogCount ( { dialogManagerId : dialogManager ?. id } ) ;
10+ // const [destinationRoot, setDestinationRoot] = useState<HTMLDivElement | null>(null);
11+
12+ // todo: allow to configure and then enable
13+ // useEffect(() => {
14+ // if (!destinationRoot) return;
15+ // const handleClickOutside = (event: MouseEvent) => {
16+ // if (!destinationRoot?.contains(event.target as Node)) {
17+ // dialogManager?.closeAll();
18+ // }
19+ // };
20+ // document.addEventListener('click', handleClickOutside, { capture: true });
21+ // return () => {
22+ // document.removeEventListener('click', handleClickOutside, { capture: true });
23+ // };
24+ // }, [destinationRoot, dialogManager]);
1025
1126 if ( ! openedDialogCount ) return null ;
1227
1328 return (
1429 < div
1530 className = 'str-chat__dialog-overlay'
16- data-str-chat__portal-id = { dialogManager . id }
31+ data-str-chat__portal-id = { dialogManager ? .id }
1732 data-testid = 'str-chat__dialog-overlay'
18- onClick = { ( ) => dialogManager . closeAll ( ) }
33+ onClick = { ( ) => dialogManager ?. closeAll ( ) }
34+ // ref={setDestinationRoot}
1935 style = {
2036 {
2137 '--str-chat__dialog-overlay-height' : openedDialogCount > 0 ? '100%' : '0' ,
@@ -27,14 +43,16 @@ export const DialogPortalDestination = () => {
2743
2844type DialogPortalEntryProps = {
2945 dialogId : string ;
46+ dialogManagerId ?: string ;
3047} ;
3148
3249export const DialogPortalEntry = ( {
3350 children,
3451 dialogId,
52+ dialogManagerId,
3553} : PropsWithChildren < DialogPortalEntryProps > ) => {
36- const { dialogManager } = useDialogManager ( { dialogId } ) ;
37- const dialogIsOpen = useDialogIsOpen ( dialogId , dialogManager . id ) ;
54+ const { dialogManager } = useDialogManager ( { dialogId, dialogManagerId } ) ;
55+ const dialogIsOpen = useDialogIsOpen ( dialogId , dialogManagerId ) ;
3856
3957 const getPortalDestination = useCallback (
4058 ( ) => document . querySelector ( `div[data-str-chat__portal-id="${ dialogManager . id } "]` ) ,
0 commit comments