@@ -4,11 +4,13 @@ import { getKeyForObject, splitObjectByPrefix } from "../util";
44import { useMethod , useConversation , useUIBox , useMountBox } from "../hooks" ;
55import { EventListeners } from "../EventListeners" ;
66import { UIBoxProps } from "../types" ;
7+ import { useEffect } from "react" ;
78
89type PopupProps = UIBoxProps < Talk . Popup > &
910 Talk . PopupOptions & {
1011 highlightedWords ?: Parameters < Talk . Popup [ "setHighlightedWords" ] > [ 0 ] ;
1112 popupRef ?: React . MutableRefObject < Talk . Popup | undefined > ;
13+ show ?: boolean ;
1214 } ;
1315
1416export function Popup ( props : PopupProps ) {
@@ -27,6 +29,7 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
2729 conversationId,
2830 syncConversation,
2931 asGuest,
32+ show,
3033 popupRef,
3134 ...optionsAndEvents
3235 } = props ;
@@ -40,7 +43,20 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
4043 useMethod ( box , presence , "setPresence" ) ;
4144 useMethod ( box , highlightedWords , "setHighlightedWords" ) ;
4245 useConversation ( session , box , syncConversation , conversationId , asGuest ) ;
43- useMountBox ( box , undefined ) ;
46+ const mounted = useMountBox ( box , { show : show ?? true } ) ;
47+
48+ useEffect ( ( ) => {
49+ if ( show === undefined || ! mounted ) {
50+ return ;
51+ }
52+
53+ if ( show ) {
54+ box ?. show ( ) ;
55+ } else {
56+ box ?. hide ( ) ;
57+ }
58+
59+ } , [ show , mounted , box ] )
4460
4561 return < EventListeners target = { box } handlers = { events } /> ;
4662}
0 commit comments