Skip to content

Commit 99e1568

Browse files
authored
feat(web): add dark mode support (#891) (#900)
1 parent bf9c907 commit 99e1568

File tree

35 files changed

+1041
-92
lines changed

35 files changed

+1041
-92
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ docs/.vitepress/.temp
3030
.idea/
3131

3232
update-changelog.sh
33-
runtimes/nodejs-esm
33+
runtimes/nodejs-esm
34+
yarn.lock

web/public/locales/en/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
"Back": "Return",
268268
"Personal Access Token": "Personal Access Token",
269269
"SwitchLanguage": "Switch Language",
270+
"SwitchColorMode": "Switch ColorMode",
270271
"Storage": "Storage",
271272
"upload example": "file upload",
272273
"Unit": {

web/public/locales/zh-CN/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
"Back": "返回",
268268
"Personal Access Token": "访问凭证 (PAT)",
269269
"SwitchLanguage": "切换语言",
270+
"SwitchColorMode": "切换颜色模式",
270271
"Storage": "云存储",
271272
"upload example": "文件上传示例",
272273
"Unit": {

web/public/locales/zh/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
"Back": "返回",
268268
"Personal Access Token": "访问凭证 (PAT)",
269269
"SwitchLanguage": "切换语言",
270+
"SwitchColorMode": "切换颜色模式",
270271
"Storage": "云存储",
271272
"upload example": "文件上传示例",
272273
"Unit": {

web/src/App.css

+15-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
width: 4px;
1212
height: 6px;
1313
}
14+
1415
/* 滚动槽 */
1516
::-webkit-scrollbar-track {
1617
border-radius: 2px;
1718
}
19+
1820
/* 滚动条滑块 */
1921
::-webkit-scrollbar-thumb {
2022
border-radius: 4px;
@@ -26,15 +28,24 @@ body {
2628
height: 100%;
2729
}
2830

31+
/* oevrrides chakra default value */
2932
body {
30-
background-color: #f1f3f5 !important;
31-
background-image: url("/bg.png") !important;
3233
background-repeat: no-repeat !important;
3334
background-size: cover !important;
3435
background-position: center !important;
3536
font-size: 12px;
3637
}
3738

39+
[data-theme=light] body {
40+
background-color: #f1f3f5 !important;
41+
background-image: url("/bg.png") !important;
42+
}
43+
44+
[data-theme=dark] ::-webkit-scrollbar-thumb {
45+
/* 滚动条滑块 */
46+
background: rgba(21, 22, 26, 0.4);
47+
}
48+
3849
a {
3950
color: inherit;
4051
text-decoration: none;
@@ -48,8 +59,9 @@ a {
4859
html {
4960
color-scheme: dark;
5061
}
62+
5163
body {
5264
color: white;
5365
background: black;
5466
}
55-
}
67+
}

web/src/App.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect, useState } from "react";
12
import { useTranslation } from "react-i18next";
23
import { BrowserRouter, useRoutes } from "react-router-dom";
34
import { ChakraProvider } from "@chakra-ui/react";
@@ -7,6 +8,7 @@ import { ClickToComponent } from "click-to-react-component";
78
import "@/utils/i18n";
89

910
import theme from "./chakraTheme";
11+
import darkTheme from "./chakraThemeDark";
1012
import routes from "./routes";
1113

1214
import "./App.css";
@@ -30,11 +32,23 @@ const queryClient = new QueryClient({
3032
function APP() {
3133
useTranslation();
3234

35+
const [colorMode, setColorMode] = useState(localStorage.getItem("chakra-ui-color-mode"));
36+
useEffect(() => {
37+
function onColorModeChange() {
38+
const colorMode = localStorage.getItem("chakra-ui-color-mode");
39+
setColorMode(colorMode);
40+
}
41+
window.addEventListener("ColorModeChange", onColorModeChange);
42+
return () => {
43+
window.removeEventListener("ColorModeChange", onColorModeChange);
44+
};
45+
});
46+
3347
return (
3448
<>
3549
<QueryClientProvider client={queryClient}>
3650
{process.env.NODE_ENV === "development" ? <ClickToComponent /> : null}
37-
<ChakraProvider theme={theme}>
51+
<ChakraProvider theme={colorMode === "light" ? theme : darkTheme}>
3852
<BrowserRouter>
3953
<RouteElement />
4054
</BrowserRouter>

web/src/chakraTheme.ts

+3
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ const Menu = {
323323
};
324324

325325
const theme = extendTheme({
326+
initialColorMode: "dark", // 'dark | 'light'
327+
useSystemColorMode: false,
326328
fontSizes: {
327329
sm: "12px",
328330
base: "12px",
@@ -424,4 +426,5 @@ const theme = extendTheme({
424426
Menu,
425427
},
426428
});
429+
427430
export default theme;

0 commit comments

Comments
 (0)