Skip to content

Commit 6fbfc62

Browse files
[docs][nextjs] Migrate from deprecated "legacyBehavior" prop (#44871)
1 parent 6915f8d commit 6fbfc62

File tree

11 files changed

+87
-214
lines changed

11 files changed

+87
-214
lines changed

Diff for: docs/data/joy/getting-started/templates/TemplateCollection.js

+52-62
Original file line numberDiff line numberDiff line change
@@ -137,53 +137,48 @@ export default function TemplateCollection() {
137137
'--template-name-dark': `center/cover no-repeat url(/static/screenshots/joy-ui/getting-started/templates/${template.name}-dark.jpg)`,
138138
}}
139139
/>
140-
<NextLink
140+
<Link
141141
href={`/joy-ui/getting-started/templates/${template.name}/`}
142-
passHref
143-
legacyBehavior
142+
tabIndex={-1}
143+
component={NextLink}
144+
overlay
145+
aria-hidden
146+
data-ga-event-category="joy-template"
147+
data-ga-event-label={template.name}
148+
data-ga-event-action="preview-img"
149+
sx={[
150+
(theme) => ({
151+
display: 'flex',
152+
alignItems: 'center',
153+
justifyContent: 'center',
154+
flexDirection: 'column',
155+
gap: 1,
156+
transition: '0.15s',
157+
position: 'absolute',
158+
width: '100%',
159+
height: '100%',
160+
opacity: 0,
161+
top: 0,
162+
left: 0,
163+
bgcolor: `rgba(${theme.vars.palette.primary.lightChannel} / 0.3)`,
164+
backdropFilter: 'blur(4px)',
165+
'&:hover, &:focus': {
166+
opacity: 1,
167+
},
168+
[theme.getColorSchemeSelector('dark')]: {
169+
bgcolor: `rgba(${theme.vars.palette.primary.darkChannel} / 0.3)`,
170+
},
171+
}),
172+
]}
144173
>
145-
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
146-
<Link
147-
tabIndex={-1}
148-
overlay
149-
aria-hidden
150-
data-ga-event-category="joy-template"
151-
data-ga-event-label={template.name}
152-
data-ga-event-action="preview-img"
153-
sx={[
154-
(theme) => ({
155-
display: 'flex',
156-
alignItems: 'center',
157-
justifyContent: 'center',
158-
flexDirection: 'column',
159-
gap: 1,
160-
transition: '0.15s',
161-
position: 'absolute',
162-
width: '100%',
163-
height: '100%',
164-
opacity: 0,
165-
top: 0,
166-
left: 0,
167-
bgcolor: `rgba(${theme.vars.palette.primary.lightChannel} / 0.3)`,
168-
backdropFilter: 'blur(4px)',
169-
'&:hover, &:focus': {
170-
opacity: 1,
171-
},
172-
[theme.getColorSchemeSelector('dark')]: {
173-
bgcolor: `rgba(${theme.vars.palette.primary.darkChannel} / 0.3)`,
174-
},
175-
}),
176-
]}
174+
<Visibility />
175+
<Typography
176+
textColor="text.primary"
177+
sx={{ fontWeight: 'bold', fontFamily: 'IBM Plex Sans' }}
177178
>
178-
<Visibility />
179-
<Typography
180-
textColor="text.primary"
181-
sx={{ fontWeight: 'bold', fontFamily: 'IBM Plex Sans' }}
182-
>
183-
View live preview
184-
</Typography>
185-
</Link>
186-
</NextLink>
179+
View live preview
180+
</Typography>
181+
</Link>
187182
</AspectRatio>
188183
</CardOverflow>
189184
<CardContent sx={{ display: 'flex', flexDirection: 'column' }}>
@@ -255,26 +250,21 @@ export default function TemplateCollection() {
255250
gap: 1.5,
256251
}}
257252
>
258-
<NextLink
253+
<Button
259254
href={`https://github.com/mui/material-ui/tree/master/docs/data/joy/getting-started/templates/${template.name}`}
260-
passHref
261-
legacyBehavior
255+
component={NextLink}
256+
variant="outlined"
257+
color="neutral"
258+
fullWidth
259+
startDecorator={<CodeRoundedIcon />}
260+
aria-label="Source code"
261+
data-ga-event-category="joy-template"
262+
data-ga-event-label={template.name}
263+
data-ga-event-action="preview"
264+
sx={{ fontFamily: 'IBM Plex Sans' }}
262265
>
263-
<Button
264-
component="a"
265-
variant="outlined"
266-
color="neutral"
267-
fullWidth
268-
startDecorator={<CodeRoundedIcon />}
269-
aria-label="Source code"
270-
data-ga-event-category="joy-template"
271-
data-ga-event-label={template.name}
272-
data-ga-event-action="preview"
273-
sx={{ fontFamily: 'IBM Plex Sans' }}
274-
>
275-
Source
276-
</Button>
277-
</NextLink>
266+
Source
267+
</Button>
278268
<Button
279269
variant="outlined"
280270
color="neutral"

