Skip to content

Commit f30cacf

Browse files
Merge branch 'master' into feat/htmlpanel
2 parents 359bb0f + 6cbdc0b commit f30cacf

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.1.8-beta.0
2+
3+
- Add `show` prop to `Popup`, that allows you to specify whether the popup should be shown or hidden.
4+
15
## v0.1.7-beta.0
26

37
- Add `<HtmlPanel>` component

lib/ui/Popup.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import { useMethod, useConversation, useUIBox, useMountBox } from "../hooks";
99
import { EventListeners } from "../EventListeners";
1010
import { UIBoxProps } from "../types";
1111
import { BoxContext } from "../MountedBox";
12+
import { useEffect } from "react";
1213

1314
type PopupProps = UIBoxProps<Talk.Popup> &
1415
Talk.PopupOptions & {
1516
highlightedWords?: Parameters<Talk.Popup["setHighlightedWords"]>[0];
1617
popupRef?: React.MutableRefObject<Talk.Popup | undefined>;
18+
show?: boolean;
1719
children?: React.ReactNode;
1820
};
1921

@@ -39,6 +41,7 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
3941
conversationId,
4042
syncConversation,
4143
asGuest,
44+
show,
4245
popupRef,
4346
children,
4447
...optionsAndEvents
@@ -53,7 +56,20 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
5356
useMethod(box, presence, "setPresence");
5457
useMethod(box, highlightedWords, "setHighlightedWords");
5558
useConversation(session, box, syncConversation, conversationId, asGuest);
56-
useMountBox(box, undefined);
59+
const mounted = useMountBox(box, {show: show ?? true});
60+
61+
useEffect(() => {
62+
if(show === undefined || !mounted) {
63+
return;
64+
}
65+
66+
if(show) {
67+
box?.show();
68+
} else {
69+
box?.hide();
70+
}
71+
72+
}, [show, mounted, box])
5773

5874
return (
5975
<BoxContext.Provider value={box}>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"url": "https://github.com/talkjs/talkjs-react/issues"
2929
},
3030
"homepage": "https://talkjs.com",
31-
"version": "0.1.7-beta.0",
31+
"version": "0.1.8-beta.0",
3232
"type": "module",
3333
"files": [
3434
"dist"

0 commit comments

Comments
 (0)