mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: ui theme
This commit is contained in:
49
src/components/layout/use-custom-theme.ts
Normal file
49
src/components/layout/use-custom-theme.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import useSWR from "swr";
|
||||
import { useMemo } from "react";
|
||||
import { createTheme } from "@mui/material";
|
||||
import { getVergeConfig } from "../../services/cmds";
|
||||
|
||||
/**
|
||||
* wip: custome theme
|
||||
*/
|
||||
export default function useCustomTheme() {
|
||||
const { data } = useSWR("getVergeConfig", getVergeConfig);
|
||||
const mode = data?.theme_mode ?? "light";
|
||||
|
||||
const theme = useMemo(() => {
|
||||
// const background = mode === "light" ? "#f5f5f5" : "#000";
|
||||
const selectColor = mode === "light" ? "#f5f5f5" : "#d5d5d5";
|
||||
|
||||
const rootEle = document.documentElement;
|
||||
rootEle.style.background = "transparent";
|
||||
rootEle.style.setProperty("--selection-color", selectColor);
|
||||
|
||||
const theme = createTheme({
|
||||
breakpoints: {
|
||||
values: { xs: 0, sm: 650, md: 900, lg: 1200, xl: 1536 },
|
||||
},
|
||||
palette: {
|
||||
mode,
|
||||
primary: { main: "#5b5c9d" },
|
||||
text: { primary: "#637381", secondary: "#909399" },
|
||||
},
|
||||
});
|
||||
|
||||
const { palette } = theme;
|
||||
|
||||
setTimeout(() => {
|
||||
const dom = document.querySelector("#Gradient2");
|
||||
if (dom) {
|
||||
dom.innerHTML = `
|
||||
<stop offset="0%" stop-color="${palette.primary.main}" />
|
||||
<stop offset="80%" stop-color="${palette.primary.dark}" />
|
||||
<stop offset="100%" stop-color="${palette.primary.dark}" />
|
||||
`;
|
||||
}
|
||||
}, 0);
|
||||
|
||||
return theme;
|
||||
}, [mode]);
|
||||
|
||||
return { theme };
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
import { useRef } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useTheme } from "@mui/material";
|
||||
|
||||
const minPoint = 10;
|
||||
const maxPoint = 36;
|
||||
|
||||
const refLineAlpha = 0.5;
|
||||
const refLineAlpha = 1;
|
||||
const refLineWidth = 2;
|
||||
const refLineColor = "#ccc";
|
||||
|
||||
const upLineAlpha = 0.6;
|
||||
const upLineWidth = 4;
|
||||
const upLineColor = "#9c27b0";
|
||||
|
||||
const downLineAlpha = 1;
|
||||
const downLineWidth = 4;
|
||||
const downLineColor = "#5b5c9d";
|
||||
|
||||
/**
|
||||
* draw the traffic graph
|
||||
@@ -24,11 +22,23 @@ export default function useTrafficGraph() {
|
||||
const styleRef = useRef(true);
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null!);
|
||||
|
||||
const { palette } = useTheme();
|
||||
const paletteRef = useRef(palette);
|
||||
|
||||
useEffect(() => {
|
||||
paletteRef.current = palette;
|
||||
}, [palette]);
|
||||
|
||||
const drawGraph = () => {
|
||||
const canvas = canvasRef.current!;
|
||||
|
||||
if (!canvas) return;
|
||||
|
||||
const { primary, secondary, divider } = paletteRef.current;
|
||||
const refLineColor = divider || "rgba(0, 0, 0, 0.12)";
|
||||
const upLineColor = secondary.main || "#9c27b0";
|
||||
const downLineColor = primary.main || "#5b5c9d";
|
||||
|
||||
const context = canvas.getContext("2d")!;
|
||||
const width = canvas.width;
|
||||
const height = canvas.height;
|
||||
|
||||
Reference in New Issue
Block a user