Skip to content

Commit 8f5a120

Browse files
committed
Mark necessary MDX components as Client Components
1 parent cc34811 commit 8f5a120

File tree

15 files changed

+202
-170
lines changed

15 files changed

+202
-170
lines changed

src/components/Layout/HomeContent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/**
24
* Copyright (c) Meta Platforms, Inc. and affiliates.
35
*

src/components/MDX/Challenges/Challenges.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {H2} from 'components/MDX/Heading';
1616
import {H4} from 'components/MDX/Heading';
1717
import {Challenge} from './Challenge';
1818
import {Navigation} from './Navigation';
19-
import {useRouter} from 'next/router';
19+
import {useRouter} from 'next/compat/router';
2020

2121
interface ChallengesProps {
2222
children: React.ReactElement[];

src/components/MDX/Challenges/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/**
24
* Copyright (c) Meta Platforms, Inc. and affiliates.
35
*

src/components/MDX/ErrorDecoder.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/**
24
* Copyright (c) Meta Platforms, Inc. and affiliates.
35
*
@@ -6,7 +8,7 @@
68
*/
79

810
import {useEffect, useState} from 'react';
9-
import {useErrorDecoderParams} from '../ErrorDecoderContext';
11+
import {useErrorDecoderParams} from '../_/ErrorDecoderContext';
1012
import cn from 'classnames';
1113

1214
function replaceArgs(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export function AuthorCredit({
2+
author = 'Rachel Lee Nabors',
3+
authorLink = 'https://nearestnabors.com/',
4+
}: {
5+
author: string;
6+
authorLink: string;
7+
}) {
8+
return (
9+
<div className="sr-only group-hover:not-sr-only group-focus-within:not-sr-only hover:sr-only">
10+
<p className="bg-card dark:bg-card-dark text-center text-sm text-secondary dark:text-secondary-dark leading-tight p-2 rounded-lg absolute start-1/2 -top-4 -translate-x-1/2 -translate-y-full group-hover:flex group-hover:opacity-100 after:content-[''] after:absolute after:start-1/2 after:top-[95%] after:-translate-x-1/2 after:border-8 after:border-x-transparent after:border-b-transparent after:border-t-card after:dark:border-t-card-dark opacity-0 transition-opacity duration-300">
11+
<cite>
12+
Illustrated by{' '}
13+
{authorLink ? (
14+
<a
15+
target="_blank"
16+
rel="noreferrer"
17+
className="text-link dark:text-link-dark"
18+
href={authorLink}>
19+
{author}
20+
</a>
21+
) : (
22+
author
23+
)}
24+
</cite>
25+
</p>
26+
</div>
27+
);
28+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use client';
2+
3+
import {useContext} from 'react';
4+
import {IllustrationContext} from './IllustrationContext';
5+
import {AuthorCredit} from './AuthorCredit';
6+
7+
export function Illustration({
8+
caption,
9+
src,
10+
alt,
11+
author,
12+
authorLink,
13+
}: {
14+
caption: string;
15+
src: string;
16+
alt: string;
17+
author: string;
18+
authorLink: string;
19+
}) {
20+
const {isInBlock} = useContext(IllustrationContext);
21+
22+
return (
23+
<div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
24+
<figure className="my-8 flex justify-center">
25+
<img
26+
src={src}
27+
alt={alt}
28+
style={{maxHeight: 300}}
29+
className="rounded-lg"
30+
/>
31+
{caption ? (
32+
<figcaption className="text-center leading-tight mt-4">
33+
{caption}
34+
</figcaption>
35+
) : null}
36+
</figure>
37+
{!isInBlock && <AuthorCredit author={author} authorLink={authorLink} />}
38+
</div>
39+
);
40+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {Children} from 'react';
2+
import {IllustrationContext} from './IllustrationContext';
3+
import {AuthorCredit} from './AuthorCredit';
4+
5+
const isInBlockTrue = {isInBlock: true};
6+
7+
export function IllustrationBlock({
8+
sequential,
9+
author,
10+
authorLink,
11+
children,
12+
}: {
13+
author: string;
14+
authorLink: string;
15+
sequential: boolean;
16+
children: any;
17+
}) {
18+
const imageInfos = Children.toArray(children).map(
19+
(child: any) => child.props
20+
);
21+
const images = imageInfos.map((info, index) => (
22+
<figure key={index}>
23+
<div className="bg-white rounded-lg p-4 flex-1 flex xl:p-6 justify-center items-center my-4">
24+
<img
25+
className="text-primary"
26+
src={info.src}
27+
alt={info.alt}
28+
height={info.height}
29+
/>
30+
</div>
31+
{info.caption ? (
32+
<figcaption className="text-secondary dark:text-secondary-dark text-center leading-tight mt-4">
33+
{info.caption}
34+
</figcaption>
35+
) : null}
36+
</figure>
37+
));
38+
return (
39+
<IllustrationContext value={isInBlockTrue}>
40+
<div className="relative group before:absolute before:-inset-y-16 before:inset-x-0 my-16 mx-0 2xl:mx-auto max-w-4xl 2xl:max-w-6xl">
41+
{sequential ? (
42+
<ol className="mdx-illustration-block flex">
43+
{images.map((x: any, i: number) => (
44+
<li className="flex-1" key={i}>
45+
{x}
46+
</li>
47+
))}
48+
</ol>
49+
) : (
50+
<div className="mdx-illustration-block">{images}</div>
51+
)}
52+
<AuthorCredit author={author} authorLink={authorLink} />
53+
</div>
54+
</IllustrationContext>
55+
);
56+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use client';
2+
3+
import {createContext} from 'react';
4+
5+
export const IllustrationContext = createContext<{
6+
isInBlock?: boolean;
7+
}>({
8+
isInBlock: false,
9+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use client';
2+
3+
import {useContext} from 'react';
4+
import {LanguagesContext} from './LanguagesContext';
5+
import {finishedTranslations} from 'utils/finishedTranslations';
6+
import Link from 'next/link';
7+
import {LI, UL} from './List';
8+
9+
type TranslationProgress = 'complete' | 'in-progress';
10+
11+
export function LanguageList({progress}: {progress: TranslationProgress}) {
12+
const allLanguages = useContext(LanguagesContext) ?? [];
13+
const languages = allLanguages
14+
.filter(
15+
({code}) =>
16+
code !== 'en' &&
17+
(progress === 'complete'
18+
? finishedTranslations.includes(code)
19+
: !finishedTranslations.includes(code))
20+
)
21+
.sort((a, b) => a.enName.localeCompare(b.enName));
22+
return (
23+
<UL>
24+
{languages.map(({code, name, enName}) => {
25+
return (
26+
<LI key={code}>
27+
<Link href={`https://${code}.react.dev/`}>
28+
{enName} ({name})
29+
</Link>{' '}
30+
&mdash;{' '}
31+
<Link href={`https://github.com/reactjs/${code}.react.dev`}>
32+
Contribute
33+
</Link>
34+
</LI>
35+
);
36+
})}
37+
</UL>
38+
);
39+
}

src/components/MDX/LanguagesContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
/**
24
* Copyright (c) Meta Platforms, Inc. and affiliates.
35
*

0 commit comments

Comments
 (0)