Raw
1 import React from "react"
2 import type { MDXComponents as MDXComponentsType } from "mdx/types"
3 import { CodeMdx } from "@/components/CodeMdx"
4 import { Details, DetailsProps } from "@/components/Details"
5 import { DetailsSummary } from "@/components/Details/Summary"
6 import { Kbd } from "@/components/Kbd"
7 import { Note } from "@/components/Note"
8 import { Card } from "@/components/Card"
9 import { CardList } from "@/components/CardList"
10 import { ZoomImg } from "@/components/ZoomImg"
11 import { H1 } from "@/components/Heading/H1"
12 import { H2 } from "@/components/Heading/H2"
13 import { H3 } from "@/components/Heading/H3"
14 import { H4 } from "@/components/Heading/H4"
15 import { Link } from "@/components/Link"
16 import clsx from "clsx"
17 import { Text } from "@medusajs/ui"
18
19 export const MDXComponents: MDXComponentsType = {
20 code: CodeMdx,
21 kbd: Kbd,
22 Kbd,
23 // Referenced through a wrapper (read at render time, not module-init time) to
24 // break a circular-import TDZ: Note -> Note/Layout -> MarkdownContent ->
25 // MDXComponents -> Note. Without this, importing `Note` before this module is
26 // initialized throws "Cannot access 'Note' before initialization".
27 Note: (props: React.ComponentProps<typeof Note>) => <Note {...props} />,
28 details: Details,
29 Details: ({ className, ...props }: DetailsProps) => {
30 return <Details {...props} className={clsx(className, "my-docs_1")} />
31 },
32 Summary: DetailsSummary,
33 Card,
34 CardList,
35 h1: H1,
36 h2: H2,
37 h3: H3,
38 h4: H4,
39 p: ({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) => {
40 return (
41 <p
42 className={clsx(
43 "text-medusa-fg-base [&:not(:last-child)]:mb-docs_1.5 last:!mb-0",
44 className
45 )}
46 {...props}
47 />
48 )
49 },
50 ul: ({
51 className,
52 children,
53 ...props
54 }: React.HTMLAttributes<HTMLUListElement>) => {
55 return (
56 <ul
57 {...props}
58 className={clsx(
59 "list-disc px-docs_1 mb-docs_1.5 [&_ul]:mb-0 [&_ol]:mb-0 [&_p]:!mb-0",
60 className
61 )}
62 >
63 {children}
64 </ul>
65 )
66 },
67 ol: ({
68 className,
69 children,
70 ...props
71 }: React.HTMLAttributes<HTMLOListElement>) => {
72 return (
73 <ol
74 {...props}
75 className={clsx(
76 "list-decimal px-docs_1 mb-docs_1.5 [&_ul]:mb-0 [&_ol]:mb-0 [&_p]:!mb-0",
77 className
78 )}
79 >
80 {children}
81 </ol>
82 )
83 },
84 li: ({
85 className,
86 children,
87 ...props
88 }: React.HTMLAttributes<HTMLElement>) => {
89 return (
90 <li
91 className={clsx(
92 "text-medusa-fg-base [&:not(:last-child)]:mb-docs_0.5",
93 "[&_ol]:mt-docs_0.5 [&_ul]:mt-docs_0.5",
94 className
95 )}
96 {...props}
97 >
98 <Text as="span">{children}</Text>
99 </li>
100 )
101 },
102 hr: ({ className, ...props }: React.HTMLAttributes<HTMLHRElement>) => {
103 return (
104 <hr
105 className={clsx(
106 "my-docs_2 h-[1px] w-full border-0 bg-medusa-border-base",
107 className
108 )}
109 {...props}
110 />
111 )
112 },
113 img: (
114 props: React.DetailedHTMLProps<
115 React.ImgHTMLAttributes<HTMLImageElement>,
116 HTMLImageElement
117 >
118 ) => {
119 // NOTE: don't destructure `key` here — React 19 strips it from props and
120 // warns when it's accessed ("key is not a prop").
121 return <ZoomImg {...props} />
122 },
123 a: (props) => <Link {...props} variant="content" />,
124 strong: ({ className, ...props }: React.HTMLAttributes<HTMLElement>) => {
125 return <strong className={clsx("txt-medium-plus", className)} {...props} />
126 },
127 }
128
129 export const Hr = MDXComponents["hr"] as () => React.JSX.Element