From be9e79528ad94f8bf206ef1a4dbf617a9774329d Mon Sep 17 00:00:00 2001 From: mahdi Date: Sun, 1 May 2022 08:40:36 +0430 Subject: [PATCH] update App.js, Input.js, src/components/FormInput/index.js and src/components/TestComponentNew/index.js --- src/App.js | 4 +- src/components/FormInput/Input.js | 4 +- src/components/FormInput/index.js | 1 + src/components/TestComponentNew/fixNumbers.js | 22 +++++++ src/components/TestComponentNew/index.js | 15 +++++ src/components/TestComponentNew/input.js | 65 +++++++++++++++++++ 6 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 src/components/TestComponentNew/fixNumbers.js create mode 100644 src/components/TestComponentNew/input.js diff --git a/src/App.js b/src/App.js index b66009b..caf6076 100644 --- a/src/App.js +++ b/src/App.js @@ -213,7 +213,7 @@ function App() { {/* */} - + {/* */} {/* ----------------------------$$$ start---------------------------- */} {/* @@ -272,7 +272,7 @@ function App() { {/* */} {/* */} - {/* */} + ); diff --git a/src/components/FormInput/Input.js b/src/components/FormInput/Input.js index 122fb8d..35994f6 100644 --- a/src/components/FormInput/Input.js +++ b/src/components/FormInput/Input.js @@ -25,12 +25,12 @@ const FormFields = ({ className={ "h-full flex flex-row items-center rounded border mx-1 relative " + borderClassname + - (value ? " bg-white border rounded" : " bg-transparent") + (value ? "bg-white border rounded" : "bg-transparent") } >
{ return (
+ { // defaultValue={info?.firstName} label="نام " /> +
{ // defaultValue={info?.firstName} label="نام " /> +
{ // defaultValue={info?.firstName} label="نام " /> +
diff --git a/src/components/TestComponentNew/input.js b/src/components/TestComponentNew/input.js new file mode 100644 index 0000000..298c90b --- /dev/null +++ b/src/components/TestComponentNew/input.js @@ -0,0 +1,65 @@ +import fixNumbers from "./fixNumbers"; +import { useState } from "react"; +const Input = ({ + defaultValue, + set, + label, + className, + type, + maxLength, + max, + min, + register, +}) => { + const [value, setValue] = useState(defaultValue); + return ( +
+
+ {label} +
+ {type !== "textarea" ? ( + setValue(e.target.value)} + inputMode={type === "number" ? "numeric" : ""} + onInput={(e) => { + let value = e.target.value; + if (type === "number") + value = fixNumbers(value).replace(/[^\d.-]/g, ""); + if (maxLength && value.length > maxLength) + value = value.slice(0, maxLength); + if (!isNaN(max) && +e.target.value > max) value = max; + if (!isNaN(min) && +e.target.value < min) value = min; + e.target.value = value; + }} + /> + ) : ( + + )} +
+ ); +}; +export default Input;