Skip to content

Commit

Permalink
extract global style/theme logic to GlobalStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholeuf committed Feb 13, 2024
1 parent fdac8fb commit 5d73564
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
23 changes: 23 additions & 0 deletions src/app/GlobalStyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AppRouterCacheProvider } from '@mui/material-nextjs/v14-appRouter';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';

Check warning on line 3 in src/app/GlobalStyles.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/GlobalStyles.tsx#L1-L3

Added lines #L1 - L3 were not covered by tests

import theme from '@/app/styles/theme';

Check warning on line 5 in src/app/GlobalStyles.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/GlobalStyles.tsx#L5

Added line #L5 was not covered by tests

interface GlobalStylesProps {
children: React.ReactNode;
}

const GlobalStyles: React.FC<GlobalStylesProps> = ({ children }) => {

Check warning on line 11 in src/app/GlobalStyles.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/GlobalStyles.tsx#L11

Added line #L11 was not covered by tests
return (
<AppRouterCacheProvider options={{ enableCssLayer: true }}>
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
{children}
</ThemeProvider>
</AppRouterCacheProvider>
);
}

export default GlobalStyles;

Check warning on line 23 in src/app/GlobalStyles.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/GlobalStyles.tsx#L23

Added line #L23 was not covered by tests
19 changes: 6 additions & 13 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

import { Metadata } from "next";
import { AppRouterCacheProvider } from '@mui/material-nextjs/v14-appRouter';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';

import theme from '@/app/styles/theme';
import Header from '@/components/Header';
import Footer from '@/components/Footer';
import MainContainer from '@/components/MainContainer';
import GlobalStyles from "./GlobalStyles";

Check warning on line 7 in src/app/layout.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/layout.tsx#L4-L7

Added lines #L4 - L7 were not covered by tests

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -40,15 +37,11 @@ const RootLayout: React.FC<RootLayoutProps> = ({ children }) => {
return (
<html lang='en'>
<body>
<AppRouterCacheProvider options={{ enableCssLayer: true }}>
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Header />
<MainContainer>{children}</MainContainer>
<Footer />
</ThemeProvider>
</AppRouterCacheProvider>
<GlobalStyles>
<Header />
<MainContainer>{children}</MainContainer>
<Footer />
</GlobalStyles>
</body>
</html>
);
Expand Down

0 comments on commit 5d73564

Please sign in to comment.