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,
labalClass,
inputClass,
fieldClass,
onClick,
disable,
blurHandler,
spanTag,
inputBg,
onInput,
maxLength = 45,
minLength = 0,
direction,
tabIndex,
error,
autoComplete="on",
minDate='1900-01-01',
maxDate='2099-09-13'
}) {
const inputRef = useRef(null);
// Entry Validation
// for Min Length:
const minLengthValidation = () => {
const inputConfig = inputConfigs[inputRef?.current?.name]?.minLength;
return inputConfig || minLength;
};
// for MaxLength
const maxLengthValidation = () => {
const inputConfig = inputConfigs[inputRef?.current?.name]?.maxLength;
return inputConfig || maxLength;
};
// for Patterns
const inputPatterns = () => {
const inputConfig = inputConfigs[inputRef?.current?.name]?.pattern;
return inputConfig || "";
};
return (
{label && (
)}
{forgotPassword && (
Forgot Password?
)}
<>
{type == 'date' ?
:
}
>
{iconName && (
{iconName.split(" ").map((item, index) => (
))}
)}
{passIcon && (
)}
);
}
const inputConfigs = {
email: { minLength: 7, maxLength: 45 },
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: 299 },
title: { minLength: 5, maxLength: 149 },
job_detail: { minLength: 4, maxLength: 1440 },
cardNum: { minLength: 4, maxLength: 19 },
};
/* Numbers Only: strictly numbers
Alphabets Only: strictly alphabets
Alphanumeric: mix
Password: a minimum of 8 characters
*/