Skip to content

Commit

Permalink
docs: add extends prop to the props list
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Oct 4, 2023
1 parent a4e31a7 commit 6b05c12
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
42 changes: 37 additions & 5 deletions docs/component-docs-plugin/generatePageMDX.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function generateScreenshots(componentName, screenshotData) {
`;
}

function generatePropsTable(data, link) {
function generatePropsTable(data, link, extendsAttributes) {
const ANNOTATION_OPTIONAL = '@optional';
const ANNOTATION_INTERNAL = '@internal';

Expand Down Expand Up @@ -128,14 +128,44 @@ function generatePropsTable(data, link) {

return `
## Props
<ExtendsLink componentLink="${link}" />
${
extendsAttributes.length === 0
? `<span />`
: `### ${extendsAttributes?.[0]?.name}`
}
${extendsAttributes
.map((attr) => {
return `<ExtendsLink name="${attr.name}" link="${attr.link}" />`;
})
.join('')}
---
${props}
`;
}

function generateExtendsAttributes(doc) {
const ANNOTATION_EXTENDS = '@extends';

const extendsAttributes = [];
doc?.description
.split('\n')
.filter((line) => {
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');

return extendsAttributes;
}

function generatePageMDX(doc, link) {
const summaryRegex = /([\s\S]*?)## Usage/;

Expand All @@ -153,6 +183,8 @@ function generatePageMDX(doc, link) {
const themeColorsData = JSON.stringify(customFields.themeColors[doc.title]);
const screenshotData = JSON.stringify(customFields.screenshots[doc.title]);

const extendsAttributes = generateExtendsAttributes(doc);

const mdx = `
---
title: ${doc.title}
Expand All @@ -169,7 +201,7 @@ ${generateScreenshots(doc.title, screenshotData)}
${usage}
${generatePropsTable(doc.data.props, link)}
${generatePropsTable(doc.data.props, link, extendsAttributes)}
${generateMoreExamples(doc.title)}
Expand Down
45 changes: 9 additions & 36 deletions docs/src/components/ExtendsLink.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,21 @@
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,
name,
link,
}: {
componentLink: string;
name: string;
link?: 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}>
return (
<div key={name} className="extends">
<i>Extends: </i>
<a key={prop.name} href={prop.link}>
<a key={name} href={link}>
<code>
...
{prop.name}
{name}
</code>
</a>
</div>
));
);
}
6 changes: 6 additions & 0 deletions docs/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,9 @@ a .badge .badge-text {
grid-template-columns: repeat(2, 1fr);
}
}

/* ExtendsLink.tsx */

.extends {
margin-bottom: 20px;
}

0 comments on commit 6b05c12

Please sign in to comment.