Skip to content

Commit

Permalink
chore: reduce layout shift, simplify codebox and cleanup text
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Feb 25, 2024
1 parent 51aba24 commit 2d595d2
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 70 deletions.
4 changes: 2 additions & 2 deletions components/Downloads/Release/BitnessDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ const BitnessDropdown: FC = () => {

return (
<Select
label={t('layouts.download.dropdown.bitness')}
values={formatDropdownItems({
items: bitnessItems[os],
disabledItems,
})}
defaultValue={String(bitness)}
onChange={bitness => setBitness(parseNumericBitness(bitness))}
className="w-28"
inline={true}
className="min-w-20"
label={t('layouts.download.dropdown.bitness')}
/>
);
};
Expand Down
6 changes: 1 addition & 5 deletions components/Downloads/Release/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { FC } from 'react';

import Button from '@/components/Common/Button';
import { ReleaseContext } from '@/providers/releaseProvider';
import { OperatingSystem } from '@/util/downloadUtils';
import { getNodeDownloadUrl } from '@/util/getNodeDownloadUrl';

type DownloadButtonProps = { kind: 'installer' | 'binary' | 'source' };
Expand All @@ -24,10 +23,7 @@ const DownloadButton: FC<DownloadButtonProps> = ({ kind = 'installer' }) => {
<Button href={url} disabled={!version}>
<CloudArrowDownIcon />

{t('layouts.download.buttons.prebuilt', {
version,
os: OperatingSystem[os],
})}
{t('layouts.download.buttons.prebuilt', { version })}
</Button>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions components/Downloads/Release/OperatingSystemDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const OperatingSystemDropdown: FC<OperatingSystemDropdownProps> = ({

return (
<Select
label={t('layouts.download.dropdown.os')}
values={formatDropdownItems({
items: operatingSystemItems,
disabledItems,
Expand All @@ -74,9 +75,8 @@ const OperatingSystemDropdown: FC<OperatingSystemDropdownProps> = ({
})}
defaultValue={os}
onChange={value => setOS(value as UserOS)}
className="w-[8.5rem]"
inline={true}
className="min-w-28"
label={t('layouts.download.dropdown.os')}
/>
);
};
Expand Down
8 changes: 2 additions & 6 deletions components/Downloads/Release/PlatformDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { FC } from 'react';

import Select from '@/components/Common/Select';
import Docker from '@/components/Icons/Platform/Docker';
import Generic from '@/components/Icons/Platform/Generic';
import Homebrew from '@/components/Icons/Platform/Homebrew';
import NVM from '@/components/Icons/Platform/NVM';
import { ReleaseContext } from '@/providers/releaseProvider';
Expand Down Expand Up @@ -65,23 +64,20 @@ const PlatformDropdown: FC = () => {

return (
<Select
label={t('layouts.download.dropdown.platform')}
values={formatDropdownItems({
items: platformItems,
icons: {
NVM: <NVM width={16} height={16} />,
BREW: <Homebrew width={16} height={16} />,
DOCKER: <Docker width={16} height={16} />,
},
defaultIcon: (
<Generic className="dark:stroke-neutral-600" width={16} height={16} />
),
disabledItems,
})}
defaultValue={platform}
onChange={platform => setPlatform(platform as PackageManager)}
className="w-28"
inline={true}
className="min-w-24"
label={t('layouts.download.dropdown.platform')}
/>
);
};
Expand Down
20 changes: 14 additions & 6 deletions components/Downloads/Release/ReleaseCodeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import type { FC } from 'react';

import CodeBox from '@/components/Common/CodeBox';
import { ReleaseContext } from '@/providers/releaseProvider';
import { getShiki, highlightToHtml } from '@/util/getHighlighter';
import { getNodeDownloadSnippet } from '@/util/getNodeDownloadSnippet';

// We cannot do top-level awaits on utilities or code that is imported by client-only components
// hence we only declare a Promise and let it be fulfilled by the first call to the function
const memoizedShiki = getShiki();

const ReleaseCodeBox: FC = () => {
const {
platform,
Expand All @@ -17,20 +22,23 @@ const ReleaseCodeBox: FC = () => {
const [code, setCode] = useState('');

useEffect(() => {
const updatedCode = getNodeDownloadSnippet(major, os)[platform];
// Docker and NVM support downloading tags/versions by their full release number
// but usually we should recommend users to download "major" versions
// since our Downlooad Buttons get the latest minor of a major, it does make sense
// to request installation of a major via a package manager
getNodeDownloadSnippet(major, os).then(platforms =>
setCode(platforms[platform])
);
memoizedShiki
.then(shiki => highlightToHtml(shiki)(updatedCode, 'bash'))
.then(setCode);
}, [major, os, platform]);

return (
<div className="mb-2 mt-6 flex min-h-80 flex-col gap-2">
<CodeBox language="Bash">
<code dangerouslySetInnerHTML={{ __html: code }} />
</CodeBox>
{code && (
<CodeBox language="Bash">
<code dangerouslySetInnerHTML={{ __html: code }} />
</CodeBox>
)}

<span className="text-center text-xs text-neutral-800 dark:text-neutral-200">
Package Managers and their installation scripts are not maintained by
Expand Down
14 changes: 5 additions & 9 deletions components/Downloads/Release/VersionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import { useTranslations } from 'next-intl';
import type { FC } from 'react';
import { useContext, useEffect } from 'react';
import { useContext } from 'react';

import Select from '@/components/Common/Select';
import { ReleaseContext } from '@/providers/releaseProvider';
import type { NodeRelease } from '@/types';

const getDropDownStatus = (version: string, status: string) => {
if (status === 'Active LTS') {
Expand All @@ -20,24 +19,21 @@ const getDropDownStatus = (version: string, status: string) => {
return version;
};

const VersionDropdown: FC<NodeRelease> = ({ versionWithPrefix }) => {
const VersionDropdown: FC = () => {
const { releases, release, setVersion } = useContext(ReleaseContext);
const t = useTranslations();
// we shouldn't react when "actions" change
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => setVersion(versionWithPrefix), []);

return (
<Select
label={t('layouts.download.dropdown.version')}
values={releases.map(({ status, versionWithPrefix }) => ({
value: versionWithPrefix,
label: getDropDownStatus(versionWithPrefix, status),
}))}
defaultValue={release.versionWithPrefix}
onChange={setVersion}
className="min-w-28"
inline
label={t('layouts.download.dropdown.version')}
className="w-40"
inline={true}
/>
);
};
Expand Down
14 changes: 13 additions & 1 deletion components/withDownloadCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import type { FC, PropsWithChildren } from 'react';
import { useClientContext } from '@/hooks/react-server';
import getReleaseData from '@/next-data/releaseData';
import { ReleaseProvider } from '@/providers/releaseProvider';
import type { NodeReleaseStatus } from '@/types';
import { getDownloadCategory, mapCategoriesToTabs } from '@/util/downloadUtils';

import LinkTabs from './Common/LinkTabs';
import WithNodeRelease from './withNodeRelease';

const WithDownloadCategories: FC<PropsWithChildren> = async ({ children }) => {
const t = await getTranslations();
Expand All @@ -15,6 +17,10 @@ const WithDownloadCategories: FC<PropsWithChildren> = async ({ children }) => {
const { pathname } = useClientContext();
const { page, category, subCategory } = getDownloadCategory(pathname);

const initialRelease: Array<NodeReleaseStatus> = pathname.includes('current')
? ['Current']
: ['Active LTS', 'Maintenance LTS'];

return (
<LinkTabs
activeTab={category}
Expand Down Expand Up @@ -42,7 +48,13 @@ const WithDownloadCategories: FC<PropsWithChildren> = async ({ children }) => {
subCategory: subCategory,
})}
>
<ReleaseProvider releases={releases}>{children}</ReleaseProvider>
<WithNodeRelease status={initialRelease}>
{({ release }) => (
<ReleaseProvider initialRelease={release} releases={releases}>
{children}
</ReleaseProvider>
)}
</WithNodeRelease>
</LinkTabs>
);
};
Expand Down
4 changes: 2 additions & 2 deletions i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@
"source-code": "Source Code"
},
"buttons": {
"prebuilt": "Download {version} Node.js for {os}",
"source": "Download {version} source code"
"prebuilt": "Download Node.js {version}",
"source": "Download Node.js {version} source"
},
"dropdown": {
"bitness": "Bitness",
Expand Down
4 changes: 2 additions & 2 deletions pages/en/new-design/download/current.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subtitle: Download Node.js the way you want.
---

<section>
I want the <WithNodeRelease status={['Current']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> version of Node for <Release.OperatingSystemDropdown exclude={["LINUX"]} /> running <Release.BitnessDropdown />
I want the <Release.VersionDropdown /> version of Node.js for <Release.OperatingSystemDropdown exclude={["LINUX"]} /> running <Release.BitnessDropdown />

<Release.DownloadButton kind="installer" />
</section>

<section>
<Release.Status /> Version: <Release.Version /> (includes npm and corepack).
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Expand Down
4 changes: 2 additions & 2 deletions pages/en/new-design/download/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subtitle: Download Node.js the way you want.
---

<section>
I want the <WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> version of Node for <Release.OperatingSystemDropdown exclude={["LINUX"]} /> running <Release.BitnessDropdown />
I want the <Release.VersionDropdown /> version of Node.js for <Release.OperatingSystemDropdown exclude={["LINUX"]} /> running <Release.BitnessDropdown />

<Release.DownloadButton kind="installer" />
</section>

<section>
<Release.Status /> Version: <Release.Version /> (includes npm <Release.NpmVersion />).
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Expand Down
4 changes: 3 additions & 1 deletion pages/en/new-design/download/package-manager/current.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ subtitle: Download Node.js the way you want.
---

<section>
Install Node version <WithNodeRelease status={['Current']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> on <Release.OperatingSystemDropdown /> using <Release.PlatformDropdown />
Install Node.js <Release.VersionDropdown /> on <Release.OperatingSystemDropdown /> using <Release.PlatformDropdown />

<Release.ReleaseCodeBox />
</section>

<section>
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Learn how to <Release.VerifyingBinariesLink>verify signed SHASUMS</Release.VerifyingBinariesLink>
Expand Down
4 changes: 3 additions & 1 deletion pages/en/new-design/download/package-manager/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ subtitle: Download Node.js the way you want.
---

<section>
Install Node version <WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> on <Release.OperatingSystemDropdown /> using <Release.PlatformDropdown />
Install Node.js <Release.VersionDropdown /> on <Release.OperatingSystemDropdown /> using <Release.PlatformDropdown />

<Release.ReleaseCodeBox />
</section>

<section>
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Learn how to <Release.VerifyingBinariesLink>verify signed SHASUMS</Release.VerifyingBinariesLink>
Expand Down
4 changes: 2 additions & 2 deletions pages/en/new-design/download/prebuilt-binaries/current.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subtitle: Download Node.js the way you want.
---

<section>
I want the <WithNodeRelease status={['Current']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> version of Node for <Release.OperatingSystemDropdown /> running <Release.BitnessDropdown />
I want the <Release.VersionDropdown /> version of Node.js for <Release.OperatingSystemDropdown /> running <Release.BitnessDropdown />

<Release.DownloadButton kind="binary" />
</section>

<section>
<Release.Status /> Version: <Release.Version /> (includes npm and corepack).
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Expand Down
4 changes: 2 additions & 2 deletions pages/en/new-design/download/prebuilt-binaries/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subtitle: Download Node.js the way you want.
---

<section>
I want the <WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> version of Node for <Release.OperatingSystemDropdown /> running <Release.BitnessDropdown />
I want the <Release.VersionDropdown /> version of Node.js for <Release.OperatingSystemDropdown /> running <Release.BitnessDropdown />

<Release.DownloadButton kind="binary" />
</section>

<section>
<Release.Status /> Version: <Release.Version /> (includes npm <Release.NpmVersion />).
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Expand Down
4 changes: 2 additions & 2 deletions pages/en/new-design/download/source-code/current.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subtitle: Download Node.js the way you want.
---

<section>
I want the <WithNodeRelease status={['Current']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> version of the Node.js source code.
I want the <Release.VersionDropdown /> version of the Node.js source code.

<Release.SourceButton kind="source" />
</section>

<section>
<Release.Status /> Version: <Release.Version /> (includes npm <Release.NpmVersion />).
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Expand Down
4 changes: 2 additions & 2 deletions pages/en/new-design/download/source-code/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subtitle: Download Node.js the way you want.
---

<section>
I want the <WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>{({ release }) => <Release.VersionDropdown {...release} />}</WithNodeRelease> version of the Node.js source code.
I want the <Release.VersionDropdown /> version of the Node.js source code.

<Release.SourceButton kind="source" />
</section>

<section>
<Release.Status /> Version: <Release.Version /> (includes npm <Release.NpmVersion />).
Node.js includes <LinkWithArrow href="https://npmjs.com">npm</LinkWithArrow> (<Release.NpmVersion />) and corepack.

Read the blog post for <Release.BlogPostLink>this version</Release.BlogPostLink>

Expand Down
2 changes: 2 additions & 0 deletions providers/releaseProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const ReleaseContext = createContext<ReleaseContextType>({
export const ReleaseProvider: FC<PropsWithChildren<ReleaseProviderProps>> = ({
children,
releases,
initialRelease,
}) => {
const getReleaseFromVersion = (version: string) =>
releases.find(({ versionWithPrefix }) => versionWithPrefix === version) ??
Expand All @@ -60,6 +61,7 @@ export const ReleaseProvider: FC<PropsWithChildren<ReleaseProviderProps>> = ({
const [state, dispatch] = useReducer(releaseReducer, {
...initialState,
releases: releases,
release: initialRelease,
});

const actions = useMemo(() => createDispatchActions(dispatch), [dispatch]);
Expand Down
1 change: 1 addition & 0 deletions types/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export interface ReleaseContextType
export interface ReleaseProviderProps {
children: ReactNode;
releases: Array<NodeRelease>;
initialRelease: NodeRelease;
}
Loading

0 comments on commit 2d595d2

Please sign in to comment.