Skip to content

Commit

Permalink
[examples] Simplify Next.js example (#40661)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Jan 21, 2024
1 parent 4f8afb4 commit 9eea72d
Show file tree
Hide file tree
Showing 70 changed files with 266 additions and 583 deletions.
2 changes: 1 addition & 1 deletion apps/zero-runtime-next-app/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Demo Next.js app for Zero Runtime

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https:/vercel/next.js/tree/canary/packages/create-next-app).
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https:/vercel/next.js/tree/HEAD/packages/create-next-app).

## Getting Started

Expand Down
4 changes: 2 additions & 2 deletions apps/zero-runtime-next-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const metadata: Metadata = {
description: 'Generated by create next app',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
export default function RootLayout(props: { children: React.ReactNode }) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>{props.children}</body>
</html>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ export default function ThemeRegistry(props) {

// app/layout.js
export default function RootLayout(props) {
const { children } = props;
return (
<html lang="en">
<body>
<ThemeRegistry options={{ key: 'mui' }}>{children}</ThemeRegistry>
<ThemeRegistry options={{ key: 'mui' }}>{props.children}</ThemeRegistry>
</body>
</html>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ export default function ThemeRegistry(props) {

// app/layout.tsx
export default function RootLayout(props) {
const { children } = props;
return (
<html lang="en">
<body>
<ThemeRegistry options={{ key: 'joy' }}>{children}</ThemeRegistry>
<ThemeRegistry options={{ key: 'joy' }}>{props.children}</ThemeRegistry>
</body>
</html>
);
Expand Down
4 changes: 2 additions & 2 deletions docs/data/material/guides/nextjs/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Inside `app/layout.tsx`, import the `AppRouterCacheProvider` and wrap all elemen
// or `v1X-appRouter` if you are using Next.js v1X

export default function RootLayout(props) {
const { children } = props;
return (
<html lang="en">
<body>
+ <AppRouterCacheProvider>{children}</AppRouterCacheProvider>
- {props.children}
+ <AppRouterCacheProvider>{props.children}</AppRouterCacheProvider>
</body>
</html>
);
Expand Down
2 changes: 1 addition & 1 deletion examples/base-ui-nextjs-tailwind-ts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base UI - Next.js App Router with Tailwind CSS example in TypeScript

This is a [Next.js](https://nextjs.org/) project bootstrapped using [`create-next-app`](https:/vercel/next.js/tree/canary/packages/create-next-app) with Base UI installed and Tailwind CSS for styles.
This is a [Next.js](https://nextjs.org/) project bootstrapped using [`create-next-app`](https:/vercel/next.js/tree/HEAD/packages/create-next-app) with Base UI installed and Tailwind CSS for styles.

## How to use

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = nextConfig;
export default nextConfig;
3 changes: 1 addition & 2 deletions examples/base-ui-nextjs-tailwind-ts/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export const metadata = {
};

export default function RootLayout(props: { children: React.ReactNode }) {
const { children } = props;
return (
<html lang="en">
<body className={font.className}>{children}</body>
<body className={font.className}>{props.children}</body>
</html>
);
}
2 changes: 1 addition & 1 deletion examples/joy-ui-nextjs-ts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Joy UI - Next.js App Router with TypeScript

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https:/vercel/next.js/tree/canary/packages/create-next-app).
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https:/vercel/next.js/tree/HEAD/packages/create-next-app).

## How to use

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = nextConfig;
export default nextConfig;
3 changes: 1 addition & 2 deletions examples/joy-ui-nextjs-ts/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ export const metadata = {
};

export default function RootLayout(props: { children: React.ReactNode }) {
const { children } = props;
return (
<html lang="en">
<body>
<ThemeRegistry>{children}</ThemeRegistry>
<ThemeRegistry>{props.children}</ThemeRegistry>
</body>
</html>
);
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-styled-components-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function App() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Create React App example with styled-components in TypeScript
</Typography>
<ProTip />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props: SvgIconProps) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-styled-components/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function App() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Create React App example with styled-components
</Typography>
<ProTip />
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-styled-components/src/ProTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-tailwind-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function App() {
return (
<Container maxWidth="sm">
<div className="my-4">
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Create React App example with Tailwind CSS in TypeScript
</Typography>
<Slider
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-tailwind-ts/src/ProTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props: SvgIconProps) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function App() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Create React App example in TypeScript
</Typography>
<ProTip />
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra-ts/src/ProTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props: SvgIconProps) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function App() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Create React App example
</Typography>
<ProTip />
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-cra/src/ProTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-express-ssr/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function App() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Express.js server-rendered example
</Typography>
<ProTip />
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-express-ssr/ProTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-gatsby/src/components/ProTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-gatsby/src/pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function About() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Gatsby example
</Typography>
<Link to="/">Go to the main page</Link>
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-gatsby/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Index() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI Gatsby example
</Typography>
<Link to="/about" color="secondary">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Html, Head, Main, NextScript, DocumentProps } from 'next/document';
import { Html, Head, Main, NextScript, DocumentProps, DocumentContext } from 'next/document';
import { DocumentHeadTags, documentGetInitialProps } from '@mui/material-nextjs/v14-pagesRouter';
import theme, { roboto } from '../src/theme';

Expand All @@ -21,4 +21,7 @@ export default function MyDocument(props: DocumentProps) {
);
}

MyDocument.getInitialProps = documentGetInitialProps;
MyDocument.getInitialProps = async (ctx: DocumentContext) => {
const finalProps = await documentGetInitialProps(ctx);
return finalProps;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function About() {
alignItems: 'center',
}}
>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js example in TypeScript
</Typography>
<Box sx={{ maxWidth: 'sm' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Home() {
alignItems: 'center',
}}
>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js example in TypeScript
</Typography>
<Link href="/about" color="secondary">
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-nextjs-pages-router-ts/src/ProTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props: SvgIconProps) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
5 changes: 4 additions & 1 deletion examples/material-ui-nextjs-pages-router/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export default function MyDocument(props) {
);
}

MyDocument.getInitialProps = documentGetInitialProps;
MyDocument.getInitialProps = async (ctx) => {
const finalProps = await documentGetInitialProps(ctx);
return finalProps;
};
2 changes: 1 addition & 1 deletion examples/material-ui-nextjs-pages-router/pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function About() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js example
</Typography>
<Button variant="contained" component={Link} noLinkStyle href="/">
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-nextjs-pages-router/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Index() {
return (
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js example
</Typography>
<Link href="/about" color="secondary">
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-nextjs-pages-router/src/ProTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LightBulbIcon(props) {

export default function ProTip() {
return (
<Typography sx={{ mt: 6, mb: 3 }} color="text.secondary">
<Typography sx={{ mt: 6, mb: 3, color: 'text.secondary' }}>
<LightBulbIcon sx={{ mr: 1, verticalAlign: 'middle' }} />
{'Pro tip: See more '}
<Link href="https://mui.com/material-ui/getting-started/templates/">templates</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function MyDocument(props: DocumentProps) {
{/* PWA primary color */}
<meta name="theme-color" content={theme.palette.primary.main} />
<link rel="shortcut icon" href="/favicon.ico" />
{/* Inject MUI styles first to match with the prepend: true configuration. */}
<DocumentHeadTags {...props} />
</Head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function About() {
return (
<Container maxWidth="lg">
<div className={classes.main}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js example in TypeScript with legacy @mui/styles
</Typography>
<Box sx={{ maxWidth: 'sm' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Home() {
return (
<Container maxWidth="lg">
<div className={classes.main}>
<Typography variant="h4" component="h1" gutterBottom>
<Typography variant="h4" component="h1" sx={{ mb: 2 }}>
Material UI - Next.js example in TypeScript with legacy @mui/styles
</Typography>
<Link href="/about" color="secondary">
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-nextjs-ts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Material UI - Next.js App Router example in TypeScript

This is a [Next.js](https://nextjs.org/) project bootstrapped using [`create-next-app`](https:/vercel/next.js/tree/canary/packages/create-next-app) with Material UI installed.
This is a [Next.js](https://nextjs.org/) project bootstrapped using [`create-next-app`](https:/vercel/next.js/tree/HEAD/packages/create-next-app) with Material UI installed.

## How to use

Expand Down
15 changes: 0 additions & 15 deletions examples/material-ui-nextjs-ts/next.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions examples/material-ui-nextjs-ts/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
Loading

0 comments on commit 9eea72d

Please sign in to comment.