From 97154dbc93ebbd3d8844220151a0112c46fec737 Mon Sep 17 00:00:00 2001 From: dromerolovo Date: Mon, 24 Jun 2024 11:50:33 -0500 Subject: [PATCH] apply theme to new components --- .../components/app/overview/embedded/index.tsx | 8 ++++---- web/app/components/base/chat/chat/chat-input.tsx | 15 +++++++++++++++ web/app/components/base/chat/chat/index.tsx | 5 +++++ web/app/components/base/chat/chat/question.tsx | 15 ++++++++++++--- .../base/chat/embedded-chatbot/chat-wrapper.tsx | 2 ++ .../chat/embedded-chatbot/config-panel/index.tsx | 7 +++++++ .../base/chat/embedded-chatbot/context.tsx | 3 +++ .../base/chat/embedded-chatbot/header.tsx | 10 +++++++--- .../base/chat/embedded-chatbot/index.tsx | 6 ++++++ 9 files changed, 61 insertions(+), 10 deletions(-) diff --git a/web/app/components/app/overview/embedded/index.tsx b/web/app/components/app/overview/embedded/index.tsx index f7bb1c00f518ae..a28d8d922f0ab7 100644 --- a/web/app/components/app/overview/embedded/index.tsx +++ b/web/app/components/app/overview/embedded/index.tsx @@ -74,8 +74,8 @@ const Embedded = ({ siteInfo, isShow, onClose, appBaseUrl, accessToken, classNam const [isCopied, setIsCopied] = useState({ iframe: false, scripts: false, chromePlugin: false }) const { langeniusVersionInfo } = useAppContext() - const themeContext = useThemeContext() - themeContext.buildTheme(siteInfo?.chat_color_theme ?? '#1C64F2', siteInfo?.chat_color_theme_inverted ?? false) + const themeBuilder = useThemeContext() + themeBuilder.buildTheme(siteInfo?.chat_color_theme ?? '#1C64F2', siteInfo?.chat_color_theme_inverted ?? false) const isTestEnv = langeniusVersionInfo.current_env === 'TESTING' || langeniusVersionInfo.current_env === 'DEVELOPMENT' const onClickCopy = () => { if (option === 'chromePlugin') { @@ -84,7 +84,7 @@ const Embedded = ({ siteInfo, isShow, onClose, appBaseUrl, accessToken, classNam copy(splitUrl[1]) } else { - copy(OPTION_MAP[option].getContent(appBaseUrl, accessToken, themeContext.theme?.primaryColor ?? '#1C64F2', isTestEnv)) + copy(OPTION_MAP[option].getContent(appBaseUrl, accessToken, themeBuilder.theme?.primaryColor ?? '#1C64F2', isTestEnv)) } setIsCopied({ ...isCopied, [option]: true }) } @@ -164,7 +164,7 @@ const Embedded = ({ siteInfo, isShow, onClose, appBaseUrl, accessToken, classNam
-
{OPTION_MAP[option].getContent(appBaseUrl, accessToken, themeContext.theme?.primaryColor ?? '#1C64F2', isTestEnv)}
+
{OPTION_MAP[option].getContent(appBaseUrl, accessToken, themeBuilder.theme?.primaryColor ?? '#1C64F2', isTestEnv)}
diff --git a/web/app/components/base/chat/chat/chat-input.tsx b/web/app/components/base/chat/chat/chat-input.tsx index 17e316062d0f67..e83d579b25fa52 100644 --- a/web/app/components/base/chat/chat/chat-input.tsx +++ b/web/app/components/base/chat/chat/chat-input.tsx @@ -30,16 +30,20 @@ import { useDraggableUploader, useImageFiles, } from '@/app/components/base/image-uploader/hooks' +import { ThemeBuilder } from '../embedded-chatbot/theme/theme-context' +import { CssTransform } from '../embedded-chatbot/theme/utils' type ChatInputProps = { visionConfig?: VisionConfig speechToTextConfig?: EnableType onSend?: OnSend + themeBuilder: ThemeBuilder | null } const ChatInput: FC = ({ visionConfig, speechToTextConfig, onSend, + themeBuilder, }) => { const { appData } = useChatWithHistoryContext() const { t } = useTranslation() @@ -112,14 +116,25 @@ const ChatInput: FC = ({ }) } + const [isActiveIconFocused, setActiveIconFocused] = useState(false) + const media = useBreakpoints() const isMobile = media === MediaType.mobile + const sendIconThemeStyle = themeBuilder?.theme + ? { + color: (isActiveIconFocused || query || (query.trim() !== '')) ? themeBuilder.theme.primaryColor : '#d1d5db', + } + : {} const sendBtn = (
setActiveIconFocused(true)} + onMouseLeave={() => setActiveIconFocused(false)} onClick={handleSend} + style={isActiveIconFocused ? CssTransform(themeBuilder?.theme?.chatBubbleColorStyle ?? '') : {}} > = ({ appData, @@ -85,6 +87,7 @@ const Chat: FC = ({ chatAnswerContainerInner, hideProcessDetail, hideLogModal, + themeBuilder }) => { const { t } = useTranslation() const { currentLogItem, setCurrentLogItem, showPromptLogModal, setShowPromptLogModal, showAgentLogModal, setShowAgentLogModal } = useAppStore(useShallow(state => ({ @@ -221,6 +224,7 @@ const Chat: FC = ({ key={item.id} item={item} questionIcon={questionIcon} + theme={themeBuilder?.theme} /> ) }) @@ -262,6 +266,7 @@ const Chat: FC = ({ visionConfig={config?.file_upload?.image} speechToTextConfig={config?.speech_to_text} onSend={onSend} + themeBuilder={themeBuilder} /> ) } diff --git a/web/app/components/base/chat/chat/question.tsx b/web/app/components/base/chat/chat/question.tsx index f8eaad1ce6328e..584b750d8d8b5d 100644 --- a/web/app/components/base/chat/chat/question.tsx +++ b/web/app/components/base/chat/chat/question.tsx @@ -10,14 +10,18 @@ import { QuestionTriangle } from '@/app/components/base/icons/src/vender/solid/g import { User } from '@/app/components/base/icons/src/public/avatar' import { Markdown } from '@/app/components/base/markdown' import ImageGallery from '@/app/components/base/image-gallery' +import { Theme } from '../embedded-chatbot/theme/theme-context' +import { CssTransform } from '../embedded-chatbot/theme/utils' type QuestionProps = { item: ChatItem questionIcon?: ReactNode + theme: Theme | null | undefined } const Question: FC = ({ item, questionIcon, + theme, }) => { const { content, @@ -25,12 +29,17 @@ const Question: FC = ({ } = item const imgSrcs = message_files?.length ? message_files.map(item => item.url) : [] - return (
- -
+ +
{ !!imgSrcs.length && ( diff --git a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx index 41dcbb8eb18303..6b895ae319666d 100644 --- a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx +++ b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx @@ -32,6 +32,7 @@ const ChatWrapper = () => { appMeta, handleFeedback, currentChatInstanceRef, + themeBuilder, } = useEmbeddedChatbotContext() const appConfig = useMemo(() => { const config = appParams || {} @@ -130,6 +131,7 @@ const ChatWrapper = () => { suggestedQuestions={suggestedQuestions} answerIcon={isDify() ? : null} hideProcessDetail + themeBuilder={themeBuilder} /> ) } diff --git a/web/app/components/base/chat/embedded-chatbot/config-panel/index.tsx b/web/app/components/base/chat/embedded-chatbot/config-panel/index.tsx index 59ca2bbea26035..f58b1505f2df07 100644 --- a/web/app/components/base/chat/embedded-chatbot/config-panel/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/config-panel/index.tsx @@ -9,6 +9,8 @@ import { MessageDotsCircle } from '@/app/components/base/icons/src/vender/solid/ import { Edit02 } from '@/app/components/base/icons/src/vender/line/general' import { Star06 } from '@/app/components/base/icons/src/vender/solid/shapes' import LogoSite from '@/app/components/base/logo/logo-site' +import { useThemeContext } from '../theme/theme-context' +import { CssTransform } from '../theme/utils' const ConfigPanel = () => { const { t } = useTranslation() @@ -22,6 +24,7 @@ const ConfigPanel = () => { const [collapsed, setCollapsed] = useState(true) const customConfig = appData?.custom_config const site = appData?.site + const themeBuilder = useThemeContext() return (
@@ -34,6 +37,7 @@ const ConfigPanel = () => { )} >
{ {t('share.chat.configStatusDes')}