import { ChangeEvent, HTMLAttributes, InputHTMLAttributes, useState } from "react"; import "./Input.css"; import { getCN, randomId, usePadding, renderProps } from "../utils"; import FormField, { IFormField } from "../../componentsDefault/FormField/FormField"; export interface IInput extends InputHTMLAttributes { before?: IFormField["before"]; after?: IFormField["after"]; status?: IFormField["status"]; top?: IFormField["top"]; bottom?: IFormField["bottom"]; type?: "text" | "password" | "email" | "tel" | "number" | "hidden"; } function Input({ type = `text`, before, after, status, top, bottom, maxLength, value, onChange, ...props }: IInput) { const [props_id, setPropsId] = useState(randomId(props.id, `input_text`)); const hanldeChange = (e: ChangeEvent) => { if (Number(maxLength) && maxLength) { e.target.value = cleanString(String(e.target.value), maxLength); if (onChange) onChange(e) } else { if (onChange) onChange(e) } } return ( ); } const cleanString = (input: string, maxLength: number) => { var output = ""; for (var i = 0; i < input.length; i++) { if (output.length < maxLength) { output += input[i]; } } return output; } export default Input;