-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add chevrons to onboarding screens (#435)
- Loading branch information
1 parent
ad48646
commit 3b95d01
Showing
6 changed files
with
134 additions
and
59 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,40 @@ | ||
import { useEffect, useState } from 'react'; | ||
import cn from 'classnames'; | ||
|
||
export const ProgressBar = ({ itemsLength }: { itemsLength: number }) => { | ||
const [activeBarIndex, setActiveBarIndex] = useState<number>(0); | ||
const [filledSegments, setFilledSegments] = useState<boolean[]>(Array(itemsLength).fill(false)); | ||
export const ProgressBar = ({ | ||
activeIndex, | ||
filledSegments, | ||
}: { | ||
activeIndex: number; | ||
filledSegments: boolean[]; | ||
}) => { | ||
const [animateIndex, setAnimateIndex] = useState<number | null>(null); | ||
|
||
useEffect(() => { | ||
if (activeBarIndex !== 0) return; | ||
const timeout = setTimeout(() => { | ||
setFilledSegments([true, ...Array(itemsLength - 1).fill(false)]); | ||
}, 300); | ||
setAnimateIndex(activeIndex); | ||
}, [activeIndex]); | ||
|
||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
}, [activeBarIndex]); | ||
const bars = filledSegments.map((isFilled, index) => { | ||
const shouldAnimate = index === animateIndex; | ||
|
||
useEffect(() => { | ||
const intervalId = setInterval(() => { | ||
if (activeBarIndex === filledSegments.length - 1) { | ||
setFilledSegments(Array(itemsLength).fill(false)); | ||
setActiveBarIndex(0); | ||
return; | ||
} | ||
const newArray = [...filledSegments]; | ||
newArray[activeBarIndex + 1] = true; | ||
setFilledSegments(newArray); | ||
setActiveBarIndex((prevIndex) => (prevIndex + 1) % itemsLength); | ||
}, 4900); | ||
|
||
return () => clearInterval(intervalId); | ||
}, [filledSegments, itemsLength]); | ||
|
||
const bars = filledSegments.map((isFilled, index) => ( | ||
<div | ||
key={index} | ||
className='relative h-1.25 w-full overflow-hidden rounded-2.5xl bg-theme-secondary-200 dark:bg-theme-secondary-600' | ||
> | ||
return ( | ||
<div | ||
className={cn('h-full rounded-3xl bg-theme-primary-700 dark:bg-theme-primary-650', { | ||
'w-full': isFilled, | ||
'w-0': !isFilled, | ||
})} | ||
style={{ | ||
transition: | ||
activeBarIndex === index && isFilled ? 'width 5s ease-in-out' : 'unset', | ||
}} | ||
/> | ||
</div> | ||
)); | ||
key={index} | ||
className='relative h-1.25 w-full overflow-hidden rounded-2.5xl bg-theme-secondary-200 dark:bg-theme-secondary-600' | ||
> | ||
<div | ||
className={cn( | ||
'h-full rounded-3xl bg-theme-primary-700 dark:bg-theme-primary-650', | ||
{ | ||
'w-full': isFilled, | ||
'w-0': !isFilled, | ||
'animate-fillProgress': shouldAnimate, | ||
}, | ||
)} | ||
/> | ||
</div> | ||
); | ||
}); | ||
|
||
return <div className='flex gap-2'>{bars}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters