l-min-components 1.0.862 → 1.0.864

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.0.862",
3
+ "version": "1.0.864",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { Img } from "react-image";
3
3
  import { ImageFallbackContainer } from "./index.styled";
4
4
 
@@ -19,17 +19,37 @@ const ImageComponents = ({
19
19
  alt,
20
20
  className,
21
21
  }) => {
22
+ const [imgSrc, setImgSrc] = useState(src);
23
+ const [loading, setLoading] = useState(true);
24
+
25
+ useEffect(() => {
26
+ setImgSrc(src); // Reset to primary src when the src prop changes
27
+ setLoading(true); // Reset loading state when src changes
28
+ }, [src]);
29
+
30
+ const handleError = () => {
31
+ setLoading(false); // Stop showing the loading placeholder
32
+ };
33
+
34
+ const handleLoad = () => {
35
+ setLoading(false); // Image has loaded successfully
36
+ };
22
37
  return (
23
- <Img
24
- className={className}
25
- src={src}
26
- width={width}
27
- height={height}
28
- alt={alt}
29
- loader={
38
+ <>
39
+ {loading ? (
30
40
  <FallbackImage size={fallbackLogoSize} width={width} height={height} />
31
- }
32
- />
41
+ ) : (
42
+ <img
43
+ className={className}
44
+ src={imgSrc}
45
+ alt={alt}
46
+ onError={handleError}
47
+ onLoad={handleLoad}
48
+ style={{ display: loading ? "none" : "block", width, height }} // Hide the image while loading
49
+ {...props}
50
+ />
51
+ )}
52
+ </>
33
53
  );
34
54
  };
35
55