Skip to content

Commit 42fa316

Browse files
IgnacioUtrillaoliviertassinari
andauthoredJul 24, 2023
[examples] Fix Joy UI Next.js App Router font loading (#38095)
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
1 parent 0c62711 commit 42fa316

File tree

12 files changed

+47
-38
lines changed

12 files changed

+47
-38
lines changed
 

‎docs/src/modules/brandingTheme.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ const systemFont = [
167167

168168
export const getMetaThemeColor = (mode: 'light' | 'dark') => {
169169
const themeColor = {
170-
light: grey[50],
171-
dark: blueDark[800],
170+
light: blue[600],
171+
dark: blueDark[900],
172172
};
173173
return themeColor[mode];
174174
};

‎examples/base-next-app-router-tailwind-ts/src/app/page.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import * as React from 'react';
22
import Switch from '@mui/base/Switch';
33
import { Select, SelectOption, Slider } from './components';
44

5-
function Heading({ children }: { children: React.ReactNode }) {
6-
return <h2 className="font-bold text-gray-400 uppercase text-base mt-3 mb-2">{children}</h2>;
5+
function Heading(props: { children: React.ReactNode }) {
6+
return (
7+
<h2 className="font-bold text-gray-400 uppercase text-base mt-3 mb-2">{props.children}</h2>
8+
);
79
}
810

9-
function Section({ children }: { children: React.ReactNode }) {
11+
function Section(props: { children: React.ReactNode }) {
1012
return (
1113
<div className="grid grid-cols-3 grid-rows-[40px] gap-x-16 items-center min-h-[40px] py-1.5 border-t-[1px] border-solid border-gray-700">
12-
{children}
14+
{props.children}
1315
</div>
1416
);
1517
}
1618

17-
function Label({ children }: { children: React.ReactNode }) {
18-
return <h3 className="font-medium leading-none text-gray-300 col-span-2">{children}</h3>;
19+
function Label(props: { children: React.ReactNode }) {
20+
return <h3 className="font-medium leading-none text-gray-300 col-span-2">{props.children}</h3>;
1921
}
2022

2123
const HOURS = [
@@ -74,7 +76,6 @@ export default function Home() {
7476
defaultChecked
7577
/>
7678
</Section>
77-
7879
<Section>
7980
<Label>Auto-Enable Between</Label>
8081
<div className="col-span-1 grid grid-cols-[1fr_auto_1fr] items-center">
@@ -95,7 +96,6 @@ export default function Home() {
9596
</Select>
9697
</div>
9798
</Section>
98-
9999
<Section>
100100
<Label>Night Mode Tint</Label>
101101
<div className="col-span-1 self-stretch">

‎examples/joy-next-app-router-ts/src/app/layout.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import * as React from 'react';
2-
import { Public_Sans } from 'next/font/google';
32
import ThemeRegistry from '@/components/ThemeRegistry/ThemeRegistry';
43

5-
const publicSans = Public_Sans({ subsets: ['latin'] });
6-
74
export const metadata = {
85
title: 'Create Next App',
96
description: 'Generated by create next app',
@@ -12,7 +9,7 @@ export const metadata = {
129
export default function RootLayout({ children }: { children: React.ReactNode }) {
1310
return (
1411
<html lang="en">
15-
<body className={publicSans.className}>
12+
<body>
1613
<ThemeRegistry>{children}</ThemeRegistry>
1714
</body>
1815
</html>

‎examples/joy-next-app-router-ts/src/app/page.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ export default function Home() {
3939
</Typography>
4040
<Typography level="body2">Sign in to continue.</Typography>
4141
</div>
42-
<FormControl>
42+
<FormControl id="email">
4343
<FormLabel>Email</FormLabel>
4444
<Input name="email" type="email" placeholder="johndoe@email.com" />
4545
</FormControl>
46-
<FormControl>
46+
<FormControl id="password">
4747
<FormLabel>Password</FormLabel>
4848
<Input name="password" type="password" placeholder="password" />
4949
</FormControl>
50-
5150
<Button sx={{ mt: 1 }}>Log in</Button>
5251
<Typography
5352
endDecorator={<Link href="/sign-up">Sign up</Link>}

‎examples/joy-next-app-router-ts/src/components/ThemeRegistry/theme.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import { Public_Sans } from 'next/font/google';
12
import { extendTheme } from '@mui/joy/styles';
23

4+
const publicSans = Public_Sans({
5+
subsets: ['latin'],
6+
display: 'swap',
7+
});
8+
39
const theme = extendTheme({
10+
fontFamily: {
11+
body: publicSans.style.fontFamily,
12+
},
413
components: {
514
JoyButton: {
615
styleOverrides: {

‎examples/material-next-app-router-ts/src/app/layout.tsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Roboto } from 'next/font/google';
32
import Link from 'next/link';
43
import AppBar from '@mui/material/AppBar';
54
import Box from '@mui/material/Box';
@@ -26,12 +25,6 @@ export const metadata = {
2625
description: 'Next.js App Router + Material UI v5',
2726
};
2827

29-
const roboto = Roboto({
30-
variable: '--font-roboto',
31-
weight: ['300', '400', '500', '700'],
32-
subsets: ['latin'],
33-
});
34-
3528
const DRAWER_WIDTH = 240;
3629

3730
const LINKS = [
@@ -48,8 +41,8 @@ const PLACEHOLDER_LINKS = [
4841

4942
export default function RootLayout({ children }: { children: React.ReactNode }) {
5043
return (
51-
<html lang="en" className={roboto.variable}>
52-
<body className={roboto.className}>
44+
<html lang="en">
45+
<body>
5346
<ThemeRegistry>
5447
<AppBar position="fixed" sx={{ zIndex: 2000 }}>
5548
<Toolbar sx={{ backgroundColor: 'background.paper' }}>

‎examples/material-next-app-router-ts/src/components/ThemeRegistry/theme.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import { Roboto } from 'next/font/google';
12
import { createTheme } from '@mui/material/styles';
23

3-
const defaultTheme = createTheme({
4+
const roboto = Roboto({
5+
weight: ['300', '400', '500', '700'],
6+
subsets: ['latin'],
7+
display: 'swap',
8+
});
9+
10+
const theme = createTheme({
411
palette: {
512
mode: 'light',
613
},
714
typography: {
8-
fontFamily: 'var(--font-roboto)',
15+
fontFamily: roboto.style.fontFamily,
916
},
1017
components: {
1118
MuiAlert: {
@@ -20,4 +27,4 @@ const defaultTheme = createTheme({
2027
},
2128
});
2229

23-
export default defaultTheme;
30+
export default theme;

‎examples/material-next-ts-v4-v5-migration/pages/_document.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export default function MyDocument({ emotionStyleTags }: MyDocumentProps) {
2525
{/* PWA primary color */}
2626
<meta name="theme-color" content={theme.palette.primary.main} />
2727
<link rel="shortcut icon" href="/favicon.ico" />
28-
<link
29-
rel="stylesheet"
30-
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
31-
/>
3228
{/* Inject MUI styles first to match with the prepend: true configuration. */}
3329
{emotionStyleTags}
3430
</Head>

‎examples/material-next-ts-v4-v5-migration/src/theme.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import { Roboto } from 'next/font/google';
12
import { createTheme } from '@mui/material/styles';
23
import { red } from '@mui/material/colors';
34

5+
const roboto = Roboto({
6+
weight: ['300', '400', '500', '700'],
7+
subsets: ['latin'],
8+
display: 'swap',
9+
});
10+
411
// Create a theme instance.
512
const theme = createTheme({
613
palette: {
@@ -14,6 +21,9 @@ const theme = createTheme({
1421
main: red.A400,
1522
},
1623
},
24+
typography: {
25+
fontFamily: roboto.style.fontFamily,
26+
},
1727
});
1828

1929
export default theme;

‎examples/material-next-ts/src/theme.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const roboto = Roboto({
66
weight: ['300', '400', '500', '700'],
77
subsets: ['latin'],
88
display: 'swap',
9-
fallback: ['Helvetica', 'Arial', 'sans-serif'],
109
});
1110

1211
// Create a theme instance.

‎examples/material-next/pages/_document.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import * as React from 'react';
22
import PropTypes from 'prop-types';
33
import Document, { Html, Head, Main, NextScript } from 'next/document';
44
import createEmotionServer from '@emotion/server/create-instance';
5-
import theme, { roboto } from '../src/theme';
5+
import theme from '../src/theme';
66
import createEmotionCache from '../src/createEmotionCache';
77

88
export default function MyDocument(props) {
99
const { emotionStyleTags } = props;
1010

1111
return (
12-
<Html lang="en" className={roboto.className}>
12+
<Html lang="en">
1313
<Head>
1414
{/* PWA primary color */}
1515
<meta name="theme-color" content={theme.palette.primary.main} />

‎examples/material-next/src/theme.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { Roboto } from 'next/font/google';
22
import { createTheme } from '@mui/material/styles';
33
import { red } from '@mui/material/colors';
44

5-
export const roboto = Roboto({
5+
const roboto = Roboto({
66
weight: ['300', '400', '500', '700'],
77
subsets: ['latin'],
88
display: 'swap',
9-
fallback: ['Helvetica', 'Arial', 'sans-serif'],
109
});
1110

1211
// Create a theme instance.

0 commit comments

Comments
 (0)
Please sign in to comment.