chore: dark config

This commit is contained in:
jialin
2025-04-28 10:05:06 +08:00
parent d4d7148f16
commit ce9c31f368
35 changed files with 678 additions and 399 deletions
+7 -1
View File
@@ -1,3 +1,5 @@
import { userSettingsHelperAtom } from '@/atoms/settings';
import { useAtom } from 'jotai';
import { throttle } from 'lodash';
import {
UseOverlayScrollbarsParams,
@@ -28,6 +30,7 @@ export default function useOverlayScroller(data?: {
events?: any;
defer?: boolean;
}) {
const [useSettings] = useAtom(userSettingsHelperAtom);
const { options, events, defer = true } = data || {};
const scrollEventElement = React.useRef<any>(null);
const instanceRef = React.useRef<any>(null);
@@ -44,7 +47,10 @@ export default function useOverlayScroller(data?: {
x: 'hidden'
},
scrollbars: {
theme: options?.theme || 'os-theme-dark',
theme:
options?.theme || useSettings.theme === 'light'
? 'os-theme-dark'
: 'os-theme-light',
autoHide: 'scroll',
autoHideDelay: 600,
clickScroll: 'instant'
+46
View File
@@ -0,0 +1,46 @@
import { userSettingsHelperAtom } from '@/atoms/settings';
import themeConfig from '@/config/theme';
import { useAtom } from 'jotai';
import { useEffect, useMemo } from 'react';
type Theme = 'light' | 'realDark';
export default function useUserSettings() {
const { light, dark } = themeConfig;
const [userSettings, setUserSettings] = useAtom(userSettingsHelperAtom);
const setHtmlThemeAttr = (theme: string) => {
const html = document.querySelector('html');
if (html) {
html.setAttribute('data-theme', theme);
}
};
const themeData = useMemo(() => {
return {
...(userSettings.theme === 'realDark' ? dark : light)
};
}, [userSettings.theme]);
const isDarkTheme = useMemo(() => {
return userSettings.theme === 'realDark';
}, [userSettings.theme]);
const setTheme = (theme: Theme) => {
setHtmlThemeAttr(theme);
setUserSettings({ ...userSettings, theme: theme });
};
useEffect(() => {
setHtmlThemeAttr(userSettings.theme);
}, [userSettings.theme]);
return {
userSettings,
setUserSettings,
setTheme,
isDarkTheme,
themeData,
componentSize: 'large'
};
}