1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00

Migrate custom docs components to typescript

This commit is contained in:
checktheroads 2021-05-30 15:45:19 -07:00
parent c9febf39b7
commit 4a37fba1a0
17 changed files with 157 additions and 84 deletions

View file

@ -1,9 +0,0 @@
import React from "react";
import styles from "./styles.module.css";
export default ({ hex }) => (
<div className={styles.colorCode}>
<span style={{ backgroundColor: hex }} className={styles.color} />
<span className={styles.code}>{hex}</span>
</div>
);

View file

@ -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;

View file

@ -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 <span {...props}>{granularity}</span>;
};

View file

@ -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;

View file

@ -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<FontProps>): JSX.Element => {
const { name } = props;
const fontClass = { Nunito: "fontBody", "Fira Code": "fontMono" };
return (
<a href={`https://fonts.google.com/specimen/${name.split(" ").join("+")}`}>
@ -10,3 +15,5 @@ export default ({ name }) => {
</a>
);
};
export default Font;

View file

@ -1,4 +0,0 @@
import React from "react";
import styles from "./styles.module.css";
export default ({ children }) => <span className={styles.code}>{children}</span>;

View file

@ -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;

View file

@ -1,17 +0,0 @@
import React from "react";
export default ({ children, newLine = true }) => (
<>
{newLine && <br />}
<span
style={{
fontSize: "var(--ifm-font-size-sm)",
color: "var(--ifm-blockquote-color)",
display: "inline-block",
fontStyle: "italic"
}}
>
{children}
</span>
</>
);

View file

@ -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;

View file

@ -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;

View file

@ -1,8 +0,0 @@
import React from "react";
import Link from "@docusaurus/Link";
export default ({ children, to }) => (
<Link to={to} style={{ textDecoration: "unset" }}>
{children}
</Link>
);

View file

@ -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;

View file

@ -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 <Code>'{thisPattern}'</Code>;
};

View file

@ -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;

View file

@ -1,5 +0,0 @@
import React from "react";
export default () => (
<span style={{ color: "var(--ifm-color-danger)", display: "inline-block" }}>*</span>
);

View file

@ -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;

View file

@ -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;
}