forked from liferay/clay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
74 lines (71 loc) · 1.79 KB
/
Copy pathmdx-components.tsx
File metadata and controls
74 lines (71 loc) · 1.79 KB
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
import {CodeBlock, MDXComponents} from 'renoun/components';
import Link from 'next/link';
import {Sandpack} from '@/app/_components/Sandpack.server';
import styles from './mdx-components.module.css';
import React from 'react';
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
h1: ({children, id}) => (
<h1 className="text-10" id={id}>
{children}
</h1>
),
h2: ({children, id}) => (
<h2 className="text-7 mb-4 mt-5" id={id}>
{children}
</h2>
),
h3: ({children, id}) => (
<h3 className="text-6 mb-3 mt-4 text-weight-semi-bold" id={id}>
{children}
</h3>
),
h4: ({children, id}) => (
<h4 className="text-4 mb-2 mt-3 text-weight-semi-bold" id={id}>
{children}
</h4>
),
p: ({children}) => <p className={styles.p}>{children}</p>,
ul: ({children}) => <ul className={styles.ul}>{children}</ul>,
code: ({children}) => <code className={styles.code}>{children}</code>,
a: ({children, ...otherProps}) => {
const As = otherProps.href?.includes('http') ? 'a' : Link;
return (
<As
{...(otherProps as any)}
className="c-link link-primary text-decoration-underline"
>
{children}
</As>
);
},
pre: ({children, preview, language, value, ...otherProps}: any) => {
if (preview) {
return (
<Sandpack language={language}>
{(children as any).props.children}
</Sandpack>
);
}
return (
<CodeBlock
{...otherProps}
value={value}
allowCopy
className={{
container: styles.code_editor,
}}
shouldFormat={false}
showToolbar={false}
language={language}
/>
);
},
blockquote: ({children, ...otherProps}) => (
<blockquote {...otherProps} className={styles.blockquote}>
{children}
</blockquote>
),
};
}