<div id='app'></div>
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap");
html,
body,
#app {
height: 100vh;
}
body {
margin: 0;
background: black;
color: black;
font-size: 1.2em;
font-family: "Montserrat", sans-serif;
font-weight: 600;
}
h1 {
font-size: 1.2em;
}
p {
font-size: 0.8em;
}
#app {
display: flex;
justify-content: center;
align-items: center;
}
.box {
display: grid;
align-items: center;
width: 25%;
height: 50%;
padding: 2em 3em;
background: white;
border-radius: 5px;
}
.box > div {
display: flex;
flex-direction: column;
align-self: center;
width: 100%;
grid-row: 2/3;
}
a {
color: #3274d7;
font-weight: 600;
grid-row: 1/2;
cursor: pointer;
}
a:hover {
color: #284bc7;
}
input {
width: 90%;
height: 2em;
padding: 0.5em 1em;
background: #c4c4c4;
border: none;
border-radius: 5px;
}
input.error {
border: 1px solid red;
}
input[type="submit"] {
background: linear-gradient(45deg, #607cde 0%, #284bc7 60%);
color: white;
border: none;
cursor: pointer;
grid-row: 3/4;
width: 8em;
padding: 0.5em 1em;
font-weight: 600;
border-radius: 5px;
}
input[type="submit"]:hover {
background: #284bc7;
}
input[type="submit"]:disabled {
opacity: 0.5;
}
@media (max-width: 700px) {
.box {
width: 65%;
}
}
function Input(props) {
return (
<div>
<label htmlFor={props.label.toLowerCase()}>{props.label}</label>
<input
type={props.type}
name={props.label.toLowerCase()}
id={props.label.toLowerCase()}
onInput={props.onInput}
minLength={props.type === "password" ? "8" : "2"}
value={props.value}
required
/>
</div>
);
}
class App extends React.Component {
state = {
submit: { name: "", email: "", date: "", password: "" },
page: 0,
};
onInput = (event) => {
const submit = this.state.submit;
const currentInput = event.currentTarget;
if (currentInput.id === "name") {
submit.name = currentInput.value;
} else if (currentInput.id === "email") {
submit.email = currentInput.value;
} else if (currentInput.id === "date") {
submit.date = currentInput.value;
} else {
submit.password = currentInput.value;
}
this.setState({ submit });
};
next = (event) => {
event.preventDefault();
let page = this.state.page;
if (event.target.parentElement[0].checkValidity()) {
page++;
this.setState({ page });
document.querySelector("input").classList.remove("error");
document.querySelector("input").value = "";
} else {
document.querySelector("input").classList.add("error");
}
};
back = () => {
let page = this.state.page;
page--;
this.setState({ page });
document.querySelector("input").classList.remove("error");
};
renderInputs = () => {
if (this.state.page === 0) {
return (
<Input
type="text"
label="Name"
onInput={this.onInput}
value={this.state.submit.name}
/>
);
} else if (this.state.page === 1) {
return (
<Input
type="email"
label="Email"
onInput={this.onInput}
value={this.state.submit.email}
/>
);
} else if (this.state.page === 2) {
return (
<Input
type="date"
label="Date"
onInput={this.onInput}
value={this.state.submit.date}
/>
);
} else if (this.state.page === 3) {
return (
<Input
type="password"
label="Password"
onInput={this.onInput}
value={this.state.submit.password}
/>
);
} else {
return [
<h1>Details</h1>,
<p>Name: {this.state.submit.name}</p>,
<p>Email: {this.state.submit.email}</p>,
<p>Date: {this.state.submit.date}</p>,
<p>Password: {this.state.submit.password}</p>,
];
}
};
render() {
return (
<form className="box">
{this.state.page > 0 && this.state.page < 4 ? (
<a onClick={this.back}>{"< Back"}</a>
) : null}
{this.renderInputs()}
{this.state.page >= 0 && this.state.page <= 3 ? (
<input
type="submit"
onClick={this.next}
value={this.state.page === 3 ? "Submit" : "Next"}
/>
) : null}
</form>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));
View Compiled
This Pen doesn't use any external CSS resources.