Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Issue/533 add light and dark mode #719

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
#533 Added theme mode provider
  • Loading branch information
Arturas1989 committed Feb 9, 2024
commit a888988c78bb599f73e2973f2c8922c32835eb54
44 changes: 22 additions & 22 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Provider } from 'react-redux';
import { Grid } from '@mui/material';
import { ThemeProvider } from "@mui/material/styles";
import { ThemeModeProvider } from 'features/ThemeModeProvider';
import store from 'app/store';
import InfoAlert from 'features/alert/InfoAlert.js';
import WarningAlert from 'features/alert/WarningAlert.js';
Expand All @@ -18,31 +18,31 @@ import theme from 'styles/theme.js';

const App = () => {
return (
<ThemeProvider theme={theme}>
<Provider store={store}>
<Grid container>
<Nav />
<NavDialogs />
</Grid>
<Grid container sx={{ p: 2 }} spacing={2}>
<Grid item xs={12} md={5}>
<Board />
<ThemeModeProvider theme={theme}>
<Grid container>
<Nav />
<NavDialogs />
</Grid>
<Grid item xs={12} md={7}>
<Panel />
<Grid container sx={{ p: 2 }} spacing={2}>
<Grid item xs={12} md={5}>
<Board />
</Grid>
<Grid item xs={12} md={7}>
<Panel />
</Grid>
</Grid>
</Grid>
<ModeFenDialogs />
<ModePlayDialogs />
<ModeRavDialogs />
<ModeSanDialogs />
<ModeSanDialogs />
<ModeStockfishDialogs />
<ProgressDialog />
<InfoAlert />
<WarningAlert />
<ModeFenDialogs />
<ModePlayDialogs />
<ModeRavDialogs />
<ModeSanDialogs />
<ModeSanDialogs />
<ModeStockfishDialogs />
<ProgressDialog />
<InfoAlert />
<WarningAlert />
</ThemeModeProvider>
</Provider>
</ThemeProvider>
);
};

Expand Down
20 changes: 20 additions & 0 deletions src/features/ThemeModeProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CssBaseline } from "@mui/material";
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { useSelector } from "react-redux";

export const ThemeModeProvider = ({ children, theme }) => {
const darkTheme = useSelector(state => state.nav.dialogs.settings.fields.darkTheme);
const mode = darkTheme === 'on' ? 'dark' : 'light';
theme = createTheme({
...theme,
palette: {
mode
}
})
return (
<ThemeProvider theme={theme}>
<CssBaseline />
{children}
</ThemeProvider>
)
}