Skip to content

Commit

Permalink
chore: upgrade docusaurus to 2.3.1 & react 18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
blakef committed Mar 13, 2023
1 parent 5c41e87 commit 21846bf
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 288 deletions.
12 changes: 6 additions & 6 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@
]
},
"dependencies": {
"@docusaurus/core": "^2.0.1",
"@docusaurus/plugin-pwa": "^2.0.1",
"@docusaurus/preset-classic": "^2.0.1",
"@docusaurus/core": "^2.3.1",
"@docusaurus/plugin-pwa": "^2.3.1",
"@docusaurus/preset-classic": "^2.3.1",
"docusaurus-plugin-sass": "^0.2.2",
"esbuild-loader": "^2.19.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-github-btn": "^1.3.0",
"sass": "^1.53.0"
},
"devDependencies": {
"@docusaurus/types": "^2.0.1",
"@docusaurus/types": "^2.3.1",
"@react-native-website/lint-examples": "0.0.0",
"alex": "^10.0.0",
"fs-extra": "^10.1.0",
Expand Down
58 changes: 32 additions & 26 deletions website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
useActiveDocContext,
} from '@docusaurus/plugin-content-docs/client';
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
import {useDocsVersionCandidates} from '@docusaurus/theme-common/internal';
import {translate} from '@docusaurus/Translate';
import {useLocation} from '@docusaurus/router';

const getVersionMainDoc = version =>
version.docs.find(doc => doc.id === version.mainDocId);

export default function DocsVersionDropdownNavbarItem({
mobile,
docsPluginId,
Expand All @@ -27,6 +28,7 @@ export default function DocsVersionDropdownNavbarItem({
dropdownItemsAfter,
...props
}) {
const {search, hash} = useLocation();
const activeDocContext = useActiveDocContext(docsPluginId);
const versions = useVersions(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);
Expand All @@ -41,32 +43,32 @@ export default function DocsVersionDropdownNavbarItem({
// (CUSTOM) Show only `next` and last 5 versions in the dropdown
const reducedVersions = versions.slice(0, 6);

function getItems() {
const versionLinks = reducedVersions.map(version => {
// We try to link to the same doc, in another version
// When not possible, fallback to the "main doc" of the version
const versionDoc =
activeDocContext?.alternateDocVersions[version.name] ||
getVersionMainDoc(version);
return {
isNavLink: true,
label: version.label,
to: versionDoc.path,
isActive: () => version === activeDocContext?.activeVersion,
onClick: () => {
savePreferredVersionName(version.name);
},
};
});
return [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter];
}
const versionLinks = reducedVersions.map(version => {
// We try to link to the same doc, in another version
// When not possible, fallback to the "main doc" of the version
const versionDoc =
activeDocContext?.alternateDocVersions[version.name] ??
getVersionMainDoc(version);
return {
label: version.label,
// preserve ?search#hash suffix on version switches
to: `${versionDoc.path}${search}${hash}`,
isActive: () => version === activeDocContext?.activeVersion,
onClick: () => savePreferredVersionName(version.name),
};
});

const items = getItems();
const dropdownVersion =
activeDocContext.activeVersion ?? preferredVersion ?? latestVersion; // Mobile dropdown is handled a bit differently
const items = [
...dropdownItemsBefore,
...versionLinks,
...dropdownItemsAfter,
];

const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0];

// Mobile dropdown is handled a bit differently
const dropdownLabel =
mobile && items
mobile && items.length > 1
? translate({
id: 'theme.navbar.mobileVersionsDropdown.label',
message: 'Versions',
Expand All @@ -75,8 +77,12 @@ export default function DocsVersionDropdownNavbarItem({
})
: dropdownVersion.label;
const dropdownTo =
mobile && items ? undefined : getVersionMainDoc(dropdownVersion).path; // We don't want to render a version dropdown with 0 or 1 item
// If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
mobile && items.length > 1
? undefined
: getVersionMainDoc(dropdownVersion).path;

// We don't want to render a version dropdown with 0 or 1 item. If we build
// the site with a single docs version (onlyIncludeVersions: ['1.0.0']),
// We'd rather render a button instead of a dropdown

if (items.length <= 1) {
Expand Down
Loading

0 comments on commit 21846bf

Please sign in to comment.