Skip to content

Commit

Permalink
docs: correct extends link annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Oct 2, 2023
1 parent fb3f65f commit a4e31a7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 37 deletions.
7 changes: 5 additions & 2 deletions docs/component-docs-plugin/generatePageMDX.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ function generatePropsTable(data, link) {
</div>
<PropTable componentLink="${link}" prop="${prop}" />
---
`;
})
.join('');

return `
## Props
<ExtendsLink componentLink="${link}" />
---
${props}
`;
}
Expand Down Expand Up @@ -157,6 +159,7 @@ title: ${doc.title}
---
import PropTable from '@site/src/components/PropTable.tsx';
import ExtendsLink from '@site/src/components/ExtendsLink.tsx';
import ThemeColorsTable from '@site/src/components/ThemeColorsTable.tsx';
import ScreenshotTabs from '@site/src/components/ScreenshotTabs.tsx';
Expand Down
48 changes: 48 additions & 0 deletions docs/src/components/ExtendsLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';

// @ts-ignore
// eslint-disable-next-line import/no-unresolved
import useDoc from '@site/component-docs-plugin/useDocs';

const ANNOTATION_EXTENDS = '@extends';

export default function ExtendsLink({
componentLink,
}: {
componentLink: string;
}) {
const doc = useDoc(componentLink);

const extendsAttributes: { name: string; link?: string }[] = [];
doc?.description
.split('\n')
.filter((line: string) => {
if (line.startsWith(ANNOTATION_EXTENDS)) {
const parts = line.split(' ').slice(1);
const link = parts.pop();
extendsAttributes.push({
name: parts.join(' '),
link,
});
return false;
}
return true;
})
.join('\n');

if (extendsAttributes.length === 0) {
return null;
}

return extendsAttributes.map((prop) => (
<div key={prop.name}>
<i>Extends: </i>
<a key={prop.name} href={prop.link}>
<code>
...
{prop.name}
</code>
</a>
</div>
));
}
35 changes: 0 additions & 35 deletions docs/src/components/PropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,13 @@ const typeDefinitions = {
'StyleProp<TextStyle>': 'https://reactnative.dev/docs/text-style-props',
};

const ANNOTATION_EXTENDS = '@extends';

const renderBadge = (annotation: string) => {
const [annotType, ...annotLabel] = annotation.split(' ');

// eslint-disable-next-line prettier/prettier
return `<span class="badge badge-${annotType.replace('@', '')} ">${annotLabel.join(' ')}</span>`;
};

const renderExtendsLink = (description: string) => {
const extendsAttributes: { name: string; link?: string }[] = [];
description
.split('\n')
.filter((line: string) => {
if (line.startsWith(ANNOTATION_EXTENDS)) {
const parts = line.split(' ').slice(1);
const link = parts.pop();
extendsAttributes.push({
name: parts.join(' '),
link,
});
return false;
}
return true;
})
.join('\n');

if (extendsAttributes.length === 0) {
return null;
}

return extendsAttributes.map((prop) => (
<a key={prop.name} href={prop.link}>
<code>
...
{prop.name}
</code>
</a>
));
};

export default function PropTable({
componentLink,
prop,
Expand Down Expand Up @@ -132,7 +98,6 @@ export default function PropTable({
</div>
);
})}
{renderExtendsLink(doc.description)}
</div>
);
}

0 comments on commit a4e31a7

Please sign in to comment.