-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmdx-components.tsx
64 lines (59 loc) · 1.49 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
import type { LinkProps, TypographyProps } from "@mui/material";
// TODO(kilemensi): Switch to @cui/next/Link
import { Link, Typography } from "@mui/material";
import type { MDXComponents } from "mdx/types";
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
function createHeading(level: HeadingLevel) {
const Heading = ({ children, ...others }: TypographyProps) => (
<Typography
{...others}
variant={`h${level}`}
sx={{
scrollMarginTop: 48 + 16, // Toolbar height + 1M
"&>a": {
opacity: 0.65,
},
"& .icon.icon-link": {
display: "none",
paddingLeft: 1,
},
"&:hover": {
"& .icon.icon-link": {
display: "initial",
},
},
"& .icon.icon-link:before": {
content: '"#"',
},
}}
>
{children}
</Typography>
);
Heading.displayName = `Heading${level}`;
return Heading;
}
const customComponents = {
h1: createHeading(1),
h2: createHeading(2),
h3: createHeading(3),
h4: createHeading(4),
h5: createHeading(5),
h6: createHeading(6),
p: ({ children, ...others }: TypographyProps) => (
<Typography variant="body1" {...others}>
{children}
</Typography>
),
a: ({ children, ...others }: LinkProps) => (
<Link underline="none" color="inherit" {...others}>
{children}
</Link>
),
};
export function useMDXComponents(components?: MDXComponents) {
return {
...customComponents,
...components,
};
}