diff --git a/src/App.tsx b/src/App.tsx index f13ea4750..4842a352e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,11 @@ interface Props extends Partial { botId?: string; hashedKey?: string; autoOpen?: boolean; + renderWidgetToggleButton?: (props: { + onClick: () => void; + accentColor: string; + isOpen: boolean; + }) => React.ReactElement; } const App = (props: Props) => { @@ -33,6 +38,7 @@ const App = (props: Props) => { enableMention={props.enableMention} customUserAgentParam={props.customUserAgentParam} autoOpen={props.autoOpen} + renderWidgetToggleButton={props.renderWidgetToggleButton} /> ); }; diff --git a/src/components/ChatAiWidget.tsx b/src/components/ChatAiWidget.tsx index c815fc916..8386bd345 100644 --- a/src/components/ChatAiWidget.tsx +++ b/src/components/ChatAiWidget.tsx @@ -1,5 +1,4 @@ import '@sendbird/uikit-react/dist/index.css'; -import '../css/index.css'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { useEffect, useRef, useState } from 'react'; import styled, { css } from 'styled-components'; @@ -101,22 +100,17 @@ const StyledArrowIcon = styled.span<{ isOpen: boolean }>` `; }} `; -export interface Props extends Partial { - applicationId: string; - botId: string; - hashedKey?: string; - autoOpen?: boolean; -} +interface ToggleButtonProps { + onClick: () => void; + accentColor: string; + isOpen: boolean; +} const WidgetToggleButton = ({ onClick, accentColor, isOpen, -}: { - onClick: () => void; - accentColor: string; - isOpen: boolean; -}) => { +}: ToggleButtonProps) => { return ( { + applicationId: string; + botId: string; + hashedKey?: string; + autoOpen?: boolean; + renderWidgetToggleButton?: (props: ToggleButtonProps) => React.ReactElement; +} + const Component = (props: Props) => { const { isFetching, ...channelStyle } = useChannelStyle({ appId: props.applicationId, @@ -164,6 +166,11 @@ const Component = (props: Props) => { } }, [channelStyle.autoOpen, props.autoOpen]); + const toggleButtonProps = { + onClick: buttonClickHandler, + accentColor: channelStyle.accentColor, + isOpen, + }; return isMobile && isOpen ? ( @@ -171,13 +178,8 @@ const Component = (props: Props) => { ) : ( <> - {!isFetching && ( - - )} + {props.renderWidgetToggleButton?.(toggleButtonProps) || + (!isFetching && )} ); };