forked from globus/static-data-portal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmdx-components.tsx
35 lines (34 loc) · 936 Bytes
/
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
import React from "react";
import { Heading, Link } from "@chakra-ui/react";
import { ExternalLinkIcon } from "@chakra-ui/icons";
import type { MDXComponents } from "mdx/types";
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
h1(props) {
return <Heading as="h1" size="xl" {...props} />;
},
h2(props) {
return <Heading as="h2" size="lg" {...props} />;
},
h3(props) {
return <Heading as="h3" size="md" {...props} />;
},
h4(props) {
return <Heading as="h4" size="sm" {...props} />;
},
h5(props) {
return <Heading as="h5" size="sm" {...props} />;
},
a(props) {
if (props?.href?.startsWith("http")) {
return (
<Link {...props} isExternal>
{props.children} <ExternalLinkIcon mx="2px" />
</Link>
);
}
return <Link {...props} />;
},
};
}