react-frontend-common-components 0.0.98 → 0.1.0

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.98",
3
+ "version": "0.1.0",
4
4
  "description": "Reusable frontend library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -12,7 +12,7 @@ import {
12
12
  } from "react";
13
13
  import "./app-input.css";
14
14
 
15
- interface AppInputProps extends InputProps {
15
+ interface AppInputProps extends Omit<InputProps, "maxLength"> {
16
16
  className?: string;
17
17
  label?: string;
18
18
  name?: string;
@@ -32,6 +32,7 @@ interface AppInputProps extends InputProps {
32
32
  suffixIcon?: React.ReactNode;
33
33
  prefixIcon?: React.ReactNode;
34
34
  required?: boolean;
35
+ maxLength?: number;
35
36
  }
36
37
 
37
38
  const AppInput = ({
@@ -54,6 +55,7 @@ const AppInput = ({
54
55
  suffixIcon,
55
56
  prefixIcon,
56
57
  required,
58
+ maxLength,
57
59
  ...props
58
60
  }: AppInputProps) => {
59
61
  const inputRef = useRef<InputRef>(null);
@@ -77,6 +79,17 @@ const AppInput = ({
77
79
  const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
78
80
  let newValue = e.target.value;
79
81
 
82
+ const isFloat = type === "float";
83
+ const isNumber = type === "number" || isFloat;
84
+
85
+ if (isNumber) {
86
+ const floatRegex = /^-?\d*\.?\d*$/;
87
+ if (!floatRegex.test(newValue)) return;
88
+
89
+ const digitCount = newValue.replace(/\./g, "").length;
90
+ if (maxLength && digitCount > maxLength) return;
91
+ }
92
+
80
93
  if (name === "name") {
81
94
  const alphabetOnly = /^[a-zA-Z\s]*$/;
82
95
  if (!alphabetOnly.test(newValue)) return;
@@ -86,11 +99,9 @@ const AppInput = ({
86
99
  setIsTyping(newValue.length > 0);
87
100
  handleChange?.(e);
88
101
  };
89
-
90
102
 
91
103
  return (
92
- <div className={`appInput ${className}`}>
93
- {/* Show placeholder only if user hasn't started typing */}
104
+ <div className={`appInput ${className || ""}`}>
94
105
  {required && !isTyping && !inputValue && (
95
106
  <div className="placeHolder" onClick={() => inputRef.current?.focus()}>
96
107
  <label className="requiredText" htmlFor={id}>
@@ -101,7 +112,8 @@ const AppInput = ({
101
112
  )}
102
113
 
103
114
  <Input
104
- type={type}
115
+ type={type === "float" ? "text" : type}
116
+ inputMode={type === "float" ? "decimal" : undefined}
105
117
  data-test-id={dataTestId}
106
118
  id={id}
107
119
  disabled={disabled}
@@ -7,6 +7,7 @@ interface AppPhoneInputProps {
7
7
  countryIsoCode?: string;
8
8
  countryCode?: string;
9
9
  phone: string;
10
+ placeholder?: string;
10
11
  handleChange: (
11
12
  phone: string,
12
13
  countryCode: string,
@@ -21,6 +22,7 @@ const AppPhoneInput = ({
21
22
  handleChange,
22
23
  countryIsoCode,
23
24
  phone,
25
+ placeholder,
24
26
  className,
25
27
  id,
26
28
  }: AppPhoneInputProps) => {
@@ -43,10 +45,13 @@ const AppPhoneInput = ({
43
45
  country={countryIsoCode || "us"}
44
46
  countryCodeEditable={false}
45
47
  enableSearch={true}
46
- inputProps={{ required: true }}
48
+ inputProps={{
49
+ required: true,
50
+ placeholder: placeholder || "",
51
+ }}
47
52
  onChange={(value, country: CountryData) => {
48
53
  handleChange(
49
- value,
54
+ value,
50
55
  country.dialCode,
51
56
  country.countryCode,
52
57
  country.name