chore: App theme added

This commit is contained in:
2025-07-12 21:59:36 +03:30
parent a87120d163
commit f14bd00ed8
8 changed files with 771 additions and 28 deletions

View File

@@ -0,0 +1,33 @@
import { useLayoutEffect, type JSX, type PropsWithChildren } from 'react';
import { useLocalStorage } from '@/hooks/useLocalStorage';
import type { AppTheme } from '@/types/theme';
import { AppThemeContext } from '@/contexts/AppThemeContext';
import { createTheme, ThemeProvider } from '@mui/material';
import { useLangauge } from '@/hooks/useLanguage';
export const AppThemeProvider = (props: PropsWithChildren): JSX.Element => {
const { language } = useLangauge();
const [currentThemeMode, setCurrentTheme] = useLocalStorage<AppTheme>(
'theme',
'default',
);
const muiTheme = createTheme({
direction: language === 'fa' ? 'rtl' : 'ltr',
});
useLayoutEffect(() => {
document.body.setAttribute('theme', currentThemeMode);
}, [currentThemeMode]);
return (
<AppThemeContext.Provider
value={{
mode: currentThemeMode,
changeTheme: setCurrentTheme,
}}
>
<ThemeProvider theme={muiTheme}>{props.children}</ThemeProvider>
</AppThemeContext.Provider>
);
};