Diff for: examples/material-ui-nextjs-pages-router-ts/pages/about.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Container from '@mui/material/Container';
33
import Typography from '@mui/material/Typography';
44
import Box from '@mui/material/Box';
55
import Button from '@mui/material/Button';
6-
import Link from '../src/Link';
6+
import { Link } from '../src/Link';
77
import ProTip from '../src/ProTip';
88
import Copyright from '../src/Copyright';
99

Diff for: examples/material-ui-nextjs-pages-router-ts/pages/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import Container from '@mui/material/Container';
33
import Typography from '@mui/material/Typography';
44
import Box from '@mui/material/Box';
5-
import Link from '../src/Link';
5+
import { Link } from '../src/Link';
66
import ProTip from '../src/ProTip';
77
import Copyright from '../src/Copyright';
88

Diff for: examples/material-ui-nextjs-pages-router-ts/src/Link.tsx

+6-31
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,9 @@ interface NextLinkComposedProps
1313

1414
export const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComposedProps>(
1515
function NextLinkComposed(props, ref) {
16-
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
16+
const { to, linkAs, ...other } = props;
1717

18-
return (
19-
<NextLink
20-
href={to}
21-
prefetch={prefetch}
22-
as={linkAs}
23-
replace={replace}
24-
scroll={scroll}
25-
shallow={shallow}
26-
passHref
27-
locale={locale}
28-
ref={ref}
29-
{...other}
30-
/>
31-
);
18+
return <NextLink href={to} as={linkAs} ref={ref} {...other} />;
3219
},
3320
);
3421

@@ -43,38 +30,28 @@ export type LinkProps = {
4330

4431
// A styled version of the Next.js Link component:
4532
// https://nextjs.org/docs/pages/api-reference/components/link
46-
const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props, ref) {
33+
export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props, ref) {
4734
const {
4835
activeClassName = 'active',
4936
as,
5037
className: classNameProps,
5138
href,
5239
linkAs: linkAsProp,
53-
locale,
5440
noLinkStyle,
55-
prefetch,
56-
replace,
57-
role, // Link don't have roles.
58-
scroll,
59-
shallow,
6041
...other
6142
} = props;
6243

6344
const router = useRouter();
64-
const pathname = typeof href === 'string' ? href : href.pathname;
45+
const pathname = typeof href === 'string' ? href : href?.pathname;
46+
6547
const className = clsx(classNameProps, {
6648
[activeClassName]: router.pathname === pathname && activeClassName,
6749
});
6850

69-
const linkAs = linkAsProp || as;
51+
const linkAs = linkAsProp || as || (href as string);
7052
const nextjsProps = {
7153
to: href,
7254
linkAs,
73-
replace,
74-
scroll,
75-
shallow,
76-
prefetch,
77-
locale,
7855
};
7956

8057
if (noLinkStyle) {
@@ -91,5 +68,3 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
9168
/>
9269
);
9370
});
94-
95-
export default Link;

