Skip to content

Commit 8afa9bb

Browse files
committed
fix: improve context menu animation
1 parent 7f3db83 commit 8afa9bb

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

src/animations/variants.ts

+18
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ export const pageVariants = {
1212
x: '-100vw',
1313
},
1414
};
15+
16+
export const menuVariants = {
17+
open: {
18+
opacity: 1,
19+
scale: 1,
20+
y: 100,
21+
transition: {
22+
opacity: { duration: 0.1 },
23+
scale: { type: 'spring', stiffness: 260, damping: 20 },
24+
},
25+
},
26+
closed: {
27+
y: 100,
28+
opacity: 0,
29+
scale: 0.95,
30+
transition: { duration: 0.1 },
31+
},
32+
};

src/components/ContextMenu/ContextMenu.module.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
position: absolute;
88
bottom: 0;
99
right: 0;
10-
width: 200px;
10+
width: 150px;
1111
padding: 8px 0;
1212
border-radius: 8px;
1313
background-color: $color-bg;
14-
transform: translateY(100%);
14+
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
1515
}

src/components/ContextMenu/ContextMenu.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import styles from './ContextMenu.module.scss';
33
import { useOutsideClickRef } from 'rooks';
44
import DropdownToggle from './ContextMenuToggle';
55
import type { IContextMenuItem } from './ContextMenuItem';
6+
import { AnimatePresence, motion } from 'framer-motion';
7+
import { menuVariants } from '@/animations/variants';
68

79
interface IContextMenu {
810
children: ReactElement<IContextMenuItem> | ReactElement<IContextMenuItem>[];
@@ -20,7 +22,19 @@ const ContextMenu = ({ children }: IContextMenu) => {
2022
return (
2123
<div className={styles.menu} ref={ref}>
2224
<DropdownToggle onClick={toggleHandler} />
23-
{isOpen && <ul className={styles.list}>{children}</ul>}
25+
<AnimatePresence>
26+
{isOpen && (
27+
<motion.ul
28+
className={styles.list}
29+
initial='closed'
30+
animate='open'
31+
exit='closed'
32+
variants={menuVariants}
33+
>
34+
{children}
35+
</motion.ul>
36+
)}
37+
</AnimatePresence>
2438
</div>
2539
);
2640
};
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.item {
22
display: flex;
33
align-items: center;
4-
padding: 4px 16px;
4+
padding: 8px 16px;
55
cursor: pointer;
66

77
&:hover {
8-
background-color: $color-bg;
8+
background-color: $color-hover;;
99
}
1010

11-
&[data-variant='danger'] {
11+
&[data-variant='info'] {
1212
color: $color-text;
1313
fill: $color-text;
1414
}
@@ -20,5 +20,5 @@
2020
}
2121

2222
.label {
23-
margin-left: 20px;
23+
margin-left: 8px;
2424
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.toggle {
2-
background-color: red;
32
background-color: transparent;
43
border: none;
5-
}
4+
cursor: pointer;
5+
fill:$color-text;
6+
}

src/styles/_theme.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
--color-button-text: #ffffff;
2323

2424
/* Other */
25-
--color-hover: #f1f1f1;
25+
--color-hover: #f1f1f1d9;
2626
}
2727

2828
&[data-theme='dark'] {

0 commit comments

Comments
 (0)