import React, { useState } from 'react'; import ImageInput from './image-input'; export function ImageInputDemo() { const [selectedImage, setSelectedImage] = useState(null); const [validationResult, setValidationResult] = useState<{ isValid: boolean; error?: string; detectedType?: string; filename?: string } | null>(null); const [demoLog, setDemoLog] = useState([]); const log = (message: string) => { const timestamp = new Date().toLocaleTimeString(); setDemoLog(prev => [`[${timestamp}] ${message}`, ...prev.slice(0, 4)]); }; const handleImageChange = (value: File | string | null) => { setSelectedImage(value); log(`Image ${value ? 'selected' : 'cleared'}: ${value instanceof File ? value.name : value}`); }; const handleValidation = (result: { isValid: boolean; error?: string; detectedType?: string; filename?: string }) => { setValidationResult(result); log(`Validation: ${result.isValid ? 'Valid' : 'Invalid'} - ${result.error || 'OK'}`); }; const handleUploadToServer = async () => { if (!selectedImage) return; log('Uploading to server...'); // Simulate server upload await new Promise(resolve => setTimeout(resolve, 2000)); log('Upload completed successfully!'); }; return (

ImageInput Component Demo

This demo showcases the ImageInput component with both file upload and URL input modes. Try selecting an image file or entering an image URL to see validation and preview in action.

{/* ImageInput Component */}
{/* Demo Actions */} {selectedImage && (
)} {/* Status Display */}
{/* Validation Status */}

Validation Status

{validationResult ? (
Valid:{' '} {validationResult.isValid ? 'Yes' : 'No'}
{validationResult.error && (
Error:{' '} {validationResult.error}
)} {validationResult.detectedType && (
Type: {validationResult.detectedType}
)} {validationResult.filename && (
Filename: {validationResult.filename}
)}
) : (

No validation performed yet

)}
{/* Activity Log */}

Activity Log

{demoLog.length > 0 ? ( demoLog.map((entry, index) => (
{entry}
)) ) : (

No activity yet

)}
{/* Code Example */}

Usage Example

{`import { ImageInput } from './components/ui/image-input';

function MyComponent() {
  const [image, setImage] = useState(null);

  return (
     {
        console.log('Validation:', result);
      }}
      showPreview={true}
      maxSize={5 * 1024 * 1024} // 5MB
    />
  );
}`}
        
); } export default ImageInputDemo;