Skip to content

Commit

Permalink
feat: add animation to menu box
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Jan 2, 2024
1 parent 184bb09 commit 17027e2
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState } from 'react';
import { IoMenu, IoClose } from 'react-icons/io5/index';
import { AnimatePresence, motion } from 'framer-motion';

import { Tooltip } from '@/components/tooltip';
import { useSoundStore } from '@/store';
import { slideY, fade, mix } from '@/lib/motion';

import styles from './menu.module.css';

Expand All @@ -11,24 +12,33 @@ export function Menu() {

const shuffle = useSoundStore(state => state.shuffle);

const variants = mix(slideY(-20), fade());

return (
<div className={styles.wrapper}>
<Tooltip content="Menu" hideDelay={0} showDelay={0}>
<button
className={styles.menuButton}
onClick={() => setIsOpen(prev => !prev)}
>
{isOpen ? <IoClose /> : <IoMenu />}
</button>
</Tooltip>
<button
aria-label="Menu"
className={styles.menuButton}
onClick={() => setIsOpen(prev => !prev)}
>
{isOpen ? <IoClose /> : <IoMenu />}
</button>

{isOpen && (
<div className={styles.menu}>
<button className={styles.menuItem} onClick={shuffle}>
Shuffle Sounds
</button>
</div>
)}
<AnimatePresence>
{isOpen && (
<motion.div
animate="show"
className={styles.menu}
exit="hidden"
initial="hidden"
variants={variants}
>
<button className={styles.menuItem} onClick={shuffle}>
Shuffle Sounds
</button>
</motion.div>
)}
</AnimatePresence>
</div>
);
}

0 comments on commit 17027e2

Please sign in to comment.