-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProgressBar.jsx
70 lines (63 loc) · 1.68 KB
/
ProgressBar.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useEffect, useState } from "react";
import GoToHome from "../../Components/GoToHome";
import "./style.css";
import { MAX, MIN } from "./constants";
const ProgressBar = () => {
const [value, setValue] = useState(0);
const [success, setSuccess] = useState(false);
useEffect(() => {
setInterval(() => {
setValue(val => val + 1);
}, 100);
}, []);
return (
<div>
<div className="flex justify-center items-center flex-col h-screen">
<h1>Progress bar</h1>
<div className="mb-56 flex flex-col">
<ProgressBarr value={value} onComplete={() => setSuccess(true)} />
<span className="">
{success ? "Complete!" : "Loading..."}
</span>
<button className="custom-button w-32 mt-10" onClick={() => window.location.reload()}>Restart </button>
</div>
<GoToHome />
</div>
</div>
);
};
function ProgressBarr({ value = 0, onComplete = () => {} }) {
const [percent, setPercent] = useState(value);
useEffect(
() => {
setPercent(Math.min(Math.max(value, MIN), MAX));
if (value >= MAX) {
onComplete();
}
},
[value]
);
return (
<div className="progress">
<span
style={{
color: percent > 49 ? "white" : "black"
}}
>
{percent.toFixed()}%
</span>
<div
// style={{ width: `${percent}%` }}
style={{
transform: `scaleX(${percent / MAX})`,
transformOrigin: "left"
}}
aria-valuemin={MIN}
aria-valuemax={MAX}
aria-valuenow={percent}
role="ProgressBarr"
/>
</div>
);
}
export default ProgressBar;