-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quick example creating docs with TypeDoc (#159)
* Quick example creating docs with TypeDoc * Attempt to fix broken build * Fix gitignore
- Loading branch information
Showing
13 changed files
with
271 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ node_modules | |
*/**/dist | ||
*/**/build | ||
|
||
# SDS docs | ||
@stellar/design-system/docs | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
@stellar/design-system-website/src/components/ComponentDescription/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import SdsDocs from "@stellar/design-system/docs/components.json"; | ||
import { Element } from "@site/src/components/Element"; | ||
|
||
export const ComponentDescription = ({ | ||
componentName, | ||
}: { | ||
componentName: string; | ||
}) => { | ||
const component = SdsDocs?.children?.find( | ||
(c) => c.name === componentName && c.variant === "declaration", | ||
); | ||
|
||
if (!component) { | ||
throw Error(`Component "${componentName}" description not found.`); | ||
} | ||
|
||
// TODO: split paragraphs /n/n | ||
const description = component.comment.summary.map((s) => ( | ||
<Element text={s.text} kind={s.kind} /> | ||
)); | ||
|
||
return <p>{description}</p>; | ||
}; |
82 changes: 82 additions & 0 deletions
82
@stellar/design-system-website/src/components/ComponentProps/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from "react"; | ||
import SdsDocs from "@stellar/design-system/docs/components.json"; | ||
import { Element } from "@site/src/components/Element"; | ||
|
||
export const ComponentProps = ({ | ||
componentName, | ||
}: { | ||
componentName: string; | ||
}) => { | ||
const component = SdsDocs?.children?.find( | ||
(c) => c.name === `${componentName}Props` && c.variant === "declaration", | ||
); | ||
|
||
if (!component) { | ||
throw Error(`Component "${componentName}" props not found.`); | ||
} | ||
|
||
// TODO: reusable component | ||
// TODO: split paragraphs /n/n | ||
const description = component.comment.summary.map((s) => ( | ||
<Element text={s.text} kind={s.kind} key={s.id} /> | ||
)); | ||
|
||
const props = component.children.map((p) => { | ||
// TODO: handle this properly | ||
const defaultVal = p.comment?.blockTags?.[0]?.content?.[0]; | ||
|
||
return ( | ||
<tr key={p.id}> | ||
<td> | ||
<code>{p.name}</code> | ||
</td> | ||
<td> | ||
<PropType type={p.type} /> | ||
</td> | ||
<td> | ||
{defaultVal ? ( | ||
<Element text={defaultVal.text} kind={defaultVal.kind} /> | ||
) : null} | ||
</td> | ||
<td>{p?.flags?.isOptional ? "Yes" : ""}</td> | ||
{/* TODO: render summary properly */} | ||
<td>{p.comment.summary[0].text}</td> | ||
</tr> | ||
); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Prop</th> | ||
<th>Type</th> | ||
<th>Default</th> | ||
<th>Optional</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody>{props}</tbody> | ||
</table> | ||
<p>{description}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
// TODO: move to its own file | ||
// TODO: might be combined with Element? | ||
const PropType = ({ type }: { type: any }) => { | ||
// TODO: handle all types | ||
switch (type.type) { | ||
case "union": | ||
return type.types.map((t) => ( | ||
<> | ||
<code>{t.value}</code>{" "} | ||
</> | ||
)); | ||
default: | ||
// reference | ||
return <code>{type.name || ""}</code>; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
|
||
export type ElementKind = "text" | "code" | "inline-tag"; | ||
|
||
export const Element = ({ | ||
text, | ||
kind, | ||
}: { | ||
text: string; | ||
kind: ElementKind; | ||
}) => { | ||
switch (kind) { | ||
case "code": | ||
// Remove `` | ||
return <code>{text.slice(1, -1)}</code>; | ||
case "inline-tag": | ||
// TODO: link to inner component | ||
return <a href="#">{text}</a>; | ||
// text is default | ||
default: | ||
// TODO: how to handle md links | ||
return <>{text}</>; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import MDXComponents from "@theme-original/MDXComponents"; | ||
import { ComponentDescription } from "@site/src/components/ComponentDescription"; | ||
import { ComponentProps } from "@site/src/components/ComponentProps"; | ||
|
||
export default { | ||
...MDXComponents, | ||
ComponentDescription, | ||
ComponentProps, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "https://typedoc.org/schema.json", | ||
"entryPoints": ["src"], | ||
"json": "./docs/components.json", | ||
"excludeNotDocumented": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.