2022-10-12 15:41:03 +00:00
|
|
|
import React from 'react'
|
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)}%`
|
2022-09-14 16:47:52 +00:00
|
|
|
|
2022-10-20 15:39:21 +00:00
|
|
|
let bgColorClass = 'bg-green-500'
|
|
|
|
if (value < 1 / 3) {
|
|
|
|
bgColorClass = 'bg-red-500'
|
|
|
|
} else if (value < 2 / 3) {
|
|
|
|
bgColorClass = 'bg-yellow-500'
|
|
|
|
}
|
|
|
|
|
2022-09-14 16:47:52 +00:00
|
|
|
return (
|
2022-11-09 09:04:06 +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-10-20 15:39:21 +00:00
|
|
|
className={`absolute z-10 h-4 rounded-full ${bgColorClass}`}
|
2022-09-14 16:47:52 +00:00
|
|
|
style={{ width: percentageValue }}
|
|
|
|
/>
|
2022-11-09 09:04:06 +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}
|
|
|
|
</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
|