-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a62ecc
commit d095d37
Showing
14 changed files
with
278 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from "react"; | ||
|
||
export interface ClientStyleContextData { | ||
reset: () => void; | ||
} | ||
|
||
export default React.createContext<ClientStyleContextData>({ | ||
reset: () => {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { CacheProvider } from "@emotion/react"; | ||
import { ThemeProvider } from "@mui/material/styles"; | ||
import CssBaseline from "@mui/material/CssBaseline"; | ||
|
||
import ClientStyleContext from "./ClientStyleContext"; | ||
import createEmotionCache from "./createEmotionCache"; | ||
import { useMemo, useState } from "react"; | ||
import theme from "./theme"; | ||
|
||
interface ClientCacheProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
function ClientCacheProvider({ children }: ClientCacheProviderProps) { | ||
const [cache, setCache] = useState(createEmotionCache()); | ||
|
||
const clientStyleContextValue = useMemo( | ||
() => ({ | ||
reset() { | ||
setCache(createEmotionCache()); | ||
}, | ||
}), | ||
[], | ||
); | ||
|
||
return ( | ||
<ClientStyleContext.Provider value={clientStyleContextValue}> | ||
<CacheProvider value={cache}>{children}</CacheProvider> | ||
</ClientStyleContext.Provider> | ||
); | ||
} | ||
|
||
export function MuiClientProvider({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<ClientCacheProvider> | ||
<ThemeProvider theme={theme}> | ||
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} | ||
<CssBaseline /> | ||
{children} | ||
</ThemeProvider> | ||
</ClientCacheProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { EmotionCache, withEmotionCache } from "@emotion/react"; | ||
import { unstable_useEnhancedEffect as useEnhancedEffect } from "@mui/material"; | ||
import { useContext } from "react"; | ||
import ClientStyleContext from "./ClientStyleContext"; | ||
|
||
interface DocumentProps { | ||
children: React.ReactNode; | ||
title?: string; | ||
} | ||
|
||
//TODO: Do we really need this one??? | ||
export const MuiDocument = withEmotionCache( | ||
({ children }: DocumentProps, emotionCache: EmotionCache) => { | ||
const clientStyleData = useContext(ClientStyleContext); | ||
|
||
// Only executed on client | ||
useEnhancedEffect(() => { | ||
debugger; | ||
// re-link sheet container | ||
emotionCache.sheet.container = document.head; | ||
// re-inject tags | ||
const tags = emotionCache.sheet.tags; | ||
emotionCache.sheet.flush(); | ||
tags.forEach((tag) => { | ||
// eslint-disable-next-line no-underscore-dangle | ||
(emotionCache.sheet as any)._insertTag(tag); | ||
}); | ||
// reset cache to reapply global styles | ||
clientStyleData.reset(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return children; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CacheProvider } from "@emotion/react"; | ||
import { ThemeProvider } from "@mui/material/styles"; | ||
import CssBaseline from "@mui/material/CssBaseline"; | ||
|
||
import createEmotionCache from "./createEmotionCache"; | ||
|
||
import theme from "./theme"; | ||
|
||
export function MuiServerProvider({ children }: { children: React.ReactNode }) { | ||
const cache = createEmotionCache(); | ||
|
||
return ( | ||
<CacheProvider value={cache}> | ||
<ThemeProvider theme={theme}> | ||
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} | ||
<CssBaseline /> | ||
{children} | ||
</ThemeProvider> | ||
</CacheProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import createCache from "@emotion/cache"; | ||
|
||
export default function createEmotionCache() { | ||
return createCache({ key: "css" }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { LinksFunction } from "@remix-run/node"; | ||
|
||
export const getMuiLinks: LinksFunction = () => [ | ||
// Google Fonts for MUI | ||
{ rel: "preconnect", href: "https://fonts.googleapis.com" }, | ||
{ | ||
rel: "preconnect", | ||
href: "https://fonts.gstatic.com", | ||
crossOrigin: "anonymous", | ||
}, | ||
{ | ||
rel: "stylesheet", | ||
href: "https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import theme from "./theme"; | ||
import { MetaDescriptor } from "@remix-run/react"; | ||
|
||
export const getMuiMeta = (): MetaDescriptor[] => [ | ||
{ name: "theme-color", content: theme.palette.primary.main }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createTheme } from "@mui/material/styles"; | ||
import { red } from "@mui/material/colors"; | ||
|
||
// Create a theme instance. | ||
const theme = createTheme({ | ||
palette: { | ||
primary: { | ||
main: "#556cd6", | ||
}, | ||
secondary: { | ||
main: "#19857b", | ||
}, | ||
error: { | ||
main: red.A400, | ||
}, | ||
}, | ||
}); | ||
|
||
export default theme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.