feat: add host actions visibility control in KefuChatShell

This commit is contained in:
mlogclub
2026-04-24 22:40:34 +08:00
parent 1db5c3bf39
commit 14f220619f
2 changed files with 32 additions and 22 deletions
+8
View File
@@ -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)}
+2
View File
@@ -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
} }