-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathPrebuiltDownloadButtons.tsx
More file actions
80 lines (68 loc) · 2.11 KB
/
PrebuiltDownloadButtons.tsx
File metadata and controls
80 lines (68 loc) · 2.11 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use client';
import { CloudArrowDownIcon } from '@heroicons/react/24/outline';
import Skeleton from '@node-core/ui-components/Common/Skeleton';
import { useTranslations } from 'next-intl';
import { use } from 'react';
import Button from '#site/components/Common/Button';
import { ReleaseContext } from '#site/providers/releaseProvider';
import {
OS_NOT_SUPPORTING_INSTALLERS,
OperatingSystemLabel,
} from '#site/util/download';
import { getNodeDownloadUrl } from '#site/util/url';
import type { FC } from 'react';
// Retrieves the pure extension piece from the input string
const getExtension = (input: string) => String(input.split('.').slice(-1));
const PrebuiltDownloadButtons: FC = () => {
const t = useTranslations();
const { release, os, platform } = use(ReleaseContext);
const installerUrl = platform
? getNodeDownloadUrl({
versionWithPrefix: release.versionWithPrefix,
os,
platform,
kind: 'installer',
})
: '';
const binaryUrl = platform
? getNodeDownloadUrl({
versionWithPrefix: release.versionWithPrefix,
os,
platform,
kind: 'binary',
})
: '';
return (
<div className="my-4 flex flex-col gap-2 sm:flex-row">
<Skeleton
loading={os === 'LOADING' || platform === ''}
hide={OS_NOT_SUPPORTING_INSTALLERS.includes(os)}
>
<Button
href={installerUrl}
size="small"
className="w-full min-w-56 sm:w-auto"
>
<CloudArrowDownIcon />
{t('layouts.download.buttons.installer', {
os: OperatingSystemLabel[os],
extension: getExtension(installerUrl),
})}
</Button>
</Skeleton>
<Skeleton loading={os === 'LOADING' || platform === ''}>
<Button
href={binaryUrl}
size="small"
className="w-full min-w-56 sm:w-auto"
>
<CloudArrowDownIcon />
{t('layouts.download.buttons.binary', {
extension: getExtension(binaryUrl),
})}
</Button>
</Skeleton>
</div>
);
};
export default PrebuiltDownloadButtons;