-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathPackageManagerDropdown.tsx
More file actions
50 lines (42 loc) · 1.63 KB
/
PackageManagerDropdown.tsx
File metadata and controls
50 lines (42 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use client';
import Select from '@node-core/ui-components/Common/Select';
import { useTranslations } from 'next-intl';
import { use, useEffect, useMemo } from 'react';
import { ReleaseContext } from '#site/providers/releaseProvider';
import { nextItem, PACKAGE_MANAGERS, parseCompat } from '#site/util/download';
import type { PackageManager } from '#site/types/release';
import type { FC } from 'react';
const PackageManagerDropdown: FC = () => {
const release = use(ReleaseContext);
const t = useTranslations();
// We parse the compatibility of the dropdown items
const parsedPackageManagers = useMemo(
() => parseCompat(PACKAGE_MANAGERS, release),
// We only want to react on the change of the Version
// eslint-disable-next-line @eslint-react/exhaustive-deps
[release.version]
);
// We set the Package Manager to the next available Package Manager when the current
// one is not valid anymore due to Version changes
useEffect(
() =>
release.setPackageManager(
nextItem(release.packageManager, parsedPackageManagers)
),
// We only want to react on the change of the Version
// eslint-disable-next-line @eslint-react/exhaustive-deps
[release.version, release.packageManager]
);
return (
<Select<PackageManager>
values={parsedPackageManagers}
value={release.packageManager}
loading={release.os === 'LOADING' || release.installMethod === ''}
ariaLabel={t('layouts.download.dropdown.packageManager')}
onChange={manager => release.setPackageManager(manager)}
className="min-w-28"
inline={true}
/>
);
};
export default PackageManagerDropdown;