mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 17:04:15 +00:00
fix: replace the animation on button
This commit is contained in:
parent
3b0c22968e
commit
8307657628
1 changed files with 27 additions and 30 deletions
|
|
@ -20,6 +20,8 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
const [showAll, setShowAll] = useLocalStorage(`${id}-show-more`, false);
|
||||
const [clickedMore, setClickedMore] = useState(false);
|
||||
|
||||
const [isAnimating, setIsAnimating] = useState(false);
|
||||
|
||||
const firstNewSound = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -30,7 +32,6 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
}, [showAll, clickedMore]);
|
||||
|
||||
const showMoreButton = useRef<HTMLButtonElement>(null);
|
||||
const [exitComplete, setExitComplete] = useState(false);
|
||||
|
||||
const [hiddenSelections, setHiddenSelections] = useState<{
|
||||
[key: string]: boolean;
|
||||
|
|
@ -57,8 +58,10 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
}, []);
|
||||
|
||||
const toggleMore = () => {
|
||||
if (!isAnimating) {
|
||||
setShowAll(prev => !prev);
|
||||
setClickedMore(true);
|
||||
}
|
||||
};
|
||||
|
||||
const variants = mix(fade(), scale(0.9));
|
||||
|
|
@ -85,34 +88,28 @@ export function Sounds({ functional, id, sounds }: SoundsProps) {
|
|||
</div>
|
||||
|
||||
{sounds.length > 6 && (
|
||||
<AnimatePresence
|
||||
initial={false}
|
||||
mode="wait"
|
||||
onExitComplete={() => setExitComplete(true)}
|
||||
>
|
||||
<motion.button
|
||||
animate="show"
|
||||
exit="hidden"
|
||||
initial="hidden"
|
||||
key={showAll ? `${id}-show-less` : `${id}-show-more`}
|
||||
<button
|
||||
ref={showMoreButton}
|
||||
transition={{ duration: 0.2 }}
|
||||
variants={variants}
|
||||
className={cn(
|
||||
styles.button,
|
||||
hasHiddenSelection && !showAll && styles.active,
|
||||
)}
|
||||
onClick={toggleMore}
|
||||
onAnimationComplete={() => {
|
||||
if (!showAll && exitComplete) {
|
||||
setExitComplete(false);
|
||||
showMoreButton.current?.focus();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<AnimatePresence initial={false} mode="wait">
|
||||
<motion.span
|
||||
animate="show"
|
||||
exit="hidden"
|
||||
initial="hidden"
|
||||
key={showAll ? `${id}-show-less` : `${id}-show-more`}
|
||||
variants={variants}
|
||||
onAnimationComplete={() => setIsAnimating(false)}
|
||||
onAnimationStart={() => setIsAnimating(true)}
|
||||
>
|
||||
{showAll ? 'Show Less' : 'Show More'}
|
||||
</motion.button>
|
||||
</motion.span>
|
||||
</AnimatePresence>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue