-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathdemo.tsx
57 lines (52 loc) · 1.19 KB
/
demo.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
import fs from "fs"
import path from "path"
import { Code } from "./code"
import { cn } from "../lib/utils"
export async function Demo({
name,
children,
className,
content = "content.md",
}: {
name: string
content?: string
children: React.ReactNode
className?: string
}) {
const value = await fs.promises.readFile(
path.join(process.cwd(), "demos", name, content),
"utf-8",
)
const usage = (
<Code
className="min-h-full flex flex-col my-0 max-h-full"
codeblock={{
value,
lang: "mdx",
meta: `${content} -pwc`,
}}
/>
)
const { default: Page } = await import(`@/demos/${name}/page`)
const preview = (
<div className="min-w-0 rounded flex-1 bg-blue-900/80 bg-[url(/dark-grid.svg)] p-3 flex flex-col overflow-hidden prose-invert">
<Page />
{children && (
<div className="mt-auto text-center text-white font-light pt-2">
{children}
</div>
)}
</div>
)
return (
<div
className={cn(
"flex gap-2 flex-wrap [&>*]:flex-1 [&>*]:min-w-72",
className,
)}
>
<div className="min-w-0 flex-1 max-h-full">{usage}</div>
{preview}
</div>
)
}