From 3e78eb391eda4cb8607b8e3d56b110ed7feac4f8 Mon Sep 17 00:00:00 2001 From: Irene Ryu Date: Tue, 27 Feb 2024 19:45:15 +0900 Subject: [PATCH] feat: add renderWidgetToggleButton prop --- src/App.tsx | 6 +++++ src/components/ChatAiWidget.tsx | 40 +++++++++++++++++---------------- 2 files changed, 27 insertions(+), 19 deletions(-) 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 && )} ); };