File size: 1,746 Bytes
eebc40f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { useState, useEffect } from 'react';
import Spinner from './Spinner';

/**
 * Composant wrapper pour les images SVG avec spinner de chargement
 */
const SvgImage = ({ 
  src, 
  alt = '', 
  className = '', 
  style = {},
  spinnerSize = '16px',
  spinnerColor = 'currentColor',
  onLoad = null,
  onError = null
}) => {
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(false);

  useEffect(() => {
    if (!src) {
      setLoading(false);
      setError(true);
      return;
    }

    setLoading(true);
    setError(false);

    // Créer une image pour tester le chargement
    const img = new Image();
    
    img.onload = () => {
      setLoading(false);
      setError(false);
      if (onLoad) onLoad();
    };
    
    img.onerror = () => {
      setLoading(false);
      setError(true);
      if (onError) onError();
    };
    
    img.src = src;
  }, [src, onLoad, onError]);

  if (loading) {
    return (
      <div 
        className={`svg-image-loading ${className}`}
        style={{
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          ...style
        }}
      >
        <Spinner size={spinnerSize} color={spinnerColor} />
      </div>
    );
  }

  if (error) {
    return (
      <div 
        className={`svg-image-error ${className}`}
        style={{
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          color: '#999',
          fontSize: '12px',
          ...style
        }}
      >
        ⚠️
      </div>
    );
  }

  return (
    <img 
      src={src}
      alt={alt}
      className={className}
      style={style}
    />
  );
};

export default SvgImage;