import React, { useRef } from "react";
import { Link } from "react-router-dom";
import Icons from "../../Icons";
export default function InputCom({
label,
type,
name,
placeholder,
iconName,
passIcon,
inputHandler,
value,
forgotPassword,
parentClass,
labelClass,
inputClass,
fieldClass,
onClick,
disable,
blurHandler,
spanTag,
inputBg,
direction,
errorBorder,
}) {
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?
)}
{iconName && (
{iconName.split(" ").map((item, index) => (
))}
)}
{passIcon && (
)}
);
}
const inputConfigs = {
email: { minLength: 7, maxLength: 35 },
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]+" },
description: { minLength: 5, maxLength: 250 },
};
/* Numbers Only: strictly numbers
Alphabets Only: strictly alphabets
Alphanumeric: mix
Password: a minimum of 8 characters
*/