This commit is contained in:
2024-06-11 21:18:54 +05:00
parent ac1a705187
commit e155066534
20 changed files with 520 additions and 113 deletions
+10 -5
View File
@@ -1,8 +1,9 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useMask } from "@react-input/mask";
import { useEffect, useState } from "react";
interface InputProps {
type?: "text" | "email" | "password" | "time";
type?: "text" | "email" | "password" | "time" | "tel";
placeholder?: string;
autoFocus?: boolean;
required?: boolean;
@@ -24,16 +25,20 @@ function Input({
handleChange,
handleFocus,
}: InputProps) {
const [value, setValue] = useState<string | undefined>(defaultValue);
const inputRef = useMask({
mask: "+7 (___) ___-__-__",
replacement: { _: /\d/ },
});
const [value, setValue] = useState<string>(defaultValue || "");
useEffect(() => {
if (value && handleChange) {
handleChange(value);
}
handleChange && handleChange(value);
}, [value]);
return (
<input
ref={type === "tel" ? inputRef : undefined}
type={type}
placeholder={placeholder}
autoFocus={autoFocus}