mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-11 22:59:03 +08:00
* 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.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
// 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 };
|
|
};
|