You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data/material/migration/upgrade-to-v6/migrating-to-pigment-css.md
+45-6Lines changed: 45 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -212,6 +212,45 @@ yarn dev
212
212
213
213
Open the browser and navigate to the localhost URL, you should see the app running with Pigment CSS.
214
214
215
+
### Next.js font optimization
216
+
217
+
If you are using `next/font` to optimize font loading, pass a CSS variable name to the `variable` property of the font configuration and use it in the body className:
218
+
219
+
```diff title="app/layout.tsx"
220
+
import { Roboto } from 'next/font/google';
221
+
222
+
const roboto = Roboto({
223
+
weight: ['300', '400', '500', '700'],
224
+
subsets: ['latin'],
225
+
display: 'swap',
226
+
+ variable: '--my-font-family',
227
+
});
228
+
229
+
export default function RootLayout(props) {
230
+
const { children } = props;
231
+
return (
232
+
<html lang="en">
233
+
+ <body className={roboto.variable}>
234
+
{children}
235
+
</body>
236
+
</html>
237
+
);
238
+
}
239
+
```
240
+
241
+
Finally, update the `typography.fontFamily` value with the variable created in the previous step:
242
+
243
+
```diff title="next.config.mjs"
244
+
const pigmentConfig = {
245
+
transformLibraries: ['@mui/material'],
246
+
theme: createTheme({
247
+
+ typography: {
248
+
+ fontFamily: 'var(--my-font-family)',
249
+
+ },
250
+
}),
251
+
};
252
+
```
253
+
215
254
### Typescript
216
255
217
256
If you are using TypeScript, you need to extend the Pigment CSS theme types with Material UI `Theme`.
@@ -274,7 +313,7 @@ We recommend reading the rest of the guide below to learn about the new styling
274
313
Since Pigment CSS is a build-time extraction tool, it does not support owner state through callbacks. Here is an example that will throw an error at build time:
275
314
276
315
```js
277
-
consttheme=extendTheme({
316
+
consttheme=createTheme({
278
317
components: {
279
318
MuiCard: {
280
319
styleOverrides: {
@@ -307,7 +346,7 @@ If you have a dynamic color based on the theme palette, you can use the `variant
307
346
<codeblock>
308
347
309
348
```js before
310
-
consttheme=extendTheme({
349
+
consttheme=createTheme({
311
350
components: {
312
351
MuiCard: {
313
352
styleOverrides: {
@@ -321,7 +360,7 @@ const theme = extendTheme({
321
360
```
322
361
323
362
```js after
324
-
consttheme=extendTheme({
363
+
consttheme=createTheme({
325
364
components: {
326
365
MuiCard: {
327
366
styleOverrides: {
@@ -352,9 +391,9 @@ Use `DefaultPropsProvider` in your main application file and move all the compon
352
391
<codeblock>
353
392
354
393
```diff next.config|vite.config
355
-
import { extendTheme } from'@mui/material';
394
+
import { createTheme } from'@mui/material';
356
395
357
-
constcustomTheme=extendTheme({
396
+
constcustomTheme=createTheme({
358
397
// ...other tokens.
359
398
components: {
360
399
MuiButtonBase: {
@@ -639,7 +678,7 @@ Update the config file with the following code to enable right-to-left support:
0 commit comments