Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve NextJS helper and offer to make it part of MUI #114

Closed
garronej opened this issue Sep 22, 2022 · 1 comment
Closed

Improve NextJS helper and offer to make it part of MUI #114

garronej opened this issue Sep 22, 2022 · 1 comment

Comments

@garronej
Copy link
Owner

We should improve the Api:

pages/_app.tsx

 import { createEmotionSsrAdvancedApproach } from "tss-react/nextJs";
-const { EmotionCacheProvider, withEmotionCache } = createEmotionSsrAdvancedApproach({ "key": "css" });
+const { withAppEmotionCache, withDocumentEmotionCache } = createEmotionSsrAdvancedApproach({ "key": "css" });

export { withDocumentEmotionCache };

+ export default withAppEmotionCache(App);

Just a memo:

import Head from "next/head";
import DefaultApp from "next/app";
import type { NextComponentType } from "next";
import type { AppProps } from "next/app";
import marianneLightWoff2Url from "../dsfr/fonts/Marianne-Light.woff2";
import marianneItalicWoff2Url from "../dsfr/fonts/Marianne-Light_Italic.woff2";
import marianneRegularWoff2Url from "../dsfr/fonts/Marianne-Regular.woff2";
import marianneRegularItalicWoff2Url from "../dsfr/fonts/Marianne-Regular_Italic.woff2";
import marianneMediumWoff2Url from "../dsfr/fonts/Marianne-Medium.woff2";
import marianneMediumItalicWoff2Url from "../dsfr/fonts/Marianne-Medium_Italic.woff2";
import marianneBoldWoff2Url from "../dsfr/fonts/Marianne-Bold.woff2";
import marianneBoldItalicWoff2Url from "../dsfr/fonts/Marianne-Bold_Italic.woff2";
import spectralRegularWoff2Url from "../dsfr/fonts/Spectral-Regular.woff2";
import spectralExtraBoldWoff2Url from "../dsfr/fonts/Spectral-ExtraBold.woff2";

export function withDsfr(): typeof DefaultApp;
export function withDsfr<AppComponent extends NextComponentType<any, any, any>>(App: AppComponent): AppComponent;
export function withDsfr<AppComponent extends NextComponentType<any, any, any>>(App: AppComponent = DefaultApp as any): AppComponent {

  function AppWithDsfr(props: AppProps) {
  	return (
  		<>
  			<Head>
  				{
  					[
  						marianneLightWoff2Url,
  						marianneItalicWoff2Url,
  						marianneRegularWoff2Url,
  						marianneRegularItalicWoff2Url,
  						marianneMediumWoff2Url,
  						marianneMediumItalicWoff2Url,
  						marianneBoldWoff2Url,
  						marianneBoldItalicWoff2Url,
  						spectralRegularWoff2Url,
  						spectralExtraBoldWoff2Url
  					].map(href => <link key={href} rel="preload" href={href} as="font" crossOrigin="anonymous" />)
  				}
  			</Head>
  			<App {...props as any} />
  		</>
  	);

  }


  Object.keys(App)
  	.forEach(staticMethod => (AppWithDsfr as any)[staticMethod] = (App as any)[staticMethod]);

  AppWithDsfr.displayName = AppWithDsfr.name;

  return AppWithDsfr as any;

}



@garronej
Copy link
Owner Author

garronej commented Oct 4, 2022

mui/material-ui#34575

@garronej garronej closed this as completed Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant