Skip to content

Commit a3d90cf

Browse files
committed
Refactor mdx
- refactor MdxCard component to parse md and file for examples section
1 parent ec6cd89 commit a3d90cf

File tree

13 files changed

+988
-460
lines changed

13 files changed

+988
-460
lines changed

apps/landing/next.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { DevupUI } from '@devup-ui/next-plugin'
22
import createMDX from '@next/mdx'
3+
import remarkGfm from 'remark-gfm'
34

4-
const withMDX = createMDX({})
5+
const withMDX = createMDX({
6+
options: {
7+
remarkPlugins: [remarkGfm],
8+
},
9+
extension: /\.mdx?$/,
10+
})
511

612
export default withMDX(
713
DevupUI(

apps/landing/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,31 @@
1111
"lint": "eslint"
1212
},
1313
"dependencies": {
14-
"body-scroll-lock": "3.1.5",
15-
"@devup-ui/react": "workspace:*",
1614
"@devup-ui/components": "workspace:*",
15+
"@devup-ui/react": "workspace:*",
1716
"@mdx-js/loader": "^3.1.0",
1817
"@mdx-js/react": "^3.1.0",
1918
"@next/mdx": "^15.3.4",
2019
"@types/mdx": "^2.0.13",
20+
"body-scroll-lock": "3.1.5",
2121
"clsx": "^2.1.1",
2222
"next": "^15.3.4",
2323
"react": "^19.1.0",
2424
"react-dom": "^19.1.0",
25+
"react-markdown": "8.0.6",
2526
"react-syntax-highlighter": "^15.6.1",
27+
"remark-gfm": "^4.0.1",
2628
"sanitize.css": "^13.0.0"
2729
},
2830
"devDependencies": {
29-
"@types/body-scroll-lock": "^3.1.2",
3031
"@devup-ui/next-plugin": "workspace:*",
32+
"@types/body-scroll-lock": "^3.1.2",
3133
"@types/node": "^24",
3234
"@types/react": "^19",
3335
"@types/react-dom": "^19",
3436
"@types/react-syntax-highlighter": "^15.5.13",
35-
"typescript": "^5",
3637
"glob": "^11.0.3",
37-
"remark": "^15.0.1"
38+
"remark": "^15.0.1",
39+
"typescript": "^5"
3840
}
3941
}

apps/landing/src/app/(detail)/components/MdxCard.tsx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1-
import { css } from '@devup-ui/react'
1+
import { readFile } from 'node:fs/promises'
2+
import { join } from 'node:path'
3+
4+
import { Box, css, VStack } from '@devup-ui/react'
5+
import ReactMarkdown from 'react-markdown'
6+
7+
import { Code } from '@/components/Code'
8+
import { _components } from '@/mdx-components'
29

310
import Card from './Card'
11+
import MdxCardFooter from './MdxCardFooter'
12+
13+
export default async function MdxCard({
14+
src,
15+
demo,
16+
}: {
17+
children: React.ReactNode
18+
src: string
19+
demo: React.ReactNode
20+
}) {
21+
const content = await readFile(
22+
join(
23+
process.cwd(),
24+
'src/app/(detail)/components',
25+
src ?? 'button/demo/Variants.tsx',
26+
),
27+
{
28+
encoding: 'utf-8',
29+
},
30+
)
31+
// extract comment
32+
const comment = content.match(/\/\*\*[\s\S]*?\*\//)?.[0]
33+
const code = content.replace('\n' + comment!, '')
34+
const normalizedComment = comment
35+
?.replace(/\/\*\*|\*\//g, '')
36+
?.replace(/^\s*\*\s*/gm, '')
437

5-
export default function MdxCard({ children }: { children: React.ReactNode }) {
638
return (
739
<Card
840
className={css({
@@ -23,9 +55,20 @@ export default function MdxCard({ children }: { children: React.ReactNode }) {
2355
_lastChild: {
2456
marginBottom: '0',
2557
},
58+
typography: 'bodyReg',
59+
color: '$text',
60+
whiteSpace: 'pre-wrap',
2661
})}
2762
>
28-
{children}
63+
<VStack gap="30px" px="24px" py="32px">
64+
<Box>{demo}</Box>
65+
<ReactMarkdown components={_components}>
66+
{normalizedComment ?? ''}
67+
</ReactMarkdown>
68+
</VStack>
69+
<MdxCardFooter>
70+
<Code language="tsx" value={code} />
71+
</MdxCardFooter>
2972
</Card>
3073
)
3174
}

apps/landing/src/app/(detail)/components/MdxCardFooter.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ export default function MdxCardFooter({
4444
{isOpen && (
4545
<Box
4646
borderTop="1px solid $border"
47-
maxW="100%"
4847
overflow="auto"
4948
px="24px"
50-
py="32px"
49+
py="16px"
5150
>
5251
{children}
5352
</Box>

apps/landing/src/app/(detail)/components/button/Api.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ button should have a width to be able to truncate the text.
6666
</Tr>
6767
</tbody>
6868
</Table>
69-
</div>
69+
</div>
70+
71+
## aa
72+
73+
| Property | Description | Type | Default | Version |
74+
| --- | --- | --- | --- | --- |
75+
| autoInsertSpace | We add a space between two Chinese characters by default, which removed by setting `autoInsertSpace` to `false`. | boolean | `true` | 5.17.0 |

0 commit comments

Comments
 (0)