Skip to content

Commit a5eb344

Browse files
authored
fix(compat): allow file/deep imports for components (#6394)
Related to #6344
1 parent d8a8df3 commit a5eb344

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

.storybook/components/DocsHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const InfoTable = ({ since, subComponents, mergeSubComponents }: InfoTabl
4848
const wcSubComponents = useGetSubComponentsOfModule(moduleName.replace('V2', ''));
4949
const subComps = mergeSubComponents
5050
? [...(subComponents ?? []), ...(wcSubComponents ?? [])]
51-
: subComponents ?? wcSubComponents;
51+
: (subComponents ?? wcSubComponents);
5252

5353
const supportsClipboardApi = typeof ClipboardItem !== 'undefined';
5454

.storybook/components/Import.tsx

+69-25
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,41 @@ interface ImportStatementPropTypes {
1111
*/
1212
packageName: string;
1313
}
14+
interface DeepPath {
15+
path: string;
16+
moduleName: string;
17+
}
18+
interface FromPathPropTypes extends Pick<ImportStatementPropTypes, 'packageName'> {
19+
deepPath?: null | undefined | DeepPath;
20+
}
21+
22+
function FromPath({ packageName, deepPath }: FromPathPropTypes) {
23+
return (
24+
<>
25+
<span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>from</span>
26+
<span> </span>
27+
<span style={{ color: 'rgb(0, 136, 0)', fontSize: '14px' }}>
28+
{deepPath ? packageName.slice(0, -1) : packageName}
29+
{deepPath && deepPath.path}
30+
{deepPath && "'"}
31+
</span>
32+
<span style={{ fontSize: '14px' }}>;</span>
33+
{deepPath && <br />}
34+
</>
35+
);
36+
}
1437

1538
export const ImportStatement = ({ moduleNames, packageName }: ImportStatementPropTypes) => {
1639
if (!moduleNames) {
1740
return null;
1841
}
42+
const isCompat = packageName.includes('compat');
43+
const paths = isCompat
44+
? moduleNames.map((item) => {
45+
return { path: `/dist/components/${item}/index.js`, moduleName: item };
46+
})
47+
: [null];
48+
1949
return (
2050
<pre
2151
data-import
@@ -31,32 +61,46 @@ export const ImportStatement = ({ moduleNames, packageName }: ImportStatementPro
3161
}}
3262
>
3363
<code style={{ whiteSpace: 'pre' }}>
34-
<span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>import</span>
35-
<span style={{ fontSize: '14px' }}>
36-
{' '}
37-
{'{'}
38-
{moduleNames.length > 2 ? (
39-
<>
40-
{moduleNames.map((item) => {
41-
return (
42-
<Fragment key={item}>
64+
{!paths[0] && <span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>import</span>}
65+
{paths.map((deepPath) => {
66+
if (!deepPath) {
67+
return (
68+
<span style={{ fontSize: '14px' }}>
69+
{' '}
70+
{'{'}
71+
{moduleNames.length > 2 ? (
72+
<>
73+
{moduleNames.map((item) => {
74+
return (
75+
<Fragment key={item}>
76+
<br />
77+
&nbsp;&nbsp;
78+
{item},
79+
</Fragment>
80+
);
81+
})}
4382
<br />
44-
&nbsp;&nbsp;
45-
{item},
46-
</Fragment>
47-
);
48-
})}
49-
<br />
50-
</>
51-
) : (
52-
<>&nbsp;{moduleNames.join(', ')}&nbsp;</>
53-
)}
54-
{'}'}{' '}
55-
</span>
56-
<span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>from</span>
57-
<span> </span>
58-
<span style={{ color: 'rgb(0, 136, 0)', fontSize: '14px' }}>{packageName}</span>
59-
<span style={{ fontSize: '14px' }}>;</span>
83+
</>
84+
) : (
85+
<>&nbsp;{moduleNames.join(', ')}&nbsp;</>
86+
)}
87+
{'}'}{' '}
88+
</span>
89+
);
90+
} else {
91+
return (
92+
<>
93+
<span style={{ color: 'rgb(0, 0, 136)', fontSize: '14px' }}>import</span>
94+
<span style={{ fontSize: '14px' }}>
95+
{' '}
96+
{'{'}&nbsp;{deepPath.moduleName}&nbsp;{'}'}{' '}
97+
</span>
98+
<FromPath packageName={packageName} deepPath={deepPath} />
99+
</>
100+
);
101+
}
102+
})}
103+
{!paths[0] && <FromPath packageName={packageName} />}
60104
</code>
61105
</pre>
62106
);

packages/compat/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"default": "./dist/index.js"
1313
},
1414
"./package.json": "./package.json",
15-
"./styles.css": "./dist/css/index.css"
15+
"./styles.css": "./dist/css/index.css",
16+
"./dist/*": "./dist/*",
17+
"./dist/*.js": "./dist/*.js"
1618
},
1719
"homepage": "https://sap.github.io/ui5-webcomponents-react",
1820
"repository": {

0 commit comments

Comments
 (0)