Skip to content

Commit cf67c70

Browse files
committed
Update index.js
1 parent 1bbc9a4 commit cf67c70

File tree

1 file changed

+60
-4
lines changed
  • plugins/docusaurus-plugin-ionic-component-api

1 file changed

+60
-4
lines changed

plugins/docusaurus-plugin-ionic-component-api/index.js

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ module.exports = function (context, options) {
1919
try {
2020
let COMPONENT_LINK_REGEXP;
2121
const response = await fetch(`https://unpkg.com/@ionic/docs@${npmTag}/core.json`);
22-
22+
2323
if (!response.ok) {
2424
console.error(`Failed to fetch component data for ${npmTag}: ${response.status}`);
2525
return;
2626
}
27-
27+
2828
const { components } = await response.json();
2929

3030
const names = components.map((component) => component.tag.slice(4));
@@ -54,7 +54,6 @@ module.exports = function (context, options) {
5454

5555
for (const version of options.versions) {
5656
const npmTag = version.slice(1);
57-
5857
await generateMarkdownForVersion(version, npmTag, false);
5958
}
6059

@@ -242,4 +241,61 @@ function renderCustomProps({ styles: customProps }) {
242241
const mdProps = customProps.filter((prop) => prop.mode === 'md');
243242

244243
const renderTable = (props) => {
245-
if
244+
if (props.length === 0) {
245+
return 'No CSS custom properties available for this component.';
246+
}
247+
248+
return `
249+
| Name | Description |
250+
| --- | --- |
251+
${props.map((prop) => `| \`${prop.name}\` | ${formatMultiline(prop.docs)} |`).join('\n')}
252+
`;
253+
};
254+
255+
if (iosProps.length > 0 || mdProps.length > 0) {
256+
// If the component has mode-specific custom props, render them in tabs for iOS and MD
257+
return `
258+
import Tabs from '@theme/Tabs';
259+
import TabItem from '@theme/TabItem';
260+
261+
\`\`\`\`mdx-code-block
262+
<Tabs
263+
groupId="mode"
264+
defaultValue="ios"
265+
values={[
266+
{ value: 'ios', label: 'iOS' },
267+
{ value: 'md', label: 'MD' },
268+
]
269+
}>
270+
<TabItem value="ios">
271+
272+
${renderTable(iosProps)}
273+
274+
</TabItem>
275+
276+
<TabItem value="md">
277+
278+
${renderTable(mdProps)}
279+
280+
</TabItem>
281+
</Tabs>
282+
\`\`\`\`
283+
284+
`;
285+
}
286+
// Otherwise render the custom props without the tabs for iOS and MD
287+
return renderTable(customProps);
288+
}
289+
290+
function renderSlots({ slots }) {
291+
if (slots.length === 0) {
292+
return 'No slots available for this component.';
293+
}
294+
295+
return `
296+
| Name | Description |
297+
| --- | --- |
298+
${slots.map((slot) => `| \`${slot.name}\` | ${formatMultiline(slot.docs)} |`).join('\n')}
299+
300+
`;
301+
}

0 commit comments

Comments
 (0)