Skip to content

Commit 6baa287

Browse files
authored
Merge pull request #140 from w3bdesign/development
Styling mobile menu
2 parents 1d0593d + 2445af9 commit 6baa287

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

src/components/Layout/MobileMenu.component.tsx

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useRef } from "react";
44
import { useClickAway } from "react-use";
55
import Link from "next/link";
6+
import { usePathname } from "next/navigation";
67

78
import { AnimatePresence, useCycle, motion } from "framer-motion";
89

@@ -20,15 +21,10 @@ interface IMobileMenuProps {
2021
links: ILink[];
2122
}
2223

23-
/**
24-
* Renders the mobile menu component with animation and navigation links.
25-
*
26-
* @param {IMobileMenuProps} links - Array of navigation links
27-
* @return {JSX.Element} - Rendered mobile menu component
28-
*/
2924
const MobileMenu = ({ links }: IMobileMenuProps) => {
3025
const [isExpanded, setisExpanded] = useCycle<boolean>(false, true);
3126
const ref = useRef(null);
27+
const pathname = usePathname();
3228

3329
const handleClickOutside = () => {
3430
setisExpanded(0);
@@ -57,12 +53,6 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
5753
};
5854

5955
const itemVariants = {
60-
/**
61-
* Returns an object with the CSS properties for a closed animation.
62-
*
63-
* @param {number} i - The index of the item being animated.
64-
* @return {Object} An object with CSS properties for the closed animation.
65-
*/
6656
closed: (i: number) => ({
6757
x: i % 2 === 0 ? "-100%" : "100%",
6858
opacity: 0,
@@ -73,19 +63,6 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
7363
duration: 0.15,
7464
},
7565
}),
76-
/**
77-
* Returns an object representing the animation properties for opening an item.
78-
*
79-
* @param {number} i - The index of the item.
80-
* @return {object} An object with the following properties:
81-
* - x: The x-coordinate of the item.
82-
* - opacity: The opacity of the item.
83-
* - transition: An object representing the animation properties.
84-
* - type: The type of the animation.
85-
* - stiffness: The stiffness of the animation.
86-
* - damping: The damping of the animation.
87-
* - delay: The delay of the animation.
88-
*/
8966
open: (i: number) => ({
9067
x: 0,
9168
opacity: 1,
@@ -137,7 +114,7 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
137114
({ title, name, hash, href, externalLink }, index) => (
138115
<motion.li
139116
key={title}
140-
className="block p-4 text-xl text-white hover:underline mx-auto text-center border-t border-b border-gray-600 border-solid shadow"
117+
className="block p-4 text-xl text-white mx-auto text-center border-t border-b border-gray-600 border-solid shadow"
141118
data-cy="mobile-menu-item"
142119
custom={index}
143120
variants={itemVariants}
@@ -149,6 +126,7 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
149126
target="_blank"
150127
rel="noreferrer"
151128
data-testid={`mobil-${name}`}
129+
className="flex w-full items-center justify-center px-2 py-2 hover:text-white transition font-semibold text-lg"
152130
>
153131
{name}
154132
</a>
@@ -157,12 +135,29 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
157135
href={href}
158136
data-testid={`mobil-${name}`}
159137
prefetch={true}
138+
className={`flex w-full items-center justify-center px-2 py-2 hover:text-white transition font-semibold text-lg ${
139+
pathname === href ? "text-green-400" : ""
140+
}`}
160141
>
161-
{name}
142+
<div className="glitch relative" data-text={name}>
143+
{name}
144+
<motion.span
145+
className={`absolute bottom-0 left-0 h-0.5 bg-current ${
146+
pathname === href ? "bg-green-400" : "bg-white"
147+
}`}
148+
initial={{
149+
width: pathname === href ? "100%" : "0%",
150+
}}
151+
animate={{
152+
width: pathname === href ? "100%" : "0%",
153+
}}
154+
transition={{ duration: 0.3 }}
155+
/>
156+
</div>
162157
</Link>
163158
)}
164159
</motion.li>
165-
),
160+
)
166161
)}
167162
</motion.ul>
168163
</nav>

0 commit comments

Comments
 (0)