Skip to content

Commit

Permalink
feat(web): add dark mode support (#891) (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
genie88 authored Mar 15, 2023
1 parent bf9c907 commit 99e1568
Show file tree
Hide file tree
Showing 35 changed files with 1,041 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ docs/.vitepress/.temp
.idea/

update-changelog.sh
runtimes/nodejs-esm
runtimes/nodejs-esm
yarn.lock
1 change: 1 addition & 0 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"Back": "Return",
"Personal Access Token": "Personal Access Token",
"SwitchLanguage": "Switch Language",
"SwitchColorMode": "Switch ColorMode",
"Storage": "Storage",
"upload example": "file upload",
"Unit": {
Expand Down
1 change: 1 addition & 0 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"Back": "返回",
"Personal Access Token": "访问凭证 (PAT)",
"SwitchLanguage": "切换语言",
"SwitchColorMode": "切换颜色模式",
"Storage": "云存储",
"upload example": "文件上传示例",
"Unit": {
Expand Down
1 change: 1 addition & 0 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"Back": "返回",
"Personal Access Token": "访问凭证 (PAT)",
"SwitchLanguage": "切换语言",
"SwitchColorMode": "切换颜色模式",
"Storage": "云存储",
"upload example": "文件上传示例",
"Unit": {
Expand Down
18 changes: 15 additions & 3 deletions web/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
width: 4px;
height: 6px;
}

/* 滚动槽 */
::-webkit-scrollbar-track {
border-radius: 2px;
}

/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
border-radius: 4px;
Expand All @@ -26,15 +28,24 @@ body {
height: 100%;
}

/* oevrrides chakra default value */
body {
background-color: #f1f3f5 !important;
background-image: url("/bg.png") !important;
background-repeat: no-repeat !important;
background-size: cover !important;
background-position: center !important;
font-size: 12px;
}

[data-theme=light] body {
background-color: #f1f3f5 !important;
background-image: url("/bg.png") !important;
}

[data-theme=dark] ::-webkit-scrollbar-thumb {
/* 滚动条滑块 */
background: rgba(21, 22, 26, 0.4);
}

a {
color: inherit;
text-decoration: none;
Expand All @@ -48,8 +59,9 @@ a {
html {
color-scheme: dark;
}

body {
color: white;
background: black;
}
}
}
16 changes: 15 additions & 1 deletion web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { BrowserRouter, useRoutes } from "react-router-dom";
import { ChakraProvider } from "@chakra-ui/react";
Expand All @@ -7,6 +8,7 @@ import { ClickToComponent } from "click-to-react-component";
import "@/utils/i18n";

import theme from "./chakraTheme";
import darkTheme from "./chakraThemeDark";
import routes from "./routes";

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

const [colorMode, setColorMode] = useState(localStorage.getItem("chakra-ui-color-mode"));
useEffect(() => {
function onColorModeChange() {
const colorMode = localStorage.getItem("chakra-ui-color-mode");
setColorMode(colorMode);
}
window.addEventListener("ColorModeChange", onColorModeChange);
return () => {
window.removeEventListener("ColorModeChange", onColorModeChange);
};
});

return (
<>
<QueryClientProvider client={queryClient}>
{process.env.NODE_ENV === "development" ? <ClickToComponent /> : null}
<ChakraProvider theme={theme}>
<ChakraProvider theme={colorMode === "light" ? theme : darkTheme}>
<BrowserRouter>
<RouteElement />
</BrowserRouter>
Expand Down
3 changes: 3 additions & 0 deletions web/src/chakraTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ const Menu = {
};

const theme = extendTheme({
initialColorMode: "dark", // 'dark | 'light'
useSystemColorMode: false,
fontSizes: {
sm: "12px",
base: "12px",
Expand Down Expand Up @@ -424,4 +426,5 @@ const theme = extendTheme({
Menu,
},
});

export default theme;
Loading

0 comments on commit 99e1568

Please sign in to comment.