({ html, css, js }: { html: string; css: string; js: string })
| 11 | |
| 12 | // CodePen Demo 组件 |
| 13 | function CodePenDemo({ html, css, js }: { html: string; css: string; js: string }) { |
| 14 | const [isExpanded, setIsExpanded] = useState(false); |
| 15 | |
| 16 | const fullHtml = ` |
| 17 | <!DOCTYPE html> |
| 18 | <html> |
| 19 | <head> |
| 20 | <meta charset="UTF-8"> |
| 21 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 22 | <style>${css}</style> |
| 23 | </head> |
| 24 | <body> |
| 25 | ${html} |
| 26 | <script>${js}</script> |
| 27 | </body> |
| 28 | </html> |
| 29 | `.trim(); |
| 30 | |
| 31 | return ( |
| 32 | <div className="my-6 border border-gray-200 rounded-lg overflow-hidden"> |
| 33 | <div className="bg-gray-50 px-4 py-2 border-b border-gray-200 flex justify-between items-center"> |
| 34 | <span className="text-sm font-medium text-gray-700">Live Demo</span> |
| 35 | <button |
| 36 | onClick={() => setIsExpanded(!isExpanded)} |
| 37 | className="text-sm text-blue-600 hover:text-blue-800" |
| 38 | > |
| 39 | {isExpanded ? '收起' : '展开'} |
| 40 | </button> |
| 41 | </div> |
| 42 | <div className={`transition-all duration-300 ${isExpanded ? 'h-96' : 'h-64'}`}> |
| 43 | <iframe |
| 44 | srcDoc={fullHtml} |
| 45 | className="w-full h-full border-0" |
| 46 | title="CodePen Demo" |
| 47 | sandbox="allow-scripts allow-same-origin" |
| 48 | /> |
| 49 | </div> |
| 50 | </div> |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | export default function CodeBlock({ children, language = 'text' }: CodeBlockProps) { |
| 55 | // 检测是否是 CodePen 格式的代码块 |
nothing calls this directly
no outgoing calls
no test coverage detected