跳至主要内容

主題

透過 theme prop 客製化聊天機器人的外觀。預設主題中的每一個顏色、 間距、圓角都可以被覆寫。

預設主題

目前主題設定

{}
聊天機器人載入中…
提示

試試看 Crazy preset,一次看到所有主題 slot 的效果。

程式範例

import { Chatbot } from "@asgard-js/react";
import type { AsgardThemeContextValue } from "@asgard-js/react";

const myTheme: Partial<AsgardThemeContextValue> = {
chatbot: {
backgroundColor: "#3c1d3b",
borderColor: "#92ff8c",
primaryComponent: {
mainColor: "#ff0000",
secondaryColor: "#aba400",
},
},
botMessage: {
color: "#00f0ff",
backgroundColor: "#ff7a00",
},
userMessage: {
color: "#522801",
backgroundColor: "#060081",
},
};

<Chatbot theme={myTheme} {...rest} />;

Theme 結構

層級欄位說明
chatbotbackgroundColor, borderColor, borderRadius外框樣式
chatbotcontentMaxWidth, width, height尺寸控制
chatbotmainColor, secondaryColor, inactiveColor全域色彩
chatbot.primaryComponentmainColor, secondaryColor主要互動元素色彩
chatbot.headerstyle, title.style, actionButton.styleHeader 樣式
chatbot.bodystyle訊息區域樣式
chatbot.footerstyle, textArea.style, submitButton.style, speechInputButton.style輸入區域樣式
botMessagecolor, backgroundColor, linkColor, quickReplyBackgroundColorBot 訊息氣泡
userMessagecolor, backgroundColor使用者訊息氣泡
templatequickReplies.style, references.style, time.style模板元素樣式
顏色會擴散到整個對話介面(0.3.x)

以下三個 chatbot 顏色會連動到 SDK 的 --asg-color-* design token,因此只要設定它們,連新版介面(執行指示器、輸入框、對話標題列、工具呼叫群組、思考區塊、任務/子代理面板)也會一起套色:

  • chatbot.primaryComponent.mainColor--asg-color-primary(+自動推導的深色 hover)
  • chatbot.backgroundColor--asg-color-bg / --asg-color-surface
  • chatbot.borderColor--asg-color-border / --asg-color-divider

只有在提供具體色碼#rrggbb,或非 var() 的邊框色)時才會注入,否則沿用內建預設。