react-frontend-common-components 0.0.58 → 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.58",
3
+ "version": "0.0.60",
4
4
  "description": "Reusable frontend library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,13 +1,14 @@
1
- import React from "react";
1
+ import React, { useEffect, useRef } from "react";
2
2
  import "react-phone-input-2/lib/style.css";
3
- import "./app-phone-input.css";
4
3
  import PhoneInput, { CountryData } from "react-phone-input-2";
4
+ import "./app-phone-input.css";
5
5
 
6
6
  interface AppPhoneInputProps {
7
7
  value: string;
8
8
  countryCode?: string;
9
9
  handleChange: (phone: string, countryCode: string, uniCode: string) => void;
10
- className:string;
10
+ className: string;
11
+ id: string;
11
12
  }
12
13
 
13
14
  const AppPhoneInput = ({
@@ -15,10 +16,21 @@ const AppPhoneInput = ({
15
16
  handleChange,
16
17
  countryCode,
17
18
  className,
19
+ id,
18
20
  }: AppPhoneInputProps) => {
21
+ const wrapperRef = useRef<HTMLDivElement>(null);
22
+
23
+ useEffect(() => {
24
+ if (wrapperRef.current) {
25
+ const inputElement = wrapperRef.current.querySelector("input");
26
+ if (inputElement) {
27
+ inputElement.id = id;
28
+ }
29
+ }
30
+ }, [id]);
19
31
  return (
20
32
  <div className={className}>
21
- <div className={"inputContainer"}>
33
+ <div className={"inputContainer"} ref={wrapperRef}>
22
34
  <PhoneInput
23
35
  value={value}
24
36
  country={"ae"}
@@ -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
  );