Currently, I am working on developing a login page for my project. Below is the code snippet I have implemented for the functionality:
import React, { useState, createRef } from "react";
import { Spinner } from "react-bootstrap";
import { ClipLoader } from "react-spinners";
import "./style.css";
function Login() {
const [loading, setLoading] = useState(false);
const [disabled, setDisabled] = useState(false);
const makeBlurEffect = () => {
setLoading(true);
setDisabled(true);
};
return (
<div class= {loading ? 'blur' : 'container'}>
<div>
<input type="text" placeholder="username" />
<br></br><br></br><br></br>
<input type="text" placeholder="password" />
<br></br><br></br><br></br>
<button onClick={makeBlurEffect} disabled={disabled}>
login
</button>
<br></br><br></br><br></br>
</div>
{loading ? (
<div id="loadingDiv" class="box stack-top" style={{ background: "white", border: "2px solid black" }}>
<ClipLoader />
<span id="loadingDivText" style={{ fontWeight: "bold", fontSize: "30px" }}>
Loading...
</span>
</div>
) : null}
</div>
);
}
export default Login;
//end
CSS Styling:
body{
background: black;
}
.container{
width: 200px;
height: 200px;
position: relative;
margin-top: 200px;
margin-left: 500px;
justify-content: center;
align-items: center;
}
.box{
width: 100%;
height: 100%;
position: absolute;
left: 0;
opacity: 0.8;
display: flex;
justify-content: center;
align-items: center;
}
.stack-top{
z-index: 9;
margin: -20px -20px -20px -80px;
width: 400px;
height: 150px;
opacity: 1;
}
.blur{
width: 200px;
height: 200px;
position: relative;
margin-top: 200px;
margin-left: 500px;
justify-content: center;
align-items: center;
filter: blur(2px);
}
I am currently facing an issue where clicking on the login button triggers the blur effect for the entire screen instead of just the background. Any suggestions on how to solve this problem will be greatly appreciated.
Additionally, I attempted to use the opacity toggle approach but encountered an error message stating "unable to setProperty of null" when trying to apply it in the following way:
document.getElementById("loadingDiv").style.opacity = 1;
--------------edit
Modified login.js:
import React, { useState, createRef } from "react";
import { Spinner } from "react-bootstrap";
import { ClipLoader } from "react-spinners";
import "./style.css";
function Login() {
const [loading, setLoading] = useState(false);
const [disabled, setDisabled] = useState(false);
const makeBlurEffect = () => {
setLoading(true);
setDisabled(true);
};
return (
<div>
{loading ? (
<div
class="box stack-top"
style={{ background: "white", border: "2px solid black" }}
>
<ClipLoader />
<span
style={{ fontWeight: "bold", fontSize: "30px" }}
>
Loading...
</span>
</div>
) : null}
<div class={loading ? "blur" : "container"}>
<div>
<input type="text" placeholder="username" />
<br></br><br></br><br></br>
<input type="text" placeholder="password" />
<br></br><br></br><br></br>
<button onClick={makeBlurEffect} disabled={disabled}>
login
</button>
<br></br><br></br><br></br>
</div>
</div>
</div>
);
}
export default Login;
//end
Updated style.css:
body{
background: black;
}
.container{
width: 200px;
height: 200px;
position: relative;
margin-top: 200px;
margin-left: 500px;
justify-content: center;
align-items: center;
}
.box{
width: 100%;
height: 100%;
position: absolute;
margin-left: 100px;
justify-self: center;
opacity: 0.8;
display: flex;
justify-content: center;
align-items: center;
}
.stack-top{
z-index: 9;
margin: -20px -20px -20px -80px;
width: 400px;
height: 150px;
opacity: 1;
}
.blur{
width: 200px;
height: 200px;
position: relative;
margin-top: 200px;
margin-left: 500px;
justify-content: center;
align-items: center;
filter: blur(2px);
}
With the latest changes, the blur effect now works correctly, however, there is an alignment issue where the div does not appear centered. How can I address this alignment problem?