react-frontend-common-components 0.0.59 → 0.0.60

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": "react-frontend-common-components",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "description": "Reusable frontend library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,6 +31,7 @@ const AppUploadImage = ({
31
31
  maxSizeMb = 2,
32
32
  altText = "Profile Image",
33
33
  }: AppUploadImageProps) => {
34
+
34
35
  const [imageUrl, setImageUrl] = useState<string>(value);
35
36
  const fileInputRef = useRef<HTMLInputElement>(null);
36
37
 
@@ -42,7 +43,7 @@ const AppUploadImage = ({
42
43
  const file = event.target.files?.[0];
43
44
  if (file) {
44
45
  const isAcceptedFormat = acceptedFormats.includes(file.type);
45
- const isLtMaxSize = file.size / 1024 / 1024 < maxSizeMb;
46
+ const isLtMaxSize = file.size / 1024 / 1024 <= maxSizeMb;
46
47
 
47
48
  if (!isAcceptedFormat) {
48
49
  alert(alertMessages.invalidType);
@@ -57,31 +58,39 @@ const AppUploadImage = ({
57
58
  const reader = new FileReader();
58
59
  reader.onloadend = () => {
59
60
  setImageUrl(reader.result as string);
60
- if (onFileChange) {
61
- onFileChange(file);
62
- }
61
+ onFileChange?.(file);
63
62
  };
64
63
  reader.readAsDataURL(file);
65
- } else if (onFileChange) {
66
- onFileChange(null);
64
+ } else {
65
+ setImageUrl("");
66
+ onFileChange?.(null);
67
67
  }
68
68
  };
69
69
 
70
70
  return (
71
71
  <div className={`profileImageContainer ${className}`}>
72
- <div className={imageUrl === "" ? "altTextWrapper" : ""}>
73
- <img className={"profileImage"} src={imageUrl} alt={altText} />
72
+ <div className={imageUrl ? "imageWrapper" : "altTextWrapper"}>
73
+ {imageUrl ? (
74
+ <img className="profileImage" src={imageUrl} alt={altText} />
75
+ ) : (
76
+ <span className="altText">{altText}</span>
77
+ )}
74
78
  </div>
75
- <button className={"uploadButton"} onClick={handleButtonClick}>
79
+ <button
80
+ className="uploadButton"
81
+ onClick={handleButtonClick}
82
+ aria-label={text}
83
+ >
76
84
  <span>{uploadIcon || Icons.uploadIcon}</span>
77
85
  {text}
78
86
  </button>
79
87
  <input
80
88
  type="file"
81
89
  accept={acceptedFormats.join(",")}
82
- className={"fileInput"}
90
+ className="fileInput"
83
91
  ref={fileInputRef}
84
92
  onChange={handleFileChange}
93
+ style={{ display: "none" }}
85
94
  />
86
95
  </div>
87
96
  );