Skip to content

Commit

Permalink
Migrate custom docs components to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed May 30, 2021
1 parent c9febf3 commit 4a37fba
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 84 deletions.
9 changes: 0 additions & 9 deletions docs/src/components/Color.js

This file was deleted.

18 changes: 18 additions & 0 deletions docs/src/components/Color.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from "react";
import styles from "./styles.module.css";

type ColorProps = {
hex: string;
};

const Color = (props: React.PropsWithChildren<ColorProps>): JSX.Element => {
const { hex } = props;
return (
<div className={styles.colorCode}>
<span style={{ backgroundColor: hex }} className={styles.color} />
<span className={styles.code}>{hex}</span>
</div>
);
};

export default Color;
7 changes: 0 additions & 7 deletions docs/src/components/Datetime.js

This file was deleted.

16 changes: 16 additions & 0 deletions docs/src/components/Datetime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from "react";

type DatetimeProps = {
year?: boolean;
};

const Datetime = (
props: React.PropsWithChildren<DatetimeProps>
): JSX.Element => {
const { year } = props;
const date = new Date();
const granularity = year ? date.getFullYear() : date.toString();
return <span {...props}>{granularity}</span>;
};

export default Datetime;
11 changes: 9 additions & 2 deletions docs/src/components/Font.js → docs/src/components/Font.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
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<FontProps>): JSX.Element => {
const { name } = props;
const fontClass = { Nunito: "fontBody", "Fira Code": "fontMono" };
return (
<a href={`https://fonts.google.com/specimen/${name.split(" ").join("+")}`}>
<span className={clsx(styles.font, styles[fontClass[name]])}>{name}</span>
</a>
);
};

export default Font;
4 changes: 0 additions & 4 deletions docs/src/components/JSXCode.js

This file was deleted.

8 changes: 8 additions & 0 deletions docs/src/components/JSXCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from "react";
import styles from "./styles.module.css";

const JSXCode = (props: React.ComponentProps<"span">): JSX.Element => {
return <span className={styles.code} {...props} />;
};

export default JSXCode;
17 changes: 0 additions & 17 deletions docs/src/components/MiniNote.js

This file was deleted.

28 changes: 28 additions & 0 deletions docs/src/components/MiniNote.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from "react";

type MiniNodeProps = {
newLine: boolean;
};

const MiniNote = (
props: React.PropsWithChildren<MiniNodeProps>
): JSX.Element => {
const { newLine, children } = props;
return (
<>
{newLine && <br />}
<span
style={{
fontSize: "var(--ifm-font-size-sm)",
color: "var(--ifm-blockquote-color)",
display: "inline-block",
fontStyle: "italic",
}}
>
{children}
</span>
</>
);
};

export default MiniNote;
9 changes: 9 additions & 0 deletions docs/src/components/Native.tsx
Original file line number Diff line number Diff line change
@@ -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 <span className={styles.Native}>{children}</span>;
};

export default Native;
8 changes: 0 additions & 8 deletions docs/src/components/PageLink.js

This file was deleted.

10 changes: 10 additions & 0 deletions docs/src/components/PageLink.tsx
Original file line number Diff line number Diff line change
@@ -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<LinkProps>): JSX.Element => {
return <Link style={{ textDecoration: "unset" }} {...props} />;
};

export default PageLink;
15 changes: 0 additions & 15 deletions docs/src/components/RegexPattern.js

This file was deleted.

25 changes: 25 additions & 0 deletions docs/src/components/RegexPattern.tsx
Original file line number Diff line number Diff line change
@@ -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<RegexPatternProps>
): JSX.Element => {
const { pattern } = props;
const thisPattern = useMemo<string>(() => PATTERN_MAP[pattern], [pattern]);
return <Code>'{thisPattern}'</Code>;
};

export default RegexPattern;
5 changes: 0 additions & 5 deletions docs/src/components/Required.js

This file was deleted.

11 changes: 11 additions & 0 deletions docs/src/components/Required.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from "react";

const Required = (): JSX.Element => {
return (
<span style={{ color: "var(--ifm-color-danger)", display: "inline-block" }}>
*
</span>
);
};

export default Required;
40 changes: 23 additions & 17 deletions docs/src/components/styles.module.css
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4a37fba

Please sign in to comment.