import React, { useRef } from "react";
import Icons from "../../Icons";
import { Link } from "react-router-dom";
export default function InputCom({
label,
type,
name,
placeholder,
iconName,
passIcon,
inputHandler,
value,
forgotPassword,
parentClass,
labelClass,
inputClass,
fieldClass,
onClick,
disable,
blurHandler,
spanTag,
inputBg,
direction
}) {
const inputRef = useRef(null);
// Entry Validation
// for Min Length:
const minLengthValidation = () => {
const inputConfig = inputConfigs[inputRef?.current?.name]?.minLength;
return inputConfig || 0;
};
// for MaxLength
const maxLengthValidation = () => {
const inputConfig = inputConfigs[inputRef?.current?.name]?.maxLength;
return inputConfig || 30;
};
// for Patterns
const inputPatterns = () => {
const inputConfig = inputConfigs[inputRef?.current?.name]?.pattern;
return inputConfig || ""
}
return (
{label && (
)}
{forgotPassword && (
Forgot Password?
)}
inputPatterns}
ref={inputRef}
readOnly={disable}
onBlur={blurHandler}
dir={direction}
/>
{iconName && (
)}
{passIcon && (
)}
);
}
const inputConfigs = {
email: { minLength: 7, maxLength: 30 },
first_name: { minLength: 3, maxLength: 25, pattern: "[a-zA-Z]+" },
last_name: { minLength: 3, maxLength: 25, pattern: "[a-zA-Z]+" },
address: { minLength: 5, maxLength: 49, pattern: "[a-zA-Z0-9]+" },
password: { minLength: 8, maxLength: 15, pattern: ".{8,}" },
state: { minLength: 3, maxLength: 25, pattern: "[a-zA-Z]+" },
province: { minLength: 3, maxLength: 25, pattern: "[a-zA-Z]+" },
city: { minLength: 3, maxLength: 25, pattern: "[a-zA-Z]+" },
amount: { minLength: 1, maxLength: 9, pattern: "[0-9]+" },
};
/* Numbers Only: strictly numbers
Alphabets Only: strictly alphabets
Alphanumeric: mix
Password: a minimum of 8 characters
*/