From 4a37fba1a0a6a44420f109232386eaa09d8dffa7 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Sun, 30 May 2021 15:45:19 -0700 Subject: [PATCH] Migrate custom docs components to typescript --- docs/src/components/Color.js | 9 ----- docs/src/components/Color.tsx | 18 ++++++++++ docs/src/components/Datetime.js | 7 ---- docs/src/components/Datetime.tsx | 16 +++++++++ docs/src/components/{Font.js => Font.tsx} | 11 +++++-- docs/src/components/JSXCode.js | 4 --- docs/src/components/JSXCode.tsx | 8 +++++ docs/src/components/MiniNote.js | 17 ---------- docs/src/components/MiniNote.tsx | 28 ++++++++++++++++ docs/src/components/Native.tsx | 9 +++++ docs/src/components/PageLink.js | 8 ----- docs/src/components/PageLink.tsx | 10 ++++++ docs/src/components/RegexPattern.js | 15 --------- docs/src/components/RegexPattern.tsx | 25 ++++++++++++++ docs/src/components/Required.js | 5 --- docs/src/components/Required.tsx | 11 +++++++ docs/src/components/styles.module.css | 40 +++++++++++++---------- 17 files changed, 157 insertions(+), 84 deletions(-) delete mode 100644 docs/src/components/Color.js create mode 100644 docs/src/components/Color.tsx delete mode 100644 docs/src/components/Datetime.js create mode 100644 docs/src/components/Datetime.tsx rename docs/src/components/{Font.js => Font.tsx} (62%) delete mode 100644 docs/src/components/JSXCode.js create mode 100644 docs/src/components/JSXCode.tsx delete mode 100644 docs/src/components/MiniNote.js create mode 100644 docs/src/components/MiniNote.tsx create mode 100644 docs/src/components/Native.tsx delete mode 100644 docs/src/components/PageLink.js create mode 100644 docs/src/components/PageLink.tsx delete mode 100644 docs/src/components/RegexPattern.js create mode 100644 docs/src/components/RegexPattern.tsx delete mode 100644 docs/src/components/Required.js create mode 100644 docs/src/components/Required.tsx diff --git a/docs/src/components/Color.js b/docs/src/components/Color.js deleted file mode 100644 index bda34200..00000000 --- a/docs/src/components/Color.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from "react"; -import styles from "./styles.module.css"; - -export default ({ hex }) => ( -
- - {hex} -
-); diff --git a/docs/src/components/Color.tsx b/docs/src/components/Color.tsx new file mode 100644 index 00000000..7c2864e9 --- /dev/null +++ b/docs/src/components/Color.tsx @@ -0,0 +1,18 @@ +import * as React from "react"; +import styles from "./styles.module.css"; + +type ColorProps = { + hex: string; +}; + +const Color = (props: React.PropsWithChildren): JSX.Element => { + const { hex } = props; + return ( +
+ + {hex} +
+ ); +}; + +export default Color; diff --git a/docs/src/components/Datetime.js b/docs/src/components/Datetime.js deleted file mode 100644 index 9830cae1..00000000 --- a/docs/src/components/Datetime.js +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -export default ({ year = false, ...props }) => { - const date = new Date(); - const granularity = year ? date.getFullYear() : date.toString(); - return {granularity}; -}; diff --git a/docs/src/components/Datetime.tsx b/docs/src/components/Datetime.tsx new file mode 100644 index 00000000..4c811d8c --- /dev/null +++ b/docs/src/components/Datetime.tsx @@ -0,0 +1,16 @@ +import * as React from "react"; + +type DatetimeProps = { + year?: boolean; +}; + +const Datetime = ( + props: React.PropsWithChildren +): JSX.Element => { + const { year } = props; + const date = new Date(); + const granularity = year ? date.getFullYear() : date.toString(); + return {granularity}; +}; + +export default Datetime; diff --git a/docs/src/components/Font.js b/docs/src/components/Font.tsx similarity index 62% rename from docs/src/components/Font.js rename to docs/src/components/Font.tsx index 510c0bdc..e6bb20a5 100644 --- a/docs/src/components/Font.js +++ b/docs/src/components/Font.tsx @@ -1,8 +1,13 @@ -import React from "react"; +import * as React from "react"; import clsx from "clsx"; import styles from "./fonts.module.css"; -export default ({ name }) => { +type FontProps = { + name: string; +}; + +const Font = (props: React.PropsWithChildren): JSX.Element => { + const { name } = props; const fontClass = { Nunito: "fontBody", "Fira Code": "fontMono" }; return ( @@ -10,3 +15,5 @@ export default ({ name }) => { ); }; + +export default Font; diff --git a/docs/src/components/JSXCode.js b/docs/src/components/JSXCode.js deleted file mode 100644 index 67122899..00000000 --- a/docs/src/components/JSXCode.js +++ /dev/null @@ -1,4 +0,0 @@ -import React from "react"; -import styles from "./styles.module.css"; - -export default ({ children }) => {children}; diff --git a/docs/src/components/JSXCode.tsx b/docs/src/components/JSXCode.tsx new file mode 100644 index 00000000..48de6ed8 --- /dev/null +++ b/docs/src/components/JSXCode.tsx @@ -0,0 +1,8 @@ +import * as React from "react"; +import styles from "./styles.module.css"; + +const JSXCode = (props: React.ComponentProps<"span">): JSX.Element => { + return ; +}; + +export default JSXCode; diff --git a/docs/src/components/MiniNote.js b/docs/src/components/MiniNote.js deleted file mode 100644 index c59d885a..00000000 --- a/docs/src/components/MiniNote.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from "react"; - -export default ({ children, newLine = true }) => ( - <> - {newLine &&
} - - {children} - - -); diff --git a/docs/src/components/MiniNote.tsx b/docs/src/components/MiniNote.tsx new file mode 100644 index 00000000..4086adce --- /dev/null +++ b/docs/src/components/MiniNote.tsx @@ -0,0 +1,28 @@ +import * as React from "react"; + +type MiniNodeProps = { + newLine: boolean; +}; + +const MiniNote = ( + props: React.PropsWithChildren +): JSX.Element => { + const { newLine, children } = props; + return ( + <> + {newLine &&
} + + {children} + + + ); +}; + +export default MiniNote; diff --git a/docs/src/components/Native.tsx b/docs/src/components/Native.tsx new file mode 100644 index 00000000..28e3ad2a --- /dev/null +++ b/docs/src/components/Native.tsx @@ -0,0 +1,9 @@ +import * as React from "react"; +import styles from "./styles.module.css"; + +const Native = (props: React.ComponentProps<"span">): JSX.Element => { + const { children } = props; + return {children}; +}; + +export default Native; diff --git a/docs/src/components/PageLink.js b/docs/src/components/PageLink.js deleted file mode 100644 index 5ac54cbb..00000000 --- a/docs/src/components/PageLink.js +++ /dev/null @@ -1,8 +0,0 @@ -import React from "react"; -import Link from "@docusaurus/Link"; - -export default ({ children, to }) => ( - - {children} - -); diff --git a/docs/src/components/PageLink.tsx b/docs/src/components/PageLink.tsx new file mode 100644 index 00000000..81f50916 --- /dev/null +++ b/docs/src/components/PageLink.tsx @@ -0,0 +1,10 @@ +import * as React from "react"; +import Link from "@docusaurus/Link"; + +import type { LinkProps } from "@docusaurus/Link"; + +const PageLink = (props: React.PropsWithChildren): JSX.Element => { + return ; +}; + +export default PageLink; diff --git a/docs/src/components/RegexPattern.js b/docs/src/components/RegexPattern.js deleted file mode 100644 index e0c7b1bd..00000000 --- a/docs/src/components/RegexPattern.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from "react"; -import Code from "./JSXCode"; - -const patternMap = { - aspath_asdot: String.raw`^(\^|^\_)((\d+\.\d+)\_|(\d+\.\d+)\$|(\d+\.\d+)\(\_\.\+\_\))+$`, - aspath_asplain: String.raw`^(\^|^\_)(\d+\_|\d+\$|\d+\(\_\.\+\_\))+$`, - community_decimal: String.raw`^[0-9]{1,10}$`, - community_extended: String.raw`^([0-9]{0,5})\:([0-9]{1,5})$`, - community_large: String.raw`^([0-9]{1,10})\:([0-9]{1,10})\:[0-9]{1,10}$` -}; - -export default ({ pattern }) => { - const thisPattern = patternMap[pattern]; - return '{thisPattern}'; -}; diff --git a/docs/src/components/RegexPattern.tsx b/docs/src/components/RegexPattern.tsx new file mode 100644 index 00000000..c2b4ba39 --- /dev/null +++ b/docs/src/components/RegexPattern.tsx @@ -0,0 +1,25 @@ +import * as React from "react"; +import { useMemo } from "react"; +import Code from "./JSXCode"; + +const PATTERN_MAP = { + aspath_asdot: String.raw`^(\^|^\_)((\d+\.\d+)\_|(\d+\.\d+)\$|(\d+\.\d+)\(\_\.\+\_\))+$`, + aspath_asplain: String.raw`^(\^|^\_)(\d+\_|\d+\$|\d+\(\_\.\+\_\))+$`, + community_decimal: String.raw`^[0-9]{1,10}$`, + community_extended: String.raw`^([0-9]{0,5})\:([0-9]{1,5})$`, + community_large: String.raw`^([0-9]{1,10})\:([0-9]{1,10})\:[0-9]{1,10}$`, +}; + +type RegexPatternProps = { + pattern: keyof typeof PATTERN_MAP; +}; + +const RegexPattern = ( + props: React.PropsWithChildren +): JSX.Element => { + const { pattern } = props; + const thisPattern = useMemo(() => PATTERN_MAP[pattern], [pattern]); + return '{thisPattern}'; +}; + +export default RegexPattern; diff --git a/docs/src/components/Required.js b/docs/src/components/Required.js deleted file mode 100644 index f615549e..00000000 --- a/docs/src/components/Required.js +++ /dev/null @@ -1,5 +0,0 @@ -import React from "react"; - -export default () => ( - * -); diff --git a/docs/src/components/Required.tsx b/docs/src/components/Required.tsx new file mode 100644 index 00000000..14a36b53 --- /dev/null +++ b/docs/src/components/Required.tsx @@ -0,0 +1,11 @@ +import * as React from "react"; + +const Required = (): JSX.Element => { + return ( + + * + + ); +}; + +export default Required; diff --git a/docs/src/components/styles.module.css b/docs/src/components/styles.module.css index 95e46f2f..1ad1ee47 100644 --- a/docs/src/components/styles.module.css +++ b/docs/src/components/styles.module.css @@ -1,25 +1,31 @@ .code { - background-color: var(--ifm-code-background); - color: var(--ifm-code-color); - font-family: var(--ifm-font-family-monospace); - font-size: var(--ifm-code-font-size); - border-radius: var(--ifm-code-border-radius); - margin: 0; - padding: var(--ifm-code-padding-vertical) var(--ifm-code-padding-horizontal); - font-style: normal; + background-color: var(--ifm-code-background); + color: var(--ifm-code-color); + font-family: var(--ifm-font-family-monospace); + font-size: var(--ifm-code-font-size); + border-radius: var(--ifm-code-border-radius); + margin: 0; + padding: var(--ifm-code-padding-vertical) var(--ifm-code-padding-horizontal); + font-style: normal; } .color { - border-radius: var(--ifm-global-radius); - display: inline-flex; - height: 1.5rem; - width: 1.5rem; - margin-right: 0.5rem; - padding: var(--ifm-code-padding-vertical) var(--ifm-code-padding-horizontal); + border-radius: var(--ifm-global-radius); + display: inline-flex; + height: 1.5rem; + width: 1.5rem; + margin-right: 0.5rem; + padding: var(--ifm-code-padding-vertical) var(--ifm-code-padding-horizontal); } .colorCode { - display: flex; - align-items: center; - justify-content: space-between; + display: flex; + align-items: center; + justify-content: space-between; +} + +.Native { + /* color: var(--ifm-link-color); */ + color: var(--ifm-color-success); + font-weight: bold; }