-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
128 lines (126 loc) · 3.65 KB
/
Copy pathmdx-components.tsx
File metadata and controls
128 lines (126 loc) · 3.65 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { DocCodeBlock } from "@/components/app/doc-code-block"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { cn } from "@/lib/utils"
import type { MDXComponents } from "mdx/types"
import Link from "next/link"
import { extractCodeFromFilePath } from "./lib/code"
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
code: ({ children, ...props }: React.HTMLAttributes<HTMLElement>) => (
<code {...props} className="not-prose bg-secondary p-1 font-mono">
{children}
</code>
),
a: (props: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
<Link {...props} href={props.href || "#"}>
{props.children}
</Link>
),
Link: ({ children, ...props }: React.ComponentProps<"a">) => (
<Link {...props} href={props.href as string}>
{children}
</Link>
),
CodeBlock: ({
language,
code,
filePath,
...props
}: {
language: string
code: string
filePath?: string
} & React.HTMLAttributes<HTMLDivElement>) => {
const fileContent = filePath
? extractCodeFromFilePath(filePath)
: code || ""
return <DocCodeBlock language={language} code={fileContent} {...props} />
},
Step: ({ className, children, ...props }: React.ComponentProps<"h3">) => (
<h3 className={cn("step", className)} data-heading="3" {...props}>
{children}
</h3>
),
Steps: ({ ...props }) => (
<div
className="steps mb-12 ml-4 border-l pl-8 [counter-reset:step]"
{...props}
/>
),
Tabs: ({ className, ...props }: React.ComponentProps<typeof Tabs>) => (
<Tabs className={cn("relative mt-6 w-full", className)} {...props} />
),
TabsList: ({
className,
...props
}: React.ComponentProps<typeof TabsList>) => (
<TabsList className={cn(className)} {...props} />
),
TabsTrigger: ({
className,
...props
}: React.ComponentProps<typeof TabsTrigger>) => (
<TabsTrigger className={cn(className)} {...props} />
),
TabsContent: ({
className,
...props
}: React.ComponentProps<typeof TabsContent>) => (
<TabsContent className={cn(className)} {...props} />
),
table: ({
className,
...props
}: React.HTMLAttributes<HTMLTableElement>) => (
<div className="not-prose border-border relative w-full table-auto overflow-auto rounded-lg border text-sm">
<table className={cn("w-full", className)} {...props} />
</div>
),
thead: ({
className,
...props
}: React.HTMLAttributes<HTMLTableSectionElement>) => (
<thead
className={cn("bg-secondary text-foreground", className)}
{...props}
/>
),
tbody: ({
className,
...props
}: React.HTMLAttributes<HTMLTableSectionElement>) => (
<tbody
className={cn(
"divide-y divide-zinc-200 dark:divide-y dark:divide-zinc-600",
className
)}
{...props}
/>
),
tr: ({
className,
...props
}: React.HTMLAttributes<HTMLTableRowElement>) => (
<tr className={cn("h-10", className)} {...props} />
),
th: ({
className,
...props
}: React.HTMLAttributes<HTMLTableHeaderCellElement>) => (
<th
className={cn("px-4 pb-0 text-left align-middle font-[450]", className)}
{...props}
/>
),
td: ({
className,
...props
}: React.HTMLAttributes<HTMLTableDataCellElement>) => (
<td
className={cn("px-4 py-2 text-left align-middle", className)}
{...props}
/>
),
}
}