Skip to content

Commit 6cbdc0b

Browse files
Merge pull request #10 from talkjs/feat/popup-show
Add 'show' and 'showOnMount' props to Popup component
2 parents 5963043 + 934788e commit 6cbdc0b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

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

37
- Add `asGuest?: boolean` prop to `Chatbox`, `Inbox` and `Popup`

lib/ui/Popup.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { getKeyForObject, splitObjectByPrefix } from "../util";
44
import { useMethod, useConversation, useUIBox, useMountBox } from "../hooks";
55
import { EventListeners } from "../EventListeners";
66
import { UIBoxProps } from "../types";
7+
import { useEffect } from "react";
78

89
type 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

1416
export 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
}

package.json

Lines changed: 1 addition & 1 deletion
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.6",
31+
"version": "0.1.7",
3232
"type": "module",
3333
"files": [
3434
"dist"

0 commit comments

Comments
 (0)