Diff for: examples/material-ui-nextjs-pages-router/pages/about.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Typography from '@mui/material/Typography';
44
import Box from '@mui/material/Box';
55
import Button from '@mui/material/Button';
66
import ProTip from '../src/ProTip';
7-
import Link from '../src/Link';
7+
import { Link } from '../src/Link';
88
import Copyright from '../src/Copyright';
99

1010
export default function About() {

Diff for: examples/material-ui-nextjs-pages-router/pages/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Container from '@mui/material/Container';
33
import Typography from '@mui/material/Typography';
44
import Box from '@mui/material/Box';
55
import ProTip from '../src/ProTip';
6-
import Link from '../src/Link';
6+
import { Link } from '../src/Link';
77
import Copyright from '../src/Copyright';
88

99
export default function Index() {

Diff for: examples/material-ui-nextjs-pages-router/src/Link.js

+6-31
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,35 @@ import NextLink from 'next/link';
55
import MuiLink from '@mui/material/Link';
66

77
export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props, ref) {
8-
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
8+
const { to, linkAs, ...other } = props;
99

10-
return (
11-
<NextLink
12-
href={to}
13-
prefetch={prefetch}
14-
as={linkAs}
15-
replace={replace}
16-
scroll={scroll}
17-
shallow={shallow}
18-
passHref
19-
locale={locale}
20-
ref={ref}
21-
{...other}
22-
/>
23-
);
10+
return <NextLink href={to} as={linkAs} ref={ref} {...other} />;
2411
});
2512

2613
// A styled version of the Next.js Link component:
2714
// https://nextjs.org/docs/pages/api-reference/components/link
28-
const Link = React.forwardRef(function Link(props, ref) {
15+
export const Link = React.forwardRef(function Link(props, ref) {
2916
const {
3017
activeClassName = 'active',
3118
as,
3219
className: classNameProps,
3320
href,
3421
linkAs: linkAsProp,
35-
locale,
3622
noLinkStyle,
37-
prefetch,
38-
replace,
39-
role, // Link don't have roles.
40-
scroll,
41-
shallow,
4223
...other
4324
} = props;
4425

4526
const router = useRouter();
46-
const pathname = typeof href === 'string' ? href : href.pathname;
27+
const pathname = typeof href === 'string' ? href : href?.pathname;
28+
4729
const className = clsx(classNameProps, {
4830
[activeClassName]: router.pathname === pathname && activeClassName,
4931
});
5032

51-
const linkAs = linkAsProp || as;
33+
const linkAs = linkAsProp || as || href;
5234
const nextjsProps = {
5335
to: href,
5436
linkAs,
55-
replace,
56-
scroll,
57-
shallow,
58-
prefetch,
59-
locale,
6037
};
6138

6239
if (noLinkStyle) {
@@ -73,5 +50,3 @@ const Link = React.forwardRef(function Link(props, ref) {
7350
/>
7451
);
7552
});
76-
77-
export default Link;

Diff for: examples/material-ui-nextjs-ts-v4-v5-migration/pages/about.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Typography from '@mui/material/Typography';
44
import Box from '@mui/material/Box';
55
import Button from '@mui/material/Button';
66
import { makeStyles } from '@mui/styles';
7-
import Link from '../src/Link';
7+
import { Link } from '../src/Link';
88
import ProTip from '../src/ProTip';
99
import Copyright from '../src/Copyright';
1010

Diff for: examples/material-ui-nextjs-ts-v4-v5-migration/pages/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import Container from '@mui/material/Container';
33
import Typography from '@mui/material/Typography';
44
import { makeStyles } from '@mui/styles';
5-
import Link from '../src/Link';
5+
import { Link } from '../src/Link';
66
import ProTip from '../src/ProTip';
77
import Copyright from '../src/Copyright';
88

0 commit comments

Comments
 (0)