-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmdx-components.tsx
165 lines (162 loc) · 5.76 KB
/
mdx-components.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import type {MDXComponents} from "mdx/types";
import Link from "next/link";
import Icon from "@/components/common/Icon";
import CodeBlock from "@/components/common/CodeBlock";
import Keycap from "@/components/common/Keycap";
import InlineCode from "@/components/common/InlineCode";
import Image from "next/image";
import {Table, Thead, Tbody, Tr, Th, Td} from "@/components/common/Table";
import AppCompat from "@/components/common/AppCompat";
import Noti from "@/components/common/Noti";
import Feature from "@/components/common/Feature";
import FeatureStatusNoti from "@/components/common/FeatureStatusNoti";
import MileStone from "@/components/common/MileStone";
import Details from "@/components/common/Details";
export const mdxComponents: MDXComponents = {
h2({children, ...p}) {
return (
<h2 {...p}>
{children}
</h2>
);
},
h3({children, ...p}) {
return (
<h3 className="sub" {...p}>
{children}
</h3>
);
},
h4({children, ...p}) {
return (
<h4 className="sub" {...p}>
{children}
</h4>
);
},
p({children}) {
return (<p className={"[&>svg]:relative [&>svg]:top-[-.05em] [&>svg]:z-0 [&>svg]:inline-block [&_.katex]:text-rel-base"}>{children}</p>)
},
Mark({children}) {
return (<mark className={"bg-yellow text-gray-800 font-bold"}>{children}</mark>);
},
Section({children}) {
return (<section className={"flex flex-col gap-[24px] w-full leading-normal section"}>{children}</section>);
},
ol({children, ...p}) {
return (<ol className={"flex flex-col gap-[2px]"} {...p}>{children}</ol>);
},
ul({children, ...p}) {
return (<ul {...p}>{children}</ul>);
},
li({children, ...p}) {
return (<li className={"leading-normal [&_ul]:ml-[1rem] [&_ol]:ml-[1rem]"} {...p}>{children}</li>);
},
img({...p}) {
return (
(p.alt === "icon") ?
<Icon className={"w-[.75rem] h-[.75rem] stroke-inherit-text"} icon={p.src as Icons}/>
:
<div
className={`justify-center items-center w-full h-fit ${(p.alt?.endsWith("#lightonly")) ? "flex dark:hidden" : ((p.alt?.endsWith("#darkonly")) ? "hidden dark:flex" : "")}`}>
<Image src={p.src as string} alt={p.alt || ""} className="rounded-[6px]"/>
</div>
)
},
Image(p) {
return (
<div
className={`justify-center items-center w-full h-fit ${(p.alt?.endsWith("#lightonly")) ? "flex dark:hidden" : ((p.alt?.endsWith("#darkonly")) ? "hidden dark:flex" : "")}`}>
<img src={p.src as string} alt={p.alt || ""} className="rounded-[6px]"/>
</div>
)
},
code({children, className}) {
const sthlMatch = /language-(\w+)/.exec(className || "");
const keyMatch = /key-(\w+|\W+)/.exec(children as string || "");
const content = String(children).replace(/\n$/, "");
return (
(sthlMatch) ?
<CodeBlock language={sthlMatch[1]} content={content}/>
:
(keyMatch) ?
<Keycap keytext={keyMatch[1]}/>
:
<InlineCode>{children}</InlineCode>
);
},
InlineCode({children}) {
return (<InlineCode>{children}</InlineCode>) ;
},
del(p) {
return (<del className="text-noimportance" {...p}></del>);
},
Table({children, className, ...p}) {
return (<Table {...p}>{children}</Table>);
},
Thead({children, ...p}) {
return (<Thead {...p}>{children}</Thead>);
},
Tbody({children, ...p}) {
return (<Tbody {...p}>{children}</Tbody>);
},
Tr({children, ...p}) {
return (<Tr {...p}>{children}</Tr>);
},
Th({children, ...p}) {
return (<Th {...p}>{children}</Th>);
},
Td({children, ...p}) {
return (<Td {...p}>{children}</Td>);
},
Blockquote({children}) {
return (
<blockquote
className={`flex flex-col gap-[16px] w-full overflow-auto p-[8px_12px] rounded-[6px] leading-normal md:p-[12px_16px] bg-layer1`}>
{children}
</blockquote>
);
},
Noti({children, ...p}) {
return (<Noti {...p}>{children}</Noti>);
},
a({children, href, ...p}) {
if (href?.startsWith("/")) {
return (<Link href={href} className={"break-all"}>{children}</Link>);
} else {
return <a href={href} className={"break-all"} {...p}>{children}</a>
}
},
Dl({children, className, ...p}) {
return (
<dl className={`[&_dl]:mt-[8px] [&_dl]:mb-[4px] [&_dl]:first:mt-0 [&_dl]:pl-[1rem] [&_dl]:border-l-default [&_dl]:border-l-[2px] ${className || ""}`} {...p}>{children}</dl>);
},
Dt({children, className, ...p}) {
return (<dt className={`mt-[8px] mb-[4px] first:mt-0 ${className || ""}`} {...p}>{children}</dt>);
},
Dd({children, className, ...p}) {
return (
<dd className={`flex flex-col gap-[4px] ml-[16px] mb-[16px] last:mb-0 ${className || ""}`} {...p}>{children}</dd>);
},
AppCompat({...p}) {
return (<AppCompat {...p}/>);
},
Feature({children, ...p}) {
return (<Feature {...p}>{ children }</Feature>);
},
FeatureStatusNoti({...p}) {
return (<FeatureStatusNoti {...p} />);
},
MileStone({...p}) {
return (<MileStone {...p} />);
},
Details({children, ...p}) {
return (<Details {...p}>{children}</Details>);
}
};
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...mdxComponents,
...components,
}
}