Skip to content

Commit e6ea842

Browse files
authored
React icon export tagNames and exports refactor (#2819)
# Pull Request ## 🀨 Rationale - export tag names from the react wrappers - change icon file generation paths in a non-breaking way so `exports` config is simplified ## πŸ‘©β€πŸ’» Implementation See above ## πŸ§ͺ Testing Manually check react app didn't regress ## βœ… Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed.
1 parent 0ef15f7 commit e6ea842

66 files changed

Lines changed: 142 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Simplify icon export paths",
4+
"packageName": "@ni/nimble-react",
5+
"email": "rajsite@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

β€Žpackages/react-workspace/nimble-react/build/generate-icons.mjsβ€Ž

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@ if (fs.existsSync(iconsDirectory)) {
2323
}
2424
console.log(`Creating icons directory "${iconsDirectory}"`);
2525
fs.mkdirSync(iconsDirectory);
26-
2726
console.log('Finished creating icons directory');
2827

2928
console.log('Writing icon react wrapper files');
3029

3130
let fileCount = 0;
3231
for (const key of Object.keys(icons)) {
3332
const iconName = trimSizeFromName(key); // e.g. "arrowExpanderLeft"
33+
const directoryName = spinalCase(iconName); // e.g. "arrow-expander-left"
3434
const fileName = spinalCase(iconName); // e.g. "arrow-expander-left";
3535
const className = `Icon${pascalCase(iconName)}`; // e.g. "IconArrowExpanderLeft"
36+
const tagName = `icon${pascalCase(iconName)}Tag`; // e.g. "iconArrowExpanderLeftTag"
37+
const iconDirectory = path.resolve(iconsDirectory, directoryName);
38+
fs.mkdirSync(iconDirectory);
3639

3740
fileCount += 1;
3841

3942
const iconReactWrapperContent = `${generatedFilePrefix}
40-
import { ${className} } from '@ni/nimble-components/dist/esm/icons/${fileName}';
41-
import { wrap } from '../utilities/react-wrapper';
43+
import { ${className}, ${tagName} } from '@ni/nimble-components/dist/esm/icons/${fileName}';
44+
import { wrap } from '../../utilities/react-wrapper';
4245
43-
export { type ${className} };
46+
export type { ${className} };
47+
export { ${tagName} };
4448
export const Nimble${className} = wrap(${className});`;
4549

46-
const outputPath = path.resolve(iconsDirectory, `${fileName}.ts`);
50+
const outputPath = path.resolve(iconDirectory, 'index.ts');
4751
fs.writeFileSync(outputPath, iconReactWrapperContent, {
4852
encoding: 'utf-8'
4953
});

β€Žpackages/react-workspace/nimble-react/package.jsonβ€Ž

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"exports": {
1212
"./package.json": "./package.json",
1313
"./styles/*": "./styles/*",
14-
"./icons/*": {
15-
"types": "./dist/esm/icons/*.d.ts",
16-
"import": "./dist/esm/icons/*.js"
14+
".": {
15+
"types": "./dist/esm/index.d.ts",
16+
"import": "./dist/esm/index.js"
1717
},
1818
"./*": {
1919
"types": "./dist/esm/*.d.ts",
@@ -22,10 +22,8 @@
2222
},
2323
"typesVersions": {
2424
"*": {
25-
"icons/*": [
26-
"dist/esm/icons/*.d.ts"
27-
],
2825
"*": [
26+
"dist/esm/*",
2927
"dist/esm/*/index.d.ts"
3028
]
3129
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AnchorButton } from '@ni/nimble-components/dist/esm/anchor-button';
1+
import { AnchorButton, anchorButtonTag } from '@ni/nimble-components/dist/esm/anchor-button';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchorButtonTag };
45
export { type AnchorButton };
56
export const NimbleAnchorButton = wrap(AnchorButton);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AnchorMenuItem } from '@ni/nimble-components/dist/esm/anchor-menu-item';
1+
import { AnchorMenuItem, anchorMenuItemTag } from '@ni/nimble-components/dist/esm/anchor-menu-item';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchorMenuItemTag };
45
export { type AnchorMenuItem };
56
export const NimbleAnchorMenuItem = wrap(AnchorMenuItem);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AnchorTab } from '@ni/nimble-components/dist/esm/anchor-tab';
1+
import { AnchorTab, anchorTabTag } from '@ni/nimble-components/dist/esm/anchor-tab';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchorTabTag };
45
export { type AnchorTab };
56
export const NimbleAnchorTab = wrap(AnchorTab);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AnchorTabs } from '@ni/nimble-components/dist/esm/anchor-tabs';
1+
import { AnchorTabs, anchorTabsTag } from '@ni/nimble-components/dist/esm/anchor-tabs';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchorTabsTag };
45
export { type AnchorTabs };
56
export const NimbleAnchorTabs = wrap(AnchorTabs);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AnchorTreeItem } from '@ni/nimble-components/dist/esm/anchor-tree-item';
1+
import { AnchorTreeItem, anchorTreeItemTag } from '@ni/nimble-components/dist/esm/anchor-tree-item';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchorTreeItemTag };
45
export { type AnchorTreeItem };
56
export const NimbleAnchorTreeItem = wrap(AnchorTreeItem);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Anchor } from '@ni/nimble-components/dist/esm/anchor';
1+
import { Anchor, anchorTag } from '@ni/nimble-components/dist/esm/anchor';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchorTag };
45
export { type Anchor };
56
export const NimbleAnchor = wrap(Anchor);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AnchoredRegion } from '@ni/nimble-components/dist/esm/anchored-region';
1+
import { AnchoredRegion, anchoredRegionTag } from '@ni/nimble-components/dist/esm/anchored-region';
22
import { wrap } from '../utilities/react-wrapper';
33

4+
export { anchoredRegionTag };
45
export { type AnchoredRegion };
56
export const NimbleAnchoredRegion = wrap(AnchoredRegion);

0 commit comments

Comments
Β (0)