From 9cefd1456534b498cc97a34d69fc79bf11e71986 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Wed, 8 Feb 2023 17:27:10 +0800 Subject: [PATCH] feat: add theme color param to widget --- public/locales/en/setting.json | 1 + public/locales/zh/setting.json | 1 + public/widget.js | 5 +++-- src/index-widget.tsx | 3 ++- src/routes/setting/Widget.tsx | 6 +++++- src/widget/Popup/Header.tsx | 5 +++-- src/widget/Popup/index.tsx | 5 +++-- src/widget/index.tsx | 7 ++++--- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/public/locales/en/setting.json b/public/locales/en/setting.json index e48a123d..8b2c96f5 100644 --- a/public/locales/en/setting.json +++ b/public/locales/en/setting.json @@ -195,6 +195,7 @@ "default_value": "Default Value", "remark": "Remarks", "param_host": "Assign the user chatting with visitor(User ID)", + "param_theme_color": "The theme color of widget", "param_close_width": "The width while widget closed", "param_close_height": "The height while widget closed", "param_open_width": "The width while widget opened", diff --git a/public/locales/zh/setting.json b/public/locales/zh/setting.json index 0d141ff2..acd22320 100644 --- a/public/locales/zh/setting.json +++ b/public/locales/zh/setting.json @@ -190,6 +190,7 @@ "default_value": "默认值", "remark": "备注", "param_host": "指定和谁聊天(用户ID)", + "param_theme_color": "挂件的主题色", "param_close_width": "挂件关闭态的宽度", "param_close_height": "挂件关闭态的高度", "param_open_width": "挂件打开态的宽度", diff --git a/public/widget.js b/public/widget.js index 5a2dd871..44f391e5 100644 --- a/public/widget.js +++ b/public/widget.js @@ -3,7 +3,8 @@ const { closeWidth = 48, closeHeight = 48, openWidth = 380, - openHeight = 680 + openHeight = 680, + themeColor = "#1fe1f9" } = document.currentScript.dataset; const _src = document.currentScript.src; const wrapper = document.createElement("iframe"); @@ -17,7 +18,7 @@ const styles = { boxShadow: `rgb(0 0 0 / 25%) 0px 25px 50px -12px` }; Object.assign(wrapper.style, styles); -wrapper.src = `${new URL(_src).origin}/widget.html?host=${hostId}`; +wrapper.src = `${new URL(_src).origin}/widget.html?host=${hostId}&themeColor=${themeColor}`; wrapper.width = closeWidth; wrapper.height = closeHeight; wrapper.frameborder = 0; diff --git a/src/index-widget.tsx b/src/index-widget.tsx index 5c77c5c2..ae2a47eb 100644 --- a/src/index-widget.tsx +++ b/src/index-widget.tsx @@ -8,8 +8,9 @@ import './i18n'; const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement); const hostId = new URLSearchParams(location.search).get("host"); +const themeColor = new URLSearchParams(location.search).get("themeColor") || "#1fe1f9"; root.render( hostId ? - + : null ); diff --git a/src/routes/setting/Widget.tsx b/src/routes/setting/Widget.tsx index de5b54b7..d3129c5b 100644 --- a/src/routes/setting/Widget.tsx +++ b/src/routes/setting/Widget.tsx @@ -29,7 +29,7 @@ export default function Widget() { {t('code')}: - {`\n