|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import { SchemaRenderer } from '@object-ui/react'; |
| 5 | +import type { SchemaNode } from '@object-ui/core'; |
| 6 | + |
| 7 | +interface ComponentDemoProps { |
| 8 | + schema: SchemaNode; |
| 9 | + title?: string; |
| 10 | + description?: string; |
| 11 | +} |
| 12 | + |
| 13 | +export function ComponentDemo({ schema, title, description }: ComponentDemoProps) { |
| 14 | + return ( |
| 15 | + <div className="not-prose my-6"> |
| 16 | + {(title || description) && ( |
| 17 | + <div className="mb-3"> |
| 18 | + {title && <h4 className="text-sm font-semibold mb-1">{title}</h4>} |
| 19 | + {description && <p className="text-sm text-muted-foreground">{description}</p>} |
| 20 | + </div> |
| 21 | + )} |
| 22 | + <div className="border rounded-lg p-6 bg-background"> |
| 23 | + <SchemaRenderer schema={schema} /> |
| 24 | + </div> |
| 25 | + </div> |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +interface DemoGridProps { |
| 30 | + children: React.ReactNode; |
| 31 | +} |
| 32 | + |
| 33 | +export function DemoGrid({ children }: DemoGridProps) { |
| 34 | + return ( |
| 35 | + <div className="not-prose grid gap-4 md:grid-cols-2 my-6"> |
| 36 | + {children} |
| 37 | + </div> |
| 38 | + ); |
| 39 | +} |
| 40 | + |
| 41 | +interface CodeDemoProps { |
| 42 | + schema: SchemaNode; |
| 43 | + code: string; |
| 44 | + title?: string; |
| 45 | +} |
| 46 | + |
| 47 | +export function CodeDemo({ schema, code, title }: CodeDemoProps) { |
| 48 | + return ( |
| 49 | + <div className="not-prose my-6"> |
| 50 | + {title && <h4 className="text-sm font-semibold mb-3">{title}</h4>} |
| 51 | + <div className="grid gap-4 lg:grid-cols-2"> |
| 52 | + <div className="border rounded-lg p-6 bg-background"> |
| 53 | + <SchemaRenderer schema={schema} /> |
| 54 | + </div> |
| 55 | + <div className="border rounded-lg overflow-hidden"> |
| 56 | + <pre className="p-4 text-xs overflow-auto max-h-96 bg-muted"> |
| 57 | + <code>{code}</code> |
| 58 | + </pre> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + ); |
| 63 | +} |
0 commit comments