Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breadcrumbs-mobile-length.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-core/ui-components': minor
---

`Breadcrumbs` takes a `mobileMaxLength`, truncating further below the `sm` breakpoint through CSS.
5 changes: 5 additions & 0 deletions .changeset/language-dropdown-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-core/ui-components': minor
---

`LanguageDropDown` renders a link per language, through `href` and an `as` component that receives the `locale`, replacing `onChange`.
5 changes: 5 additions & 0 deletions .changeset/navbar-stateless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-core/ui-components': patch
---

`NavBar` keeps no state, so it can be rendered from a React Server Component.
5 changes: 5 additions & 0 deletions .changeset/sidebar-mobile-disclosure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-core/ui-components': minor
---

`Sidebar` collapses its navigation behind a native disclosure on mobile instead of duplicating every page into a `Select`. The `onSelect` prop is removed and `ref` is optional.
29 changes: 18 additions & 11 deletions apps/site/app/[locale]/error.tsx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoiw is this related?

Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
'use client';

import GlowingBackdrop from '@node-core/ui-components/Common/GlowingBackdrop';
import { useTranslations } from 'next-intl';

import Button from '#site/components/Common/Button';
import GlowingBackdropLayout from '#site/layouts/GlowingBackdrop';
import styles from '#site/layouts/layouts.module.css';

import type { FC } from 'react';

const ErrorPage: FC<{ error: Error }> = () => {
const t = useTranslations();

// Error boundaries are Client Components, so this cannot use the layouts,
// whose navigation and footer are rendered on the server
return (
<GlowingBackdropLayout kind="default">
<span>500</span>
<div className={styles.centeredLayout}>
<GlowingBackdrop />

<h1 className="special -mt-4 text-center">
{t('layouts.error.internalServerError.title')}
</h1>
<main id="main" tabIndex={-1}>
<span>500</span>

<p className="-mt-4 max-w-sm text-center text-lg">
{t('layouts.error.internalServerError.description')}
</p>
<h1 className="special -mt-4 text-center">
{t('layouts.error.internalServerError.title')}
</h1>

<Button href="/">{t('layouts.error.backToHome')}</Button>
</GlowingBackdropLayout>
<p className="-mt-4 max-w-sm text-center text-lg">
{t('layouts.error.internalServerError.description')}
</p>

<Button href="/">{t('layouts.error.backToHome')}</Button>
</main>
</div>
);
};

Expand Down
34 changes: 0 additions & 34 deletions apps/site/components/AvatarGroup.tsx

This file was deleted.

32 changes: 32 additions & 0 deletions apps/site/components/AvatarGroup/Avatars.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client';

import AvatarGroupContainer from '@node-core/ui-components/Common/AvatarGroup';

import Link from '#site/components/Link';
import useMediaQuery from '#site/hooks/useMediaQuery';

import type { ComponentProps, FC } from 'react';

type AvatarsProps = Omit<ComponentProps<typeof AvatarGroupContainer>, 'as'> & {
compactLimit?: number;
};

const Avatars: FC<AvatarsProps> = ({
limit,
compactLimit = limit,
...props
}) => {
// Since we cannot always show the same number of avatars in Mobile / Tablet
// resolution as we do on desktop, `compactLimit` applies to the resolutions below
const isSmallerThanDesktop = useMediaQuery('(max-width: 1280px)');

return (
<AvatarGroupContainer
as={Link}
limit={isSmallerThanDesktop ? compactLimit : limit}
{...props}
/>
);
};

export default Avatars;
21 changes: 21 additions & 0 deletions apps/site/components/AvatarGroup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getAuthors } from '#site/util/author';

import type { AuthorProps } from '#site/types';
import type { ComponentProps, FC } from 'react';

import Avatars from './Avatars';

type AvatarGroupProps = Omit<ComponentProps<typeof Avatars>, 'avatars'> &
AuthorProps;

// Resolves the authors on the server, so `authors.json` stays there
const AvatarGroup: FC<AvatarGroupProps> = ({
usernames,
names,
clickable = true,
...props
}) => (
<Avatars avatars={getAuthors({ usernames, names, clickable })} {...props} />
);

export default AvatarGroup;
64 changes: 9 additions & 55 deletions apps/site/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,26 @@
'use client';

