feat: add host actions visibility control in KefuChatShell
This commit is contained in:
@@ -29,6 +29,7 @@ export function KefuChatShell() {
|
|||||||
const [isMaximized, setIsMaximized] = useState(false)
|
const [isMaximized, setIsMaximized] = useState(false)
|
||||||
const [isCloseDialogOpen, setIsCloseDialogOpen] = useState(false)
|
const [isCloseDialogOpen, setIsCloseDialogOpen] = useState(false)
|
||||||
const [isClosingConversation, setIsClosingConversation] = useState(false)
|
const [isClosingConversation, setIsClosingConversation] = useState(false)
|
||||||
|
const [showHostActions, setShowHostActions] = useState(false)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
title,
|
title,
|
||||||
@@ -95,6 +96,9 @@ export function KefuChatShell() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return bindKefuHostBridge({
|
return bindKefuHostBridge({
|
||||||
|
onInit: () => {
|
||||||
|
setShowHostActions(true)
|
||||||
|
},
|
||||||
onOpen: () => {
|
onOpen: () => {
|
||||||
setIsOpen(true)
|
setIsOpen(true)
|
||||||
setIsVisible(true)
|
setIsVisible(true)
|
||||||
@@ -214,6 +218,7 @@ export function KefuChatShell() {
|
|||||||
>
|
>
|
||||||
<RotateCwIcon className="size-3.75 transition duration-200 group-hover:rotate-[-20deg]" />
|
<RotateCwIcon className="size-3.75 transition duration-200 group-hover:rotate-[-20deg]" />
|
||||||
</button>
|
</button>
|
||||||
|
{showHostActions ? (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleMinimize}
|
onClick={handleMinimize}
|
||||||
@@ -223,6 +228,8 @@ export function KefuChatShell() {
|
|||||||
>
|
>
|
||||||
<MinusIcon className="size-3.75 transition duration-200 group-hover:scale-x-[0.88]" />
|
<MinusIcon className="size-3.75 transition duration-200 group-hover:scale-x-[0.88]" />
|
||||||
</button>
|
</button>
|
||||||
|
) : null}
|
||||||
|
{showHostActions ? (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleToggleMaximize}
|
onClick={handleToggleMaximize}
|
||||||
@@ -236,6 +243,7 @@ export function KefuChatShell() {
|
|||||||
<Maximize2Icon className="size-3.75 transition duration-200 group-hover:scale-[1.04]" />
|
<Maximize2Icon className="size-3.75 transition duration-200 group-hover:scale-[1.04]" />
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
) : null}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setIsCloseDialogOpen(true)}
|
onClick={() => setIsCloseDialogOpen(true)}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
} from "@/lib/kefu-widget-config"
|
} from "@/lib/kefu-widget-config"
|
||||||
|
|
||||||
type HostBridgeOptions = {
|
type HostBridgeOptions = {
|
||||||
|
onInit?: () => void
|
||||||
onOpen?: () => void
|
onOpen?: () => void
|
||||||
onMinimize?: () => void
|
onMinimize?: () => void
|
||||||
onMaximizedChange?: (isMaximized: boolean) => void
|
onMaximizedChange?: (isMaximized: boolean) => void
|
||||||
@@ -40,6 +41,7 @@ export function bindKefuHostBridge(options: HostBridgeOptions = {}) {
|
|||||||
|
|
||||||
if (data.type === INIT_MESSAGE_TYPE && data.payload) {
|
if (data.type === INIT_MESSAGE_TYPE && data.payload) {
|
||||||
setKefuWidgetConfig(data.payload as KefuWidgetHostConfig)
|
setKefuWidgetConfig(data.payload as KefuWidgetHostConfig)
|
||||||
|
options.onInit?.()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user