-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
39 lines (36 loc) · 1022 Bytes
/
mdx-components.tsx
File metadata and controls
39 lines (36 loc) · 1022 Bytes
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
import type { MDXComponents } from 'mdx/types';
import Image from 'next/image';
// This file allows you to provide custom React components
// to be used in MDX files. You can import and use any
// React component you want, including components from
// other libraries.
// This file is required to use MDX in `app` directory.
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
img: ({ className, src, alt }: React.ImgHTMLAttributes<HTMLImageElement>) =>
src &&
(src.split('.').pop() === 'mp4' ? (
<video
className={className}
src={src}
autoPlay
loop
muted
playsInline
style={{ width: '100%' }}
/>
) : (
<Image
className={className}
src={src!}
width={0}
height={0}
sizes="100vw"
alt={alt!}
style={{ width: '100%', height: 'auto' }}
priority
/>
)),
...components,
};
}