mirror of
https://github.com/RealKai42/qwerty-learner.git
synced 2026-04-05 06:19:08 +08:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import React, { useEffect, useState } from 'react'
|
|
|
|
export type ProgressProps = {
|
|
order: number
|
|
wordsLength: number
|
|
}
|
|
|
|
const Progress: React.FC<ProgressProps> = ({ order, wordsLength }) => {
|
|
const [progress, setProgress] = useState<number>(0)
|
|
const [phase, setPhase] = useState<number>(0)
|
|
|
|
const colorSwitcher: { [key: number]: string } = {
|
|
0: 'bg-indigo-200 dark:bg-indigo-300',
|
|
1: 'bg-indigo-300 dark:bg-indigo-400',
|
|
2: 'bg-indigo-400 dark:bg-indigo-500',
|
|
}
|
|
|
|
useEffect(() => {
|
|
const newProgress = Math.floor((order / wordsLength) * 100)
|
|
setProgress(newProgress)
|
|
const colorPhase = Math.floor(newProgress / 33.4)
|
|
setPhase(colorPhase)
|
|
}, [order, wordsLength])
|
|
|
|
return (
|
|
<div className="relative mt-auto w-1/4 pt-1">
|
|
<div className="mb-4 flex h-2 overflow-hidden rounded-large bg-indigo-100 text-xs transition-all duration-300 dark:bg-indigo-200">
|
|
<div
|
|
style={{ width: `${progress}%` }}
|
|
className={`flex flex-col justify-center whitespace-nowrap rounded-large text-center text-white shadow-none transition-all duration-300 ${
|
|
colorSwitcher[phase] ?? 'bg-indigo-200 dark:bg-indigo-300'
|
|
}`}
|
|
></div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Progress
|