Skip to content

Commit e0f68e8

Browse files
committed
refactor: stateless select used instead of the HTML details element
1 parent ec457eb commit e0f68e8

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

apps/site/components/withDownloadArchive.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ import {
66
buildReleaseArtifacts,
77
extractVersionFromPath,
88
findReleaseByVersion,
9-
getDownloadArchiveNavigation,
109
} from '#site/util/download/archive';
1110

1211
type DownloadArchive = ReturnType<typeof buildReleaseArtifacts>;
1312

14-
type Navigation = {
15-
label: string;
16-
href: string;
17-
};
18-
1913
type WithDownloadArchiveProps = {
20-
children: FC<DownloadArchive & { navigation: Array<Navigation> }>;
14+
children: FC<DownloadArchive>;
2115
};
2216

2317
/**
@@ -44,13 +38,12 @@ const WithDownloadArchive: FC<WithDownloadArchiveProps> = async ({
4438
return null;
4539
}
4640

47-
const navigation = getDownloadArchiveNavigation(releaseData);
4841
const releaseArtifacts = buildReleaseArtifacts(
4942
release,
5043
version === 'archive' ? release.versionWithPrefix : version
5144
);
5245

53-
return <Component {...releaseArtifacts} navigation={navigation} />;
46+
return <Component {...releaseArtifacts} />;
5447
};
5548

5649
export default WithDownloadArchive;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use client';
2+
3+
import WithNoScriptSelect from '@node-core/ui-components/Common/Select/NoScriptSelect';
4+
import type { ComponentProps, FC } from 'react';
5+
6+
import Link from '#site/components/Link';
7+
import { useRouter } from '#site/navigation.mjs';
8+
import provideReleaseData from '#site/next-data/providers/releaseData';
9+
import { getDownloadArchiveNavigation } from '#site/util/download/archive';
10+
11+
type WithReleaseSelectProps = Omit<
12+
ComponentProps<typeof WithNoScriptSelect>,
13+
'values' | 'as' | 'onChange'
14+
>;
15+
16+
const WithReleaseSelect: FC<WithReleaseSelectProps> = ({ ...props }) => {
17+
const releaseData = provideReleaseData();
18+
const { push } = useRouter();
19+
const navigation = getDownloadArchiveNavigation(releaseData);
20+
21+
return (
22+
<WithNoScriptSelect
23+
{...props}
24+
values={navigation}
25+
as={Link}
26+
onChange={push}
27+
/>
28+
);
29+
};
30+
31+
export default WithReleaseSelect;

apps/site/next.mdx.use.client.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ReleaseVersionDropdown from './components/Downloads/Release/VersionDropdo
1818
import Link from './components/Link';
1919
import MDXCodeBox from './components/MDX/CodeBox';
2020
import MDXImage from './components/MDX/Image';
21+
import WithReleaseSelect from './components/withReleaseSelect';
2122
import { ReleaseProvider } from './providers/releaseProvider';
2223

2324
/**
@@ -32,6 +33,8 @@ export const clientMdxComponents = {
3233
DownloadButton: DownloadButton,
3334
// Renders a Download Link
3435
DownloadLink: DownloadLink,
36+
// Renders a stateless Release Select Component
37+
WithReleaseSelect: WithReleaseSelect,
3538
// Group of components that enable you to select versions for Node.js
3639
// releases and download selected versions. Uses `releaseProvider` as a provider
3740
Release: {

apps/site/pages/en/download/archive.mdx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ layout: download-archive
44
---
55

66
<WithDownloadArchive>
7-
{({ binaries, installers, version, release, sources, navigation }) => (
7+
{({ binaries, installers, version, release, sources }) => (
88
<>
99
<h1>Node.js® Download Archive</h1>
1010

@@ -39,20 +39,8 @@ layout: download-archive
3939

4040
</ul>
4141

42-
<details>
43-
<summary>
44-
<h3>Other releases</h3>
45-
</summary>
46-
<ul>
47-
{navigation.map(({ href, label }) => (
48-
<li key={label}>
49-
<Link href={href}>
50-
<h4>{label}</h4>
51-
</Link>
52-
</li>
53-
))}
54-
</ul>
55-
</details>
42+
<h3>Other releases</h3>
43+
<WithReleaseSelect defaultValue={`/download/${version}`} className="w-64" />
5644

5745
<h2>Binary Downloads</h2>
5846
<DownloadsTable source={binaries} />

apps/site/util/download/archive.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ const getCompatibleArtifacts = ({
8989
* It creates a list of links for each major release, formatted with the major
9090
* version and codename if available.
9191
*/
92-
export const getDownloadArchiveNavigation = (releases: Array<NodeRelease>) =>
93-
releases.map(({ major, codename, versionWithPrefix }) => ({
92+
export const getDownloadArchiveNavigation = (releases: Array<NodeRelease>) => {
93+
const items = releases.map(({ major, codename, versionWithPrefix }) => ({
9494
label: `Node.js v${major} ${codename ? `(${codename})` : ''}`,
95-
href: `/download/${versionWithPrefix}`,
95+
value: `/download/${versionWithPrefix}`,
9696
}));
9797

98+
return [
99+
{
100+
items,
101+
},
102+
];
103+
};
104+
98105
/**
99106
* Builds the release artifacts for a given Node.js release and version.
100107
* It retrieves binaries, installers, and source files based on the version.

0 commit comments

Comments
 (0)