Skip to content

Commit a19ca6c

Browse files
Adds link to beta docs (#8998)
* add navitem accent and beta docs * filter out 'Beta Docs' from expected navigation translations in tests * refactor test * align nav accent to secondary button
1 parent e5fb9d1 commit a19ca6c

10 files changed

Lines changed: 63 additions & 11 deletions

File tree

apps/site/components/withNavBar.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ const WithNavBar: FC = () => {
5454
<WithBanner section="index" />
5555

5656
<NavBar
57-
navItems={navigationItems.map(([, { label, link, target }]) => ({
58-
link,
59-
text: label,
60-
target,
61-
}))}
57+
navItems={navigationItems.map(
58+
([, { label, link, target, accent }]) => ({
59+
link,
60+
text: label,
61+
target,
62+
accent,
63+
})
64+
)}
6265
pathname={pathname}
6366
as={Link}
6467
Logo={WithNodejsLogo}

apps/site/hooks/useSiteNavigation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type MappedNavigationEntry = {
1919
label: FormattedMessage;
2020
link: string;
2121
target?: HTMLAttributeAnchorTarget | undefined;
22+
accent?: boolean;
2223
};
2324

2425
// Provides Context replacement for variables within the Link. This is also something that is not going
@@ -44,13 +45,14 @@ const useSiteNavigation = () => {
4445
t.rich(label, context[key] || {}) as FormattedMessage;
4546

4647
return Object.entries(entries).map(
47-
([key, { label, link, items, target }]): [
48+
([key, { label, link, items, target, accent }]): [
4849
string,
4950
MappedNavigationEntry,
5051
] => [
5152
key,
5253
{
5354
target,
55+
accent,
5456
label: label ? getFormattedMessage(label, key) : '',
5557
link: link ? replaceLinkWithContext(link, context[key]) : '',
5658
items: items ? mapNavigationEntries(items, context) : [],

apps/site/navigation.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"link": "https://nodejs.org/docs/latest/api/",
2121
"label": "components.containers.navBar.links.docs"
2222
},
23+
"betaDocs": {
24+
"link": "https://beta.docs.nodejs.org/",
25+
"label": "components.containers.navBar.links.betaDocs",
26+
"target": "_blank",
27+
"accent": true
28+
},
2329
"contribute": {
2430
"link": "https://github.com/nodejs/node/blob/main/CONTRIBUTING.md",
2531
"label": "components.containers.navBar.links.contribute",

apps/site/tests/e2e/general-behavior.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const locators = {
1010
mobileMenuToggleName:
1111
englishLocale.components.containers.navBar.controls.toggle,
1212
navLinksLocator: `[aria-label="${englishLocale.components.containers.navBar.controls.toggle}"] + div`,
13+
// The Beta Docs link renders untranslated (English) across locales, so we
14+
// match on its English label to skip it during translation checks.
15+
betaDocsName: englishLocale.components.containers.navBar.links.betaDocs,
1316
// Global UI controls
1417
languageDropdownName: englishLocale.components.common.languageDropdown.label,
1518
themeToggleName: englishLocale.components.header.buttons.theme,
@@ -55,8 +58,14 @@ const verifyTranslation = async (page: Page, locale: Locale | string) => {
5558

5659
// Verify each navigation link text matches an expected translation
5760
for (const link of links) {
58-
const linkText = await link.textContent();
59-
expect(expectedTexts).toContain(linkText!.trim());
61+
const linkText = (await link.textContent())!.trim();
62+
// Skip the Beta Docs link: it renders untranslated (English) across
63+
// locales and has no translation entry in most locale files, so it
64+
// won't appear in `expectedTexts` for non-English locales (e.g. es).
65+
if (linkText === locators.betaDocsName) {
66+
continue;
67+
}
68+
expect(expectedTexts).toContain(linkText);
6069
}
6170
};
6271

apps/site/types/navigation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type NavigationKeys =
1616
| 'about'
1717
| 'download'
1818
| 'docs'
19+
| 'betaDocs'
1920
| 'getInvolved'
2021
| 'certification'
2122
| 'learn'
@@ -26,6 +27,7 @@ export type NavigationEntry = {
2627
link?: string;
2728
items?: Record<string, NavigationEntry>;
2829
target?: HTMLAttributeAnchorTarget | undefined;
30+
accent?: boolean;
2931
};
3032

3133
export type SiteNavigation = {

packages/i18n/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"about": "About",
3737
"download": "Download",
3838
"docs": "Docs",
39+
"betaDocs": "Beta Docs",
3940
"guides": "Guides",
4041
"learn": "Learn",
4142
"security": "Security",

packages/ui-components/src/Containers/NavBar/NavItem/index.module.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
gap-2
77
rounded-sm
88
px-3
9-
py-2;
9+
py-2
10+
motion-safe:transition-colors;
1011

1112
.label {
1213
@apply text-base
@@ -45,6 +46,19 @@
4546
}
4647
}
4748

49+
&.accent {
50+
@apply bg-transparent
51+
ring-1
52+
ring-neutral-200
53+
ring-inset
54+
dark:ring-neutral-900;
55+
56+
&:hover {
57+
@apply bg-neutral-200
58+
dark:bg-neutral-900;
59+
}
60+
}
61+
4862
&.footer {
4963
.label {
5064
@apply text-neutral-800

packages/ui-components/src/Containers/NavBar/NavItem/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type NavItemProps = {
1515
type?: NavItemType;
1616
className?: string;
1717
target?: HTMLAttributeAnchorTarget | undefined;
18+
accent?: boolean;
1819

1920
pathname: string;
2021
active?: boolean;
@@ -27,12 +28,18 @@ const NavItem: FC<PropsWithChildren<NavItemProps>> = ({
2728
children,
2829
className,
2930
target,
31+
accent,
3032
...props
3133
}) => (
3234
<BaseActiveLink
3335
target={target}
3436
href={href}
35-
className={classNames(styles.navItem, styles[type], className)}
37+
className={classNames(
38+
styles.navItem,
39+
styles[type],
40+
{ [styles.accent]: accent },
41+
className
42+
)}
3643
activeClassName={styles.active}
3744
allowSubPath={href.startsWith('/')}
3845
{...props}

packages/ui-components/src/Containers/NavBar/index.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export const Default: Story = {
2626
text: 'Docs',
2727
link: '/docs',
2828
},
29+
{
30+
text: 'Beta Docs',
31+
link: 'https://beta.docs.nodejs.org/',
32+
target: '_blank',
33+
accent: true,
34+
},
2935
{
3036
text: 'Download',
3137
link: '/download',

packages/ui-components/src/Containers/NavBar/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type NavbarProps = {
3838
text: FormattedMessage;
3939
link: string;
4040
target?: HTMLAttributeAnchorTarget | undefined;
41+
accent?: boolean;
4142
}>;
4243
Logo?: ElementType;
4344
as: LinkLike;
@@ -92,14 +93,15 @@ const NavBar: FC<PropsWithChildren<NavbarProps>> = ({
9293
<div className={classNames(styles.main, `hidden peer-checked:flex`)}>
9394
{navItems && navItems.length > 0 && (
9495
<div className={styles.navItems}>
95-
{navItems.map(({ text, link, target }) => (
96+
{navItems.map(({ text, link, target, accent }) => (
9697
<NavItem
9798
pathname={pathname}
9899
active={link === activeLink}
99100
as={Component}
100101
key={link}
101102
href={link}
102103
target={target}
104+
accent={accent}
103105
>
104106
{text}
105107
</NavItem>

0 commit comments

Comments
 (0)