-
Notifications
You must be signed in to change notification settings - Fork 6
/
mdx-components.tsx
111 lines (106 loc) · 2.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
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
import type { MDXComponents } from 'mdx/types';
import { css } from '@/styled-system/css';
import { styled } from '@/styled-system/jsx';
import { DetailedHTMLProps, HTMLAttributes, ReactPropTypes } from 'react';
import { CodePanel } from '@/components/app/code_panel';
function Pre({ children }: DetailedHTMLProps<HTMLAttributes<HTMLPreElement>, HTMLPreElement>) {
return <>{children}</>;
}
interface CodeProps extends React.HtmlHTMLAttributes<HTMLDivElement> {}
function Code({ children, className }: CodeProps) {
if (className?.startsWith('language-')) {
className = className.split('-').pop();
return <CodePanel language={className}>{`${children}`}</CodePanel>;
} else {
return (
<code
className={css({
bg: { _light: 'stone.200', _dark: `stone.700` },
p: '2px',
borderRadius: 'sm',
})}
>
{children}
</code>
);
}
}
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
h1: ({ children }) => (
<h1
className={css({
fontFamily: 'heading',
fontSize: '3xl',
fontWeight: 'bold',
mt: '4',
mb: '2',
})}
>
{children}
</h1>
),
h2: ({ children }) => (
<h2
className={css({
fontFamily: 'heading',
fontSize: '2xl',
fontWeight: 'bold',
mt: '5',
mb: '2',
})}
>
{children}
</h2>
),
h3: ({ children }) => (
<h3
className={css({
fontFamily: 'mono',
mt: '5',
mb: '2',
fontSize: '16px',
})}
>
{children}
</h3>
),
em: ({ children }) => <em className={css({ fontStyle: 'italic' })}>{children}</em>,
p: ({ children }) => (
<p
className={css({
fontSize: '16px',
mt: '3',
mb: '3',
lineHeight: '1.75',
fontFamily: 'body',
})}
>
{children}
</p>
),
ul: ({ children }) => (
<styled.ul
listStyle="inside"
fontFamily="body"
fontSize="16px"
ml="0"
pl="1em"
pr="-1em"
lineHeight="2"
>
{children}
</styled.ul>
),
a: ({ children, href }) => {
return (
<styled.a textDecoration="none" target="_blank" cursor="pointer" href={href}>
{children}
</styled.a>
);
},
pre: Pre,
code: Code,
};
}