-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
109 lines (105 loc) · 3.23 KB
/
Copy pathmdx-components.tsx
File metadata and controls
109 lines (105 loc) · 3.23 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
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
import type { MDXComponents } from "mdx/types";
import type { ComponentPropsWithoutRef } from "react";
function cn(...parts: (string | undefined | false)[]) {
return parts.filter(Boolean).join(" ");
}
const headingLink =
"scroll-mt-24 font-bold tracking-tight text-foreground";
const components = {
h1: ({ className, ...props }: ComponentPropsWithoutRef<"h1">) => (
<h1
className={cn("mb-5 text-2xl sm:text-3xl", headingLink, className)}
{...props}
/>
),
h2: ({ className, ...props }: ComponentPropsWithoutRef<"h2">) => (
<h2
className={cn("mt-8 mb-2 text-base sm:text-lg", headingLink, className)}
{...props}
/>
),
h3: ({ className, ...props }: ComponentPropsWithoutRef<"h3">) => (
<h3
className={cn("mt-6 mb-1.5 text-sm font-semibold text-foreground sm:text-base", className)}
{...props}
/>
),
p: ({ className, ...props }: ComponentPropsWithoutRef<"p">) => (
<p
className={cn(
"mb-3 text-xs leading-relaxed text-muted-foreground sm:text-[13px]",
className,
)}
{...props}
/>
),
a: ({ className, ...props }: ComponentPropsWithoutRef<"a">) => (
<a
className={cn(
"text-accent underline decoration-accent/40 underline-offset-2 transition-colors hover:text-accent-hover hover:decoration-accent-hover",
className,
)}
{...props}
/>
),
ul: ({ className, ...props }: ComponentPropsWithoutRef<"ul">) => (
<ul
className={cn(
"mb-3 list-disc space-y-1.5 pl-4 text-xs text-muted-foreground sm:text-[13px]",
className,
)}
{...props}
/>
),
ol: ({ className, ...props }: ComponentPropsWithoutRef<"ol">) => (
<ol
className={cn(
"mb-3 list-decimal space-y-1.5 pl-4 text-xs text-muted-foreground sm:text-[13px]",
className,
)}
{...props}
/>
),
li: ({ className, ...props }: ComponentPropsWithoutRef<"li">) => (
<li className={cn("leading-relaxed", className)} {...props} />
),
strong: ({ className, ...props }: ComponentPropsWithoutRef<"strong">) => (
<strong className={cn("font-semibold text-foreground", className)} {...props} />
),
hr: ({ className, ...props }: ComponentPropsWithoutRef<"hr">) => (
<hr className={cn("my-6 border-border", className)} {...props} />
),
blockquote: ({
className,
...props
}: ComponentPropsWithoutRef<"blockquote">) => (
<blockquote
className={cn(
"mb-3 border-l-2 border-accent/50 pl-3 text-xs italic text-muted-foreground sm:text-[13px]",
className,
)}
{...props}
/>
),
code: ({ className, ...props }: ComponentPropsWithoutRef<"code">) => (
<code
className={cn(
"rounded border border-border bg-surface-raised px-1.5 py-0.5 font-mono text-[0.9em] text-foreground",
className,
)}
{...props}
/>
),
pre: ({ className, ...props }: ComponentPropsWithoutRef<"pre">) => (
<pre
className={cn(
"mb-3 overflow-x-auto rounded border border-border bg-surface p-3 font-mono text-[11px] leading-relaxed text-muted-foreground sm:text-xs",
className,
)}
{...props}
/>
),
} satisfies MDXComponents;
export function useMDXComponents(): MDXComponents {
return components;
}