mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-02 08:40:26 +00:00
refactor: 整体重构 (#1381)
* feat: pnpm new * Refactor build and release workflows, update dependencies Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
This commit is contained in:
42
packages/napcat-webui-frontend/src/hooks/use-theme.ts
Normal file
42
packages/napcat-webui-frontend/src/hooks/use-theme.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// originally written by @imoaazahmed
|
||||
import { useLocalStorage } from '@uidotdev/usehooks';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
|
||||
const ThemeProps = {
|
||||
key: 'theme',
|
||||
light: 'light',
|
||||
dark: 'dark',
|
||||
} as const;
|
||||
|
||||
type Theme = typeof ThemeProps.light | typeof ThemeProps.dark;
|
||||
|
||||
export const useTheme = (defaultTheme?: Theme) => {
|
||||
const [theme, setTheme] = useLocalStorage<Theme>(ThemeProps.key, defaultTheme);
|
||||
|
||||
const isDark = useMemo(() => {
|
||||
return theme === ThemeProps.dark;
|
||||
}, [theme]);
|
||||
|
||||
const isLight = useMemo(() => {
|
||||
return theme === ThemeProps.light;
|
||||
}, [theme]);
|
||||
|
||||
const _setTheme = (theme: Theme) => {
|
||||
setTheme(theme);
|
||||
document.documentElement.classList.remove(ThemeProps.light, ThemeProps.dark);
|
||||
document.documentElement.classList.add(theme);
|
||||
};
|
||||
|
||||
const setLightTheme = () => _setTheme(ThemeProps.light);
|
||||
|
||||
const setDarkTheme = () => _setTheme(ThemeProps.dark);
|
||||
|
||||
const toggleTheme = () =>
|
||||
theme === ThemeProps.dark ? setLightTheme() : setDarkTheme();
|
||||
|
||||
useEffect(() => {
|
||||
_setTheme(theme);
|
||||
});
|
||||
|
||||
return { theme, isDark, isLight, setLightTheme, setDarkTheme, toggleTheme };
|
||||
};
|
||||
Reference in New Issue
Block a user