@@ -19,6 +19,12 @@ interface IMobileMenuProps {
19
19
links : ILink [ ] ;
20
20
}
21
21
22
+ /**
23
+ * Renders the mobile menu component with animation and navigation links.
24
+ *
25
+ * @param {IMobileMenuProps } links - Array of navigation links
26
+ * @return {JSX.Element } - Rendered mobile menu component
27
+ */
22
28
const MobileMenu = ( { links } : IMobileMenuProps ) => {
23
29
const [ isExpanded , setisExpanded ] = useCycle < boolean > ( false , true ) ;
24
30
const ref = useRef ( null ) ;
@@ -36,7 +42,7 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
36
42
type : "spring" ,
37
43
stiffness : 400 ,
38
44
damping : 40 ,
39
- delay : 0.2 , // Delay the menu closing to allow text to fade out first
45
+ delay : 0.2 ,
40
46
} ,
41
47
} ,
42
48
open : {
@@ -50,6 +56,12 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
50
56
} ;
51
57
52
58
const itemVariants = {
59
+ /**
60
+ * Returns an object with the CSS properties for a closed animation.
61
+ *
62
+ * @param {number } i - The index of the item being animated.
63
+ * @return {Object } An object with CSS properties for the closed animation.
64
+ */
53
65
closed : ( i : number ) => ( {
54
66
x : i % 2 === 0 ? "-100%" : "100%" ,
55
67
opacity : 0 ,
@@ -60,6 +72,19 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
60
72
duration : 0.15 ,
61
73
} ,
62
74
} ) ,
75
+ /**
76
+ * Returns an object representing the animation properties for opening an item.
77
+ *
78
+ * @param {number } i - The index of the item.
79
+ * @return {object } An object with the following properties:
80
+ * - x: The x-coordinate of the item.
81
+ * - opacity: The opacity of the item.
82
+ * - transition: An object representing the animation properties.
83
+ * - type: The type of the animation.
84
+ * - stiffness: The stiffness of the animation.
85
+ * - damping: The damping of the animation.
86
+ * - delay: The delay of the animation.
87
+ */
63
88
open : ( i : number ) => ( {
64
89
x : 0 ,
65
90
opacity : 1 ,
@@ -93,18 +118,18 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
93
118
variants = { menuVariants }
94
119
>
95
120
< nav aria-label = "Navigasjon" className = "w-full" >
96
- < motion . ul
121
+ < motion . ul
97
122
className = "w-full"
98
123
initial = "closed"
99
124
animate = "open"
100
125
exit = "closed"
101
126
variants = { {
102
127
open : {
103
- transition : { staggerChildren : 0.07 , delayChildren : 0.2 }
128
+ transition : { staggerChildren : 0.07 , delayChildren : 0.2 } ,
104
129
} ,
105
130
closed : {
106
- transition : { staggerChildren : 0.05 , staggerDirection : - 1 }
107
- }
131
+ transition : { staggerChildren : 0.05 , staggerDirection : - 1 } ,
132
+ } ,
108
133
} }
109
134
>
110
135
{ links . map ( ( { title, name, hash, href } , index ) => (
@@ -145,4 +170,4 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
145
170
) ;
146
171
} ;
147
172
148
- export default MobileMenu ;
173
+ export default MobileMenu ;
0 commit comments