-
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.
* Component doc template * Fix build
- Loading branch information
Showing
9 changed files
with
253 additions
and
52 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...bsite/docs/components/buttons/buttons.mdx → ...ebsite/docs/components/buttons/button.mdx
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
--- | ||
slug: /buttons | ||
slug: /button | ||
--- | ||
|
||
# Buttons | ||
# Button | ||
|
||
<ComponentDescription componentName="Button" /> | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...website/docs/components/buttons/links.mdx → ...-website/docs/components/buttons/link.mdx
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
--- | ||
slug: /links | ||
slug: /link | ||
--- | ||
|
||
# Links | ||
# Link | ||
|
||
<ComponentDescription componentName="Link" /> | ||
|
||
|
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
64 changes: 53 additions & 11 deletions
64
@stellar/design-system-website/src/components/Element.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 |
---|---|---|
@@ -1,24 +1,66 @@ | ||
import React from "react"; | ||
import React, { Fragment, createElement } from "react"; | ||
import Link from "@docusaurus/Link"; | ||
import rehypeParse from "rehype-parse"; | ||
import rehypeReact from "rehype-react"; | ||
import rehypeSanitize from "rehype-sanitize"; | ||
import { unified } from "unified"; | ||
|
||
export type ElementKind = "text" | "code" | "inline-tag"; | ||
|
||
export const Element = ({ | ||
text, | ||
kind, | ||
}: { | ||
export interface ElementProps { | ||
text: string; | ||
kind: ElementKind; | ||
}) => { | ||
kind: ElementKind | string; | ||
tag?: string; | ||
} | ||
|
||
export const Element = ({ text, kind, tag }: ElementProps) => { | ||
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>; | ||
// Remove @ from tag to use as a slug for relative link | ||
return <Link to={`/${tag?.replace("@", "")}`}>{text}</Link>; | ||
// text is default | ||
default: | ||
// TODO: how to handle md links | ||
return <>{text}</>; | ||
return parseMarkdownString(text); | ||
} | ||
}; | ||
|
||
const parseMarkdownString = (text: string): React.ReactElement => { | ||
const matches = text.match(/\[.*?\)/g); | ||
|
||
if (matches) { | ||
for (const m of matches) { | ||
const linkText = m.match(/\[(.*?)\]/)[1]; | ||
const linkUrl = m.match(/\((.*?)\)/)[1]; | ||
|
||
// TODO: can check if it's relative link | ||
text = text.replace( | ||
m, | ||
`<a href="${linkUrl}" target="_blank" rel="noreferrer noopener">${linkText}</a>`, | ||
); | ||
} | ||
} | ||
|
||
text = parseLineBreak(text); | ||
|
||
const file = unified() | ||
.use(rehypeSanitize) | ||
.use(rehypeParse, { fragment: true }) | ||
.use(rehypeReact, { createElement, Fragment }) | ||
.processSync(text); | ||
|
||
return file.result; | ||
}; | ||
|
||
const parseLineBreak = (text: string) => { | ||
const lineBreakPattern = /\n\n$/i; | ||
const matches = text.match(lineBreakPattern); | ||
|
||
if (matches) { | ||
return `${text.replace(lineBreakPattern, "")}<br><br>`; | ||
} | ||
|
||
return text; | ||
}; |
17 changes: 17 additions & 0 deletions
17
@stellar/design-system-website/src/components/ElementPropType.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,17 @@ | ||
import React, { Fragment } from "react"; | ||
|
||
export const ElementPropType = ({ type }: { type: any }) => { | ||
switch (type.type) { | ||
case "union": | ||
return type.types.map((t, i) => ( | ||
<Fragment key={i}> | ||
<code>{t.value}</code>{" "} | ||
</Fragment> | ||
)); | ||
case "intrinsic": | ||
case "reference": | ||
return <code>{type.name}</code>; | ||
default: | ||
return ""; | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
@stellar/design-system-website/src/components/ParseSummary.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,12 @@ | ||
import React from "react"; | ||
import { Element } from "@site/src/components/Element"; | ||
|
||
export const ParseSummary = ({ summary }: { summary: any }) => { | ||
return ( | ||
<> | ||
{summary.map((s, i) => ( | ||
<Element text={s.text} kind={s.kind} key={i} tag={s.tag} /> | ||
))} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.