@node-core/ui-components 1.0.1-cb0d824ab7cb750f58e9e44fa89a98ee80500bd1 → 1.0.1-d93633adc3fedbaa88949b5d4c645b675dff41e9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/MDX/CodeTabs.js +19 -15
  2. package/package.json +1 -1
package/MDX/CodeTabs.js CHANGED
@@ -1,25 +1,29 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as TabsPrimitive from '@radix-ui/react-tabs';
3
+ import { useMemo } from 'react';
3
4
  import CodeTabs from '#ui/Common/CodeTabs';
4
5
  const NAME_OVERRIDES = {
5
6
  mjs: 'ESM',
6
7
  };
7
8
  const MDXCodeTabs = ({ languages: rawLanguages, displayNames: rawDisplayNames, children: codes, defaultTab = '0', ...props }) => {
8
- const languages = rawLanguages.split('|');
9
- const displayNames = rawDisplayNames?.split('|') ?? [];
10
- const occurrences = {};
11
- const tabs = languages.map((language, index) => {
12
- const base = displayNames[index]?.trim() ||
13
- NAME_OVERRIDES[language] ||
14
- language.toUpperCase();
15
- const count = occurrences[base] ?? 0;
16
- occurrences[base] = count + 1;
17
- const label = count > 0 ? `${base} (${count + 1})` : base;
18
- return {
19
- key: `${language}-${index}`,
20
- label: label,
21
- };
22
- });
9
+ const { tabs, languages } = useMemo(() => {
10
+ const occurrences = {};
11
+ const languages = rawLanguages.split('|');
12
+ const displayNames = rawDisplayNames?.split('|') ?? [];
13
+ const tabs = languages.map((language, index) => {
14
+ const base = displayNames[index]?.trim() ||
15
+ NAME_OVERRIDES[language] ||
16
+ language.toUpperCase();
17
+ const count = occurrences[base] ?? 0;
18
+ occurrences[base] = count + 1;
19
+ const label = count > 0 ? `${base} (${count + 1})` : base;
20
+ return {
21
+ key: `${language}-${index}`,
22
+ label: label,
23
+ };
24
+ });
25
+ return { tabs, languages };
26
+ }, [rawLanguages, rawDisplayNames]);
23
27
  return (_jsx(CodeTabs, { tabs: tabs, defaultValue: tabs[Number(defaultTab)].key, ...props, children: languages.map((_, index) => (_jsx(TabsPrimitive.Content, { value: tabs[index].key, children: codes[index] }, tabs[index].key))) }));
24
28
  };
25
29
  export default MDXCodeTabs;
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "engines": {
27
27
  "node": ">=20"
28
28
  },
29
- "version": "1.0.1-cb0d824ab7cb750f58e9e44fa89a98ee80500bd1",
29
+ "version": "1.0.1-d93633adc3fedbaa88949b5d4c645b675dff41e9",
30
30
  "scripts": {
31
31
  "compile:ts": "tsc",
32
32
  "compile:css": "postcss --dir dist --base src \"src/**/*.module.css\" src/styles/index.css",