Skip to content

Commit ea06d0c

Browse files
committed
Merge branch 'main' into @stanleyoos/docs-update-react-context-link
2 parents 67a6f52 + cef7a66 commit ea06d0c

File tree

65 files changed

+685
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+685
-469
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"editor.formatOnSave": true,
23
"editor.codeActionsOnSave": ["source.organizeImports", "source.fixAll"]
34
}

docusaurus.config.js

Lines changed: 35 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
favicon: 'img/favicon.ico',
1010
organizationName: 'react-navigation',
1111
projectName: 'react-navigation.github.io',
12-
scripts: ['/js/snack-helpers.js'],
12+
scripts: ['/js/snack-helpers.js', '/js/toc-fixes.js'],
1313
themeConfig: {
1414
prism: {
1515
theme: require('prism-react-renderer').themes.github,
@@ -37,96 +37,63 @@ export default {
3737
src: 'img/spiro.svg',
3838
},
3939
items: [
40-
{ to: 'docs/getting-started', label: 'Docs', position: 'left' },
41-
{ to: 'blog', label: 'Blog', position: 'left' },
4240
{
43-
href: 'https://github.com/react-navigation',
44-
label: 'GitHub',
41+
type: 'docsVersionDropdown',
4542
position: 'right',
4643
},
4744
{
48-
to: 'help',
49-
label: 'Help',
45+
to: 'docs/getting-started',
46+
activeBasePath: 'docs',
47+
label: 'Docs',
48+
position: 'right',
5049
},
5150
{
52-
type: 'docsVersionDropdown',
53-
position: 'left',
51+
to: 'blog',
52+
label: 'Blog',
53+
position: 'right',
5454
},
55-
],
56-
},
57-
footer: {
58-
links: [
5955
{
60-
title: 'Docs',
56+
type: 'dropdown',
57+
label: 'Help',
6158
items: [
6259
{
63-
label: 'Getting Started',
64-
to: 'docs/getting-started',
65-
},
66-
{
67-
label: 'Building your own Navigator',
68-
to: 'docs/custom-navigators',
60+
label: 'Issues',
61+
href: 'https://github.com/react-navigation/react-navigation/issues',
6962
},
7063
{
71-
label: 'Contributing',
72-
to: 'docs/contributing',
64+
label: 'Feature Requests',
65+
href: 'https://react-navigation.canny.io/feature-requests',
7366
},
74-
],
75-
},
76-
{
77-
title: 'Support',
78-
items: [
7967
{
80-
label: 'Chat in our Discord channel',
81-
href: 'https://discord.gg/reactiflux',
68+
label: 'Reactiflux Discord',
69+
href: 'https://www.reactiflux.com',
8270
},
8371
{
84-
label: 'Get help on Stack Overflow',
72+
label: 'Stack Overflow',
8573
href: 'https://stackoverflow.com/questions/tagged/react-navigation',
8674
},
8775
{
88-
label: 'Request a feature on Canny',
89-
href: 'https://react-navigation.canny.io/feature-requests',
76+
label: 'Troubleshooting',
77+
to: 'docs/troubleshooting',
9078
},
9179
{
92-
label: 'Report a bug on GitHub',
93-
href: 'https://github.com/react-navigation/react-navigation/issues/new/choose',
80+
label: 'Contributing',
81+
to: 'docs/contributing',
9482
},
9583
],
84+
position: 'right',
9685
},
9786
{
98-
title: 'Social',
99-
items: [
100-
{
101-
label: 'Blog',
102-
to: 'blog',
103-
},
104-
{
105-
label: 'GitHub',
106-
href: 'https://github.com/react-navigation/react-navigation',
107-
},
108-
{
109-
label: 'Twitter',
110-
href: 'https://twitter.com/reactnavigation',
111-
},
112-
],
87+
href: 'https://x.com/reactnavigation',
88+
className: 'navbar-social-link navbar-social-link-x',
89+
'aria-label': 'X',
90+
position: 'right',
11391
},
11492
{
115-
title: 'Built with',
116-
items: [
117-
{
118-
label: 'Docusaurus',
119-
to: 'https://docusaurus.io/',
120-
},
121-
{
122-
label: 'GitHub Pages',
123-
href: 'https://pages.github.com/',
124-
},
125-
{
126-
label: 'Netlify',
127-
href: 'https://www.netlify.com/',
128-
},
129-
],
93+
href: 'https://github.com/react-navigation/react-navigation',
94+
className: 'navbar-social-link navbar-social-link-github',
95+
'aria-label': 'GitHub',
96+
position: 'right',
13097
},
13198
],
13299
},
@@ -158,7 +125,10 @@ export default {
158125
sidebarCollapsed: false,
159126
remarkPlugins: [[remarkNpm2Yarn, { sync: true }]],
160127
rehypePlugins: [
161-
[rehypeCodeblockMeta, { match: { snack: true, lang: true } }],
128+
[
129+
rehypeCodeblockMeta,
130+
{ match: { snack: true, lang: true, tabs: true } },
131+
],
162132
],
163133
},
164134
blog: {

src/components/Pre.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@ import { useColorMode } from '@docusaurus/theme-common';
33
import { usePluginData } from '@docusaurus/useGlobalData';
44
import MDXPre from '@theme-original/MDXComponents/Pre';
55
import React from 'react';
6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
9+
const SUPPORTED_TABS = {
10+
config: [
11+
{ value: 'static', label: 'Static', default: true },
12+
{ value: 'dynamic', label: 'Dynamic' },
13+
],
14+
};
615

716
export default function Pre({
817
children,
918
'data-name': name,
1019
'data-snack': snack,
1120
'data-dependencies': deps,
21+
'data-tabs': tabs,
1222
'data-lang': lang,
1323
...rest
1424
}) {
@@ -18,6 +28,62 @@ export default function Pre({
1828

1929
const child = React.Children.only(children);
2030

31+
// If we encounter tabs, we need to render 2 code blocks
32+
if (tabs && tabs in SUPPORTED_TABS) {
33+
return (
34+
<Tabs groupId="config" queryString="config">
35+
{SUPPORTED_TABS[tabs].map((tab) => {
36+
const code = child.props.children;
37+
38+
if (typeof code !== 'string') {
39+
throw new Error(
40+
'Code to display in tabs must be a string, but received ' +
41+
typeof code
42+
);
43+
}
44+
45+
const lines = code.split('\n');
46+
47+
let content = '';
48+
let exclude = false;
49+
let indent;
50+
51+
for (const line of lines) {
52+
if (line.trim().startsWith('// codeblock-tabs=')) {
53+
exclude = line.trim() !== `// codeblock-tabs=${tab.value}`;
54+
} else if (line.trim() === '// codeblock-tabs-end') {
55+
exclude = false;
56+
} else if (!exclude) {
57+
content += line + '\n';
58+
}
59+
}
60+
61+
return (
62+
<TabItem
63+
key={tab.value}
64+
value={tab.value}
65+
label={tab.label}
66+
default={tab.default}
67+
>
68+
<Pre
69+
{...rest}
70+
data-name={name}
71+
data-snack={snack}
72+
data-dependencies={deps}
73+
data-lang={lang}
74+
>
75+
{React.cloneElement(children, {
76+
...child.props,
77+
children: content.trim(),
78+
})}
79+
</Pre>
80+
</TabItem>
81+
);
82+
})}
83+
</Tabs>
84+
);
85+
}
86+
2187
// Handle diffs with language
2288
if (child.props.className === 'language-diff' && lang) {
2389
const code = child.props.children;

0 commit comments

Comments
 (0)