import React, { useState } from 'react' import { Code } from './icons' import CodeBlock from '../MDX/CodeBlock' import s from './index.module.less' interface Props { default: React.ComponentType> demoMeta: { code: string title?: string desc?: string } style?: React.CSSProperties className?: string isDemo: boolean } export function Demo({ default: DemoComp, demoMeta, isDemo, style, className, }: Props) { if (!DemoComp || !demoMeta || !isDemo) { return (
{`Demo Error:  component receives invalid props.
If you use it in jsx, you should import demoInfo like "import * as demoInfo from './demos/demo.tsx?demo'" and render it like ""
If you use it in markdown, you should use it exactly like "" (we use simple regexp to parse it, so you should use this format strictly)
`}
) } const { code, title, desc } = demoMeta const [showCode, setShowCode] = useState(false) return (
{title &&
{title}
} {desc &&
{desc}
}
{ setShowCode((v) => !v) }} >
{showCode && (
{code}
)}
) }