-
Notifications
You must be signed in to change notification settings - Fork 2
/
mdx-components.tsx
86 lines (80 loc) · 2.33 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
// Required to use MDX in app directory, based on example:
// https://github.com/vercel/next.js/tree/canary/examples/app-dir-mdx
// Accessed 2023-07-21.
import * as React from "react";
import { AppLink } from "@/components/links/AppLink";
import { assertNotNullNotUndefined } from "@/types/Guards";
import { Typography } from "@mui/material";
import type { MDXComponents } from "mdx/types";
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
// MDX links should all be our AppLink.
a: ({ children, href }) => {
assertNotNullNotUndefined(href);
return <AppLink href={href}>{children}</AppLink>;
},
// If MDX uses raw html heading elements, then MUI theming is not applied.
// For internal consistency, apply theme typography to each heading type.
h1: ({
children,
...props
}: React.PropsWithChildren | React.HTMLAttributes<HTMLHeadingElement>) => {
return (
<Typography component="h1" variant="h1" {...props}>
{children}
</Typography>
);
},
h2: ({
children,
...props
}: React.PropsWithChildren | React.HTMLAttributes<HTMLHeadingElement>) => {
return (
<Typography component="h2" variant="h2" {...props}>
{children}
</Typography>
);
},
h3: ({
children,
...props
}: React.PropsWithChildren | React.HTMLAttributes<HTMLHeadingElement>) => {
return (
<Typography component="h3" variant="h3" {...props}>
{children}
</Typography>
);
},
h4: ({
children,
...props
}: React.PropsWithChildren | React.HTMLAttributes<HTMLHeadingElement>) => {
return (
<Typography component="h4" variant="h4" {...props}>
{children}
</Typography>
);
},
h5: ({
children,
...props
}: React.PropsWithChildren | React.HTMLAttributes<HTMLHeadingElement>) => {
return (
<Typography component="h5" variant="h5" {...props}>
{children}
</Typography>
);
},
h6: ({
children,
...props
}: React.PropsWithChildren | React.HTMLAttributes<HTMLHeadingElement>) => {
return (
<Typography component="h6" variant="h6" {...props}>
{children}
</Typography>
);
},
...components,
};
}