-
Notifications
You must be signed in to change notification settings - Fork 4
/
mdx-components.tsx
95 lines (92 loc) · 2.42 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
import { Message } from "@/components/message";
import { PostFooter } from "@/components/post-footer";
import { PostHeader } from "@/components/post-header";
import clsx from "clsx";
import { LinkIcon } from "lucide-react";
import type { MDXComponents } from "mdx/types";
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
pre: (props) => (
<pre
{...props}
className={clsx(props.className, "w-full overflow-hidden sm:rounded")}
/>
),
a: (props) => (
<a
{...props}
className={clsx(
props.className,
"text-emerald-500 underline underline-offset-4 shadow-[0_2px_0_0_theme(colors.emerald.500)] hover:shadow-[0_3px_0_0_theme(colors.emerald.500)] transition-shadow",
)}
>
{props.children}
</a>
),
h2: (props) => (
<h2
{...props}
className={clsx(
props.className,
"text-4xl font-bold group flex gap-2 items-center",
)}
>
{props.children}
<a
href={`#${props.id}`}
aria-hidden
className="sr-only group-hover:not-sr-only group-focus-within:no-sr-only"
>
<LinkIcon size={18} />
</a>
</h2>
),
h3: (props) => (
<h3
{...props}
className={clsx(
props.className,
"text-3xl font-semibold group flex gap-2 items-center",
)}
>
{props.children}
<a
href={`#${props.id}`}
aria-hidden
className="sr-only group-hover:not-sr-only group-focus-within:no-sr-only"
>
<LinkIcon size={18} />
</a>
</h3>
),
blockquote: (props) => (
<blockquote
{...props}
className={clsx(
props.className,
"bg-sky-900 border-l-8 border-sky-500 sm:rounded p-4 -mx-4",
"[&_a]:text-zinc-200 [&_a]:font-medium [&_a]:shadow-[0_2px_0_0_theme(colors.sky.300)] [&_a]:hover:shadow-[0_3px_0_0_theme(colors.sky.300)]",
)}
/>
),
ol: (props) => (
<ol
{...props}
className={clsx(
props.className,
"list-decimal px-4 flex flex-col gap-2",
)}
/>
),
ul: (props) => (
<ul
{...props}
className={clsx(props.className, "list-disc px-4 flex flex-col gap-2")}
/>
),
Message,
PostHeader,
PostFooter,
};
}