2022-09-29 19:21:31 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
|
import { ArrowRightIcon } from '@heroicons/react/24/solid'
|
2022-09-14 16:47:52 +00:00
|
|
|
|
|
|
|
type Props = {
|
2022-09-29 19:21:31 +00:00
|
|
|
value: number
|
|
|
|
}
|
2022-09-14 16:47:52 +00:00
|
|
|
|
|
|
|
const ProgressBar = ({ value }: Props) => {
|
2022-09-29 19:21:31 +00:00
|
|
|
const percentageValue = `${(value * 100).toFixed(0)}%`
|
|
|
|
const [newValue, setNewValue] = useState(0.77)
|
2022-09-14 16:47:52 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setInterval(() => {
|
|
|
|
// randomizing value between value and 1
|
2022-09-29 19:21:31 +00:00
|
|
|
setNewValue(Math.random() * (1 - value) + value)
|
|
|
|
}, 3000)
|
|
|
|
}, [value])
|
2022-09-14 16:47:52 +00:00
|
|
|
|
2022-09-29 19:21:31 +00:00
|
|
|
const percentageNewValue = `${(newValue * 100).toFixed(0)}%`
|
2022-09-14 16:47:52 +00:00
|
|
|
|
|
|
|
return (
|
2022-09-30 12:50:16 +00:00
|
|
|
<div className="relative z-0 h-4 w-[130px] rounded-full bg-black">
|
2022-09-14 16:47:52 +00:00
|
|
|
<div
|
2022-09-30 12:50:16 +00:00
|
|
|
className="absolute z-10 h-4 rounded-full bg-green-500"
|
2022-09-14 16:47:52 +00:00
|
|
|
style={{ width: percentageValue }}
|
|
|
|
/>
|
|
|
|
<div
|
2022-09-30 12:50:16 +00:00
|
|
|
className="absolute h-4 rounded-full bg-red-500 transition-[width] duration-500"
|
2022-09-14 16:47:52 +00:00
|
|
|
style={{ width: percentageNewValue }}
|
|
|
|
/>
|
2022-09-30 12:50:16 +00:00
|
|
|
<div className="absolute z-20 flex w-full items-center justify-center gap-x-2 text-xs font-medium text-white">
|
2022-09-14 16:47:52 +00:00
|
|
|
{percentageValue}
|
|
|
|
<ArrowRightIcon className="h-3 w-3" />
|
|
|
|
{percentageNewValue}
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-29 19:21:31 +00:00
|
|
|
)
|
|
|
|
}
|
2022-09-14 16:47:52 +00:00
|
|
|
|
2022-09-29 19:21:31 +00:00
|
|
|
export default ProgressBar
|