Skip to content

Commit d93633a

Browse files
authored
fix: minor mdx component arrangement and type fix (#8041)
* fix: minor mdx component arrangement and type fix * Update CodeTabs.tsx Signed-off-by: Claudio Wunder <[email protected]> * Update CodeTabs.tsx Signed-off-by: Claudio Wunder <[email protected]> * chore: style fix --------- Signed-off-by: Claudio Wunder <[email protected]>
1 parent b33a5a4 commit d93633a

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

apps/site/next.mdx.use.client.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import Blockquote from '@node-core/ui-components/Common/Blockquote';
44
import MDXCodeTabs from '@node-core/ui-components/MDX/CodeTabs';
55

6-
import Button from './components/Common/Button';
76
import DownloadButton from './components/Downloads/DownloadButton';
87
import DownloadLink from './components/Downloads/DownloadLink';
98
import BlogPostLink from './components/Downloads/Release/BlogPostLink';
@@ -17,7 +16,6 @@ import ReleasePrebuiltDownloadButtons from './components/Downloads/Release/Prebu
1716
import ReleaseCodeBox from './components/Downloads/Release/ReleaseCodeBox';
1817
import ReleaseVersionDropdown from './components/Downloads/Release/VersionDropdown';
1918
import Link from './components/Link';
20-
import LinkWithArrow from './components/LinkWithArrow';
2119
import MDXCodeBox from './components/MDX/CodeBox';
2220
import MDXImage from './components/MDX/Image';
2321
import { ReleaseProvider } from './providers/releaseProvider';
@@ -30,12 +28,6 @@ import { ReleaseProvider } from './providers/releaseProvider';
3028
export const clientMdxComponents = {
3129
// Renders MDX CodeTabs
3230
CodeTabs: MDXCodeTabs,
33-
// Renders a Button Component for `button` tags
34-
Button: Button,
35-
// Links with External Arrow
36-
LinkWithArrow: LinkWithArrow,
37-
// Regular links (without arrow)
38-
Link: Link,
3931
// Renders a Download Button
4032
DownloadButton: DownloadButton,
4133
// Renders a Download Link

apps/site/next.mdx.use.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import BadgeGroup from '@node-core/ui-components/Common/BadgeGroup';
44

5+
import Button from './components/Common/Button';
56
import DownloadReleasesTable from './components/Downloads/DownloadReleasesTable';
7+
import Link from './components/Link';
8+
import LinkWithArrow from './components/LinkWithArrow';
69
import UpcomingMeetings from './components/MDX/Calendar/UpcomingMeetings';
710
import WithBadgeGroup from './components/withBadgeGroup';
811
import WithBanner from './components/withBanner';
@@ -25,4 +28,10 @@ export const mdxComponents = {
2528
BadgeGroup,
2629
// Renders an container for Upcoming Node.js Meetings
2730
UpcomingMeetings,
31+
// Renders a Button Component for `button` tags
32+
Button,
33+
// Regular links (without arrow)
34+
Link,
35+
// Links with External Arrow
36+
LinkWithArrow,
2837
};

apps/site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@opennextjs/cloudflare": "^1.6.0",
8383
"@playwright/test": "^1.54.1",
8484
"@testing-library/user-event": "~14.6.1",
85+
"@types/mdx": "^2.0.13",
8586
"@types/semver": "~7.7.0",
8687
"eslint-config-next": "15.4.3",
8788
"eslint-import-resolver-typescript": "~4.4.4",

apps/site/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"plugins": [{ "name": "next" }],
1818
"baseUrl": "."
1919
},
20+
"mdx": { "checkMdx": true },
2021
"include": [
2122
"next-env.d.ts",
2223
"global.d.ts",

packages/ui-components/src/MDX/CodeTabs.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as TabsPrimitive from '@radix-ui/react-tabs';
22
import type { FC, ReactElement } from 'react';
3+
import { useMemo } from 'react';
34

45
import CodeTabs from '#ui/Common/CodeTabs';
56

@@ -21,27 +22,32 @@ const MDXCodeTabs: FC<MDXCodeTabsProps> = ({
2122
defaultTab = '0',
2223
...props
2324
}) => {
24-
const languages = rawLanguages.split('|');
25-
const displayNames = rawDisplayNames?.split('|') ?? [];
25+
const { tabs, languages } = useMemo(() => {
26+
const occurrences: Record<string, number> = {};
2627

27-
const occurrences: Record<string, number> = {};
28+
const languages = rawLanguages.split('|');
29+
const displayNames = rawDisplayNames?.split('|') ?? [];
2830

29-
const tabs = languages.map((language, index) => {
30-
const base =
31-
displayNames[index]?.trim() ||
32-
NAME_OVERRIDES[language] ||
33-
language.toUpperCase();
31+
const tabs = languages.map((language, index) => {
32+
const base =
33+
displayNames[index]?.trim() ||
34+
NAME_OVERRIDES[language] ||
35+
language.toUpperCase();
3436

35-
const count = occurrences[base] ?? 0;
36-
occurrences[base] = count + 1;
37+
const count = occurrences[base] ?? 0;
3738

38-
const label = count > 0 ? `${base} (${count + 1})` : base;
39+
occurrences[base] = count + 1;
3940

40-
return {
41-
key: `${language}-${index}`,
42-
label: label,
43-
};
44-
});
41+
const label = count > 0 ? `${base} (${count + 1})` : base;
42+
43+
return {
44+
key: `${language}-${index}`,
45+
label: label,
46+
};
47+
});
48+
49+
return { tabs, languages };
50+
}, [rawLanguages, rawDisplayNames]);
4551

4652
return (
4753
<CodeTabs

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)