Skip to content

Commit 0b3d783

Browse files
committed
Create demo comp import function
1 parent 341ccff commit 0b3d783

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

apps/landing/src/app/(detail)/components/button/demo/Colors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Box, css, Flex } from '@devup-ui/react'
55
* **Colors**
66
* Pass in an object containing color tokens into `colors` prop. You can change color of border, background, danger color and more using `primary`, `error`, `text`, and so on.
77
*/
8-
export function Colors() {
8+
export default function Colors() {
99
return (
1010
<Box w="100%">
1111
<Flex flexWrap="wrap" gap="12px" mb="16px">

apps/landing/src/app/(detail)/components/button/demo/Danger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Box, css } from '@devup-ui/react'
55
* **Danger**
66
* Use `danger` prop to signal caution.
77
*/
8-
export function Danger() {
8+
export default function Danger() {
99
return (
1010
<Box w="100%">
1111
<Box display="flex" flexWrap="wrap" gap="12px" marginBottom="16px">

apps/landing/src/app/(detail)/components/button/demo/Disabled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Box, css, Flex } from '@devup-ui/react'
55
* **Disabled**
66
* Use `disabled` prop to show disabled UI of the button.
77
*/
8-
export function Disabled() {
8+
export default function Disabled() {
99
return (
1010
<Box w="100%">
1111
<Flex flexWrap="wrap" gap="12px" mb="16px">

apps/landing/src/app/(detail)/components/button/demo/Icon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import IconDelete from '../IconDelete'
77
* **Icon**
88
* Pass in an svg icon component into `icon` prop. If props like `stroke` and `fill` have `"currentColor"` value, the svg icon will follow the text color of the button.
99
*/
10-
export function Icon() {
10+
export default function Icon() {
1111
return (
1212
<Box w="100%">
1313
<Flex flexWrap="wrap" gap="12px" mb="16px">

apps/landing/src/app/(detail)/components/button/demo/Variants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { css, Flex } from '@devup-ui/react'
55
* **Variant & Size**
66
* `Button` components has `default` and `primary` variants. `Size` prop determines the paddings of the button.
77
*/
8-
export function Variants() {
8+
export default function Variants() {
99
return (
1010
<>
1111
<Flex flexWrap="wrap" gap="12px" mb="16px">

apps/landing/src/app/(detail)/components/button/page.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import { CustomH6 } from '@/components/mdx/components/CustomH6'
66
import { CustomParagraph } from '@/components/mdx/components/CustomParagraph'
77
import { CustomPre } from '@/components/mdx/components/CustomPre'
88
import { CustomStrong } from '@/components/mdx/components/CustomStrong'
9+
import { getDemos } from '@/utils/get-demos'
910

1011
import MdxCard from '../MdxCard'
1112
import Api from './Api.mdx'
1213
import Button from './Button.mdx'
13-
import { Colors } from './demo/Colors'
14-
import { Danger } from './demo/Danger'
15-
import { Disabled } from './demo/Disabled'
16-
import { Icon } from './demo/Icon'
17-
import { Variants } from './demo/Variants'
1814

19-
export default function Page() {
15+
export default async function Page() {
16+
const c = await getDemos(__dirname.split(/[\\/]/).pop()!)
17+
const m = Math.ceil(c.length / 2)
18+
2019
return (
2120
<VStack gap="16px" maxW="100%" overflow="hidden">
2221
<Button
@@ -34,13 +33,14 @@ export default function Page() {
3433
</Text>
3534
<Flex flexWrap="wrap" gap="16px">
3635
<Box flex="1" minW="300px" w="calc(50% - 8px)">
37-
<MdxCard demo={<Variants />} src="button/demo/Variants.tsx" />
38-
<MdxCard demo={<Danger />} src="button/demo/Danger.tsx" />
39-
<MdxCard demo={<Disabled />} src="button/demo/Disabled.tsx" />
36+
{c.slice(0, m).map(([Demo, src]) => (
37+
<MdxCard key={src} demo={<Demo />} src={src} />
38+
))}
4039
</Box>
4140
<Box flex="1" minW="300px" w="calc(50% - 8px)">
42-
<MdxCard demo={<Icon />} src="button/demo/Icon.tsx" />
43-
<MdxCard demo={<Colors />} src="button/demo/Colors.tsx" />
41+
{c.slice(m).map(([Demo, src]) => (
42+
<MdxCard key={src} demo={<Demo />} src={src} />
43+
))}
4444
</Box>
4545
</Flex>
4646
</VStack>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { readdir } from 'node:fs/promises'
2+
import { join, relative } from 'node:path'
3+
4+
export async function getDemos(
5+
dir: string,
6+
): Promise<[React.ComponentType, string][]> {
7+
const dirPath = join(
8+
process.cwd(),
9+
'src',
10+
'app',
11+
'(detail)',
12+
'components',
13+
dir,
14+
'demo',
15+
)
16+
const demos = await readdir(dirPath)
17+
18+
return Promise.all(
19+
demos.map<Promise<[React.ComponentType, string]>>((item) =>
20+
import(
21+
'./../' +
22+
relative(process.cwd(), `${dirPath}/${item}`)
23+
.replace('.tsx', '')
24+
.replaceAll('\\', '/')
25+
.slice(4)
26+
).then((m) => [m.default, `${dir}/demo/${item}`]),
27+
),
28+
)
29+
}

0 commit comments

Comments
 (0)