import BreadcrumbsContainer from '@node-core/ui-components/Common/Breadcrumbs';
import { useTranslations } from 'next-intl';
import { getTranslations } from 'next-intl/server';

import { getClientContext } from '#site/client-context';
import Link from '#site/components/Link';
import useClientContext from '#site/hooks/useClientContext';
import useMediaQuery from '#site/hooks/useMediaQuery';
import useSiteNavigation from '#site/hooks/useSiteNavigation';
import { dashToCamelCase } from '#site/util/string';
import { getBreadcrumbs, getSideNavigation } from '#site/util/navigation';

import type { NavigationKeys } from '#site/types';
import type { BreadcrumbLink } from '@node-core/ui-components/Common/Breadcrumbs';
import type { FC } from 'react';

type BreadcrumbsProps = {
navKeys?: Array<NavigationKeys>;
};

const Breadcrumbs: FC<BreadcrumbsProps> = ({ navKeys = [] }) => {
const { getSideNavigation } = useSiteNavigation();
const t = useTranslations();
const { pathname } = useClientContext();
const isMobileScreen = useMediaQuery('(max-width: 639px)');

const maxLength = isMobileScreen ? 2 : 4;

const getBreadcrumbs = () => {
const navigationTree = getSideNavigation(navKeys);

const pathList = pathname
.split('/')
.filter(item => item !== '')
.map(dashToCamelCase);

let currentNode = navigationTree;

// Reduce the pathList to a breadcrumbs array by finding each path in the current navigation layer,
// updating the currentNode to the found node's items(next layer) for the next iteration.
return pathList.reduce((breadcrumbs, path, index) => {
const nodeWithCurrentPath = currentNode.find(
([nodePath, entry]) =>
// Checking link in cases where nodePath cannot = path. Like 'discoverJavaScriptTimers'
(nodePath === path || entry.link === pathname) &&
// Skip checking child path if it is the last path since there is no more child item inside
(index === pathList.length - 1 ||
entry.items.some(
([childPath, entry]) =>
childPath === pathList[index + 1] || entry.link === pathname
))
);

if (nodeWithCurrentPath) {
const [, { label, link = '', items = [] }] = nodeWithCurrentPath;

// Goes deeper on the tree of items if there are any.
currentNode = items;

return label ? [...breadcrumbs, { label, href: link }] : breadcrumbs;
}

return breadcrumbs;
}, [] as Array<BreadcrumbLink>);
};
const Breadcrumbs: FC<BreadcrumbsProps> = async ({ navKeys = [] }) => {
const t = await getTranslations();
const { pathname } = getClientContext();

return (
<BreadcrumbsContainer
links={getBreadcrumbs()}
maxLength={maxLength}
links={getBreadcrumbs(getSideNavigation(t, navKeys), pathname)}
maxLength={4}
mobileMaxLength={2}
as={Link}
homeLinkAriaLabel={t('components.common.breadcrumbs.navigateToHome')}
/>
Expand Down
10 changes: 3 additions & 7 deletions apps/site/components/CarbonAds/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
import classNames from 'classnames';

import useCarbonAd, { adColors } from '#site/hooks/useCarbonAd';
import useClientContext from '#site/hooks/useClientContext';

import type { Layouts } from '#site/types';
import type { FC } from 'react';

import styles from './index.module.css';

const CarbonSidebar: FC = () => {
const { frontmatter } = useClientContext();

const CarbonSidebar: FC<{ layout?: Layouts }> = ({ layout }) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add type CarbonSidebarProps for regularity

// Must match where each layout's grid gives the MetaBar a right-hand column
const media =
frontmatter.layout === 'blog-post'
? '(min-width: 896px)'
: '(min-width: 1280px)';
layout === 'blog-post' ? '(min-width: 896px)' : '(min-width: 1280px)';

const { ad, ref } = useCarbonAd('CWBI6KJU', media);

Expand Down
8 changes: 2 additions & 6 deletions apps/site/components/Downloads/DownloadButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { CloudArrowDownIcon } from '@heroicons/react/24/outline';
import classNames from 'classnames';

import { getClientContext } from '#site/client-context';
import Button from '#site/components/Common/Button';
import { getNodeDownloadUrl } from '#site/util/url';
import { getUserPlatform } from '#site/util/userAgent';

import type { NodeRelease } from '#site/types';
import type { FC, PropsWithChildren } from 'react';
Expand All @@ -17,10 +15,8 @@ const DownloadButton: FC<PropsWithChildren<DownloadButtonProps>> = ({
release: { versionWithPrefix },
children,
}) => {
const { os, bitness, architecture } = getClientContext();

const platform = getUserPlatform(architecture, bitness);
const downloadLink = getNodeDownloadUrl({ versionWithPrefix, os, platform });
// The OS is only known in the browser, so this links to the source tarball
const downloadLink = getNodeDownloadUrl({ versionWithPrefix });

return (
<>
Expand Down
13 changes: 1 addition & 12 deletions apps/site/components/Downloads/DownloadLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { getClientContext } from '#site/client-context';
import LinkWithArrow from '#site/components/Common/LinkWithArrow';
import { getNodeDownloadUrl } from '#site/util/url';
import { getUserPlatform } from '#site/util/userAgent';

import type { DownloadKind, NodeRelease } from '#site/types';
import type { FC, PropsWithChildren } from 'react';
Expand All @@ -13,16 +11,7 @@ const DownloadLink: FC<PropsWithChildren<DownloadLinkProps>> = ({
kind = 'installer',
children,
}) => {
const { os, bitness, architecture } = getClientContext();

const platform = getUserPlatform(architecture, bitness);

const downloadLink = getNodeDownloadUrl({
versionWithPrefix,
os,
platform,
kind,
});
const downloadLink = getNodeDownloadUrl({ versionWithPrefix, kind });

return <LinkWithArrow href={downloadLink}>{children}</LinkWithArrow>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Select from '@node-core/ui-components/Common/Select';
import { useTranslations } from 'next-intl';
import { use, useEffect, useMemo } from 'react';

import useClientContext from '#site/hooks/useClientContext';
import useDetectOS from '#site/hooks/useDetectOS';
import { ReleaseContext } from '#site/providers/releaseProvider';
import { nextItem, OPERATING_SYSTEMS, parseCompat } from '#site/util/download';

Expand All @@ -14,15 +14,15 @@ import type { FC } from 'react';
type OperatingSystemDropdownProps = { exclude?: Array<OperatingSystem> };

const OperatingSystemDropdown: FC<OperatingSystemDropdownProps> = () => {
const { os } = useClientContext();
const { os } = useDetectOS();
const release = use(ReleaseContext);
const t = useTranslations();

useEffect(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing this? This was intentional...

if (os !== 'LOADING') {
release.setOS(os);
}
// Reacts on Client Context change of OS
// Reacts on the detection of the OS
// Only this Hook is allowed to bypass the `setOS` from above
// As this Hook is what defined the initial OS state
// eslint-disable-next-line @eslint-react/exhaustive-deps
Expand Down
6 changes: 3 additions & 3 deletions apps/site/components/Downloads/Release/PlatformDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Select from '@node-core/ui-components/Common/Select';
import { useTranslations } from 'next-intl';
import { useEffect, use, useMemo, useState } from 'react';

import useClientContext from '#site/hooks/useClientContext';
import useDetectOS from '#site/hooks/useDetectOS';
import { ReleaseContext } from '#site/providers/releaseProvider';
import { PLATFORMS, nextItem, parseCompat } from '#site/util/download';
import { getUserPlatform } from '#site/util/userAgent';
Expand All @@ -13,7 +13,7 @@ import type { Platform } from '#site/types/userAgent';
import type { FC } from 'react';

const PlatformDropdown: FC = () => {
const { architecture, bitness } = useClientContext();
const { architecture, bitness } = useDetectOS();

const release = use(ReleaseContext);

Expand All @@ -37,7 +37,7 @@ const PlatformDropdown: FC = () => {
release.setPlatform(currentPlatform);
}
},
// Only react on the change of the Client Context Architecture and Bitness
// Only react on the change of the detected Architecture and Bitness
// eslint-disable-next-line @eslint-react/exhaustive-deps
[architecture, bitness]
);
Expand Down
Loading
Loading