import { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'motion/react'; import { Smartphone, Tablet, Monitor, X } from 'lucide-react'; export interface DevicePreviewProps { url?: string; defaultDevice?: 'mobile' | 'tablet' | 'desktop'; onClose?: () => void; isOpen: boolean; } const devices = { mobile: { width: 375, height: 812, name: 'iPhone 13' }, tablet: { width: 768, height: 1024, name: 'iPad' }, desktop: { width: 1440, height: 900, name: 'MacBook Pro' } }; export function DevicePreview({ url, defaultDevice = 'mobile', onClose, isOpen }: DevicePreviewProps) { const [device, setDevice] = useState<'mobile' | 'tablet' | 'desktop'>(defaultDevice); const [previewUrl, setPreviewUrl] = useState(''); const [isLoaded, setIsLoaded] = useState(false); useEffect(() => { // Determine the URL to load in the iframe // If no URL is provided, load the current origin but add a query param to avoid infinite loops if (isOpen) { const targetUrl = url || window.location.origin + window.location.pathname; const urlObj = new URL(targetUrl); urlObj.searchParams.set('_preview', '1'); // Prevent recursive rendering setPreviewUrl(urlObj.toString()); setIsLoaded(false); } }, [url, isOpen]); if (!isOpen) return null; return (
{/* Topbar */}

Device Preview

{/* Device Toggles */}
{devices[device].width} × {devices[device].height}
{/* Device Canvas Area */}
{/* Fake Browser Bar for Desktop/Tablet */} {device !== 'mobile' && (
{previewUrl}
)} {/* Fake Mobile Notch */} {device === 'mobile' && (
)} {!isLoaded && previewUrl && (
Cargando Preview...
)} {previewUrl && (