-
Notifications
You must be signed in to change notification settings - Fork 99
/
mdx-components.tsx
128 lines (126 loc) · 3.71 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import type { MDXComponents } from 'mdx/types';
import { cn } from '@/lib/utils';
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from './components/website/tabs';
const generateId = (text: string) => {
return text
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '');
};
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
h1: ({ children, ...props }: React.HTMLProps<HTMLHeadingElement>) => {
const id = generateId(children?.toString() || '');
return (
<h1 id={id} data-heading='1' {...props}>
{children}
</h1>
);
},
h2: ({ children, ...props }: React.HTMLProps<HTMLHeadingElement>) => {
const id = generateId(children?.toString() || '');
return (
<h2 id={id} data-heading='2' {...props}>
{children}
</h2>
);
},
h3: ({ children, ...props }: React.HTMLProps<HTMLHeadingElement>) => {
const id = generateId(children?.toString() || '');
return (
<h3 id={id} data-heading='3' {...props}>
{children}
</h3>
);
},
h4: ({ children, ...props }: React.HTMLProps<HTMLHeadingElement>) => {
const id = generateId(children?.toString() || '');
return (
<h4 id={id} data-heading='4' {...props}>
{children}
</h4>
);
},
Step: ({ className, children, ...props }: React.ComponentProps<'h3'>) => (
<h3
id={generateId(children?.toString() || '')}
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.ComponentProps<'table'>) => (
<div className='not-prose relative w-full table-auto overflow-auto rounded-lg border border-zinc-200 text-sm dark:border-zinc-800'>
<table className={cn('w-full', className)} {...props} />
</div>
),
thead: ({ className, ...props }: React.ComponentProps<'thead'>) => (
<thead
className={cn(
'bg-zinc-100 text-zinc-900 dark:bg-zinc-900 dark:text-zinc-100',
className
)}
{...props}
/>
),
tbody: ({ className, ...props }: React.ComponentProps<'tbody'>) => (
<tbody
className={cn(
'divide-y divide-zinc-200 dark:divide-y dark:divide-zinc-600',
className
)}
{...props}
/>
),
tr: ({ className, ...props }: React.ComponentProps<'tr'>) => (
<tr className={cn('h-10', className)} {...props} />
),
th: ({ className, ...props }: React.ComponentProps<'th'>) => (
<th
className={cn('px-4 pb-0 text-left align-middle font-[450]', className)}
{...props}
/>
),
td: ({ className, ...props }: React.ComponentProps<'td'>) => (
<td
className={cn('px-4 py-2 text-left align-middle', className)}
{...props}
/>
),
};
}