import { useState } from 'react'; import { Send, Loader2, Code2, Eye, Copy, Check } from 'lucide-react'; const samplePrompts = [ 'Build a todo app with drag and drop', 'Create a weather dashboard with charts', 'Make an analytics dashboard with KPI cards', ]; export default function LiveDemo() { const [prompt, setPrompt] = useState(''); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const [activeTab, setActiveTab] = useState('code'); const [copied, setCopied] = useState(false); const handleGenerate = async () => { if (!prompt.trim() || loading) return; setLoading(true); setResult(null); try { const res = await fetch('/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt }), }); const data = await res.json(); setResult(data); setActiveTab('code'); } catch (err) { setResult({ code: '// Error generating code. Please try again.', explanation: 'Something went wrong. Please try another prompt.', }); } finally { setLoading(false); } }; const handleCopy = () => { if (result?.code) { navigator.clipboard.writeText(result.code); setCopied(true); setTimeout(() => setCopied(false), 2000); } }; return (
Live Demo

Try it right now

Describe what you want to build and watch the AI generate production-ready code in real-time.

{/* Input area */}
setPrompt(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleGenerate()} placeholder="Describe the app you want to build..." className="w-full px-4 py-3 bg-surface-800 border border-white/10 rounded-xl text-white placeholder-surface-300 focus:outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500 transition-all" />
{samplePrompts.map((sp) => ( ))}
{/* Result area */} {result && (
{/* Tabs */}
{activeTab === 'code' && ( )}
{activeTab === 'code' ? (
                  {result.code}
                
) : (

AI Explanation

{result.explanation}

✨ This code is production-ready and includes TypeScript types, responsive design, and accessibility features.

)}
)}
); }