From 7dc86f073108b6a8b403127732a093a301d6857e Mon Sep 17 00:00:00 2001 From: Pkpedram Date: Wed, 2 Feb 2022 16:11:41 +0330 Subject: [PATCH] Verification Input Done --- src/components/verificationInput/index.js | 58 +++++++++++++++++++++++ src/view/LoginSignUp/index.js | 38 +++++++++------ tailwind.config.js | 1 + 3 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 src/components/verificationInput/index.js diff --git a/src/components/verificationInput/index.js b/src/components/verificationInput/index.js new file mode 100644 index 0000000..8f326a5 --- /dev/null +++ b/src/components/verificationInput/index.js @@ -0,0 +1,58 @@ +import React from 'react'; +import './VerificationInput.css'; + +export default class VerificationInput extends React.Component { + + render() { + + const numOfFields = 3; + +const handleChange = e => { + const { maxLength, value, name } = e.target; + const [fieldName, fieldIndex] = name.split("-"); + + // Check if they hit the max character length + if (value.length >= maxLength) { + // Check if it's not the last input field + if (parseInt(fieldIndex, 10) < 4) { + // Get the next input field + const nextSibling = document.querySelector( + `input[name=ssn-${parseInt(fieldIndex, 10) + 1}]` + ); + + // If found, focus the next field + if (nextSibling !== null) { + nextSibling.focus(); + } + } + } +} + + + return( +
+ {[0,1,2,3].map((item, index) => ( + {if (!/[0-9]/.test(evt.key)){evt.preventDefault();}}} + autoFocus={index == 0 && true}/> + )) + + } + + + + + +
+ ); + } +} diff --git a/src/view/LoginSignUp/index.js b/src/view/LoginSignUp/index.js index 557fe5e..d6d3f7c 100644 --- a/src/view/LoginSignUp/index.js +++ b/src/view/LoginSignUp/index.js @@ -6,12 +6,13 @@ import secondPic from '../../assets/img/undraw_quiz_nlyh.svg'; import thirdPic from '../../assets/img/undraw_certificate_re_yadi.svg'; import { Slide } from 'react-slideshow-image'; import './index.css'; +import VerificationInput from "../../components/verificationInput"; const LoginSignUp = ({ activeLogin }) => { const [steps, setSteps] = useState(0); const [index, setIndex] = useState(0); - + const timeoutRef = useRef(null); const focusHandler = (id) => { @@ -23,20 +24,20 @@ const LoginSignUp = ({ activeLogin }) => { label[id].style.transform = "translate(-10px,-27px)"; label[id].style.color = "#df1452"; line[id].style.backgroundColor = "#fff"; - }; - - const blurHandler = (id) => { + }; + + const blurHandler = (id) => { let inputsBox = document.querySelectorAll(".Login-box-form-item"); let inputs = document.querySelectorAll(".Login-box-form-item-input"); let label = document.querySelectorAll(".Login-box-form-item-label"); let line = document.querySelectorAll(".Login-box-form-item-line"); if (inputs[id].value === "") { - inputsBox[id].style.borderColor = "#EBEBEB"; - label[id].style.transform = "translate(0px,0px)"; - label[id].style.color = "#959595"; - line[id].style.backgroundColor = "#EBEBEB"; + inputsBox[id].style.borderColor = "#EBEBEB"; + label[id].style.transform = "translate(0px,0px)"; + label[id].style.color = "#959595"; + line[id].style.backgroundColor = "#EBEBEB"; } - }; + }; function resetTimeout() { if (timeoutRef.current) { clearTimeout(timeoutRef.current); @@ -85,12 +86,12 @@ const LoginSignUp = ({ activeLogin }) => {
- { steps != 0 && -
setSteps(steps - 1)}> - {`>`} + {steps != 0 && +
setSteps(steps - 1)}> + {`>`} +
+ }
-} -

ورود یا ثبت نام

@@ -156,6 +157,15 @@ const LoginSignUp = ({ activeLogin }) => { } + { + steps == 2 && + <> +
+ +
+ + + }
diff --git a/tailwind.config.js b/tailwind.config.js index f8945dc..526a16a 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -25,6 +25,7 @@ module.exports = { color19: "#959595", //register input label red26: '#521326', red52: '#df1452', + red46OP: 'rgba(255, 246, 246, 0.8)', grayEC: '#ececec' }, },