Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ Add Slide Animation to Carousel Navigation Buttons Using Framer Motion 🚀 (Fixes #415) #425

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions frontend/src/components/ui/ReviewCarousel.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { motion } from 'framer-motion';

const ReviewCarousel = () => {
const [active, setActive] = useState(3);
Expand Down Expand Up @@ -148,8 +149,29 @@ const ReviewCarousel = () => {

))}

<button id="next" className=' absolute top-[40%] text-green-900 bg-none border-none text-6xl font-mono font-bold opacity-80 transition-opacity z-10 right-[50px] max-sm:text-white max-sm:text-2xl max-sm:right-2' onClick={() => setActive(prev => (prev + 1 < items.length ? prev + 1 : prev))}>{">>"}</button>
<button id="prev" className=' absolute top-[40%] text-green-900 bg-none border-none text-6xl font-mono font-bold opacity-80 transition-opacity z-10 left-[50px] max-sm:text-white max-sm:text-2xl max-sm:left-2' onClick={() => setActive(prev => (prev - 1 >= 0 ? prev - 1 : prev))}> {"<<"}</button>
{// Changed Buttons to motion.button provided by framer
// whileHover is a framer specific attribute
// It displaces buttons by 10px on hover for that nice slide animation
}
<motion.button
id="next"
className=" absolute top-[40%] text-green-900 bg-none border-none text-6xl font-mono font-bold opacity-80 transition-opacity z-10 right-[50px] max-sm:text-white max-sm:text-2xl max-sm:right-2"
onClick={() =>
setActive((prev) => (prev + 1 < items.length ? prev + 1 : prev))
}
whileHover={{ x: 10, color: '#00B2CA', opacity: 1 }}
>
{'>>'}
</motion.button>
<motion.button
id="prev"
className=" absolute top-[40%] text-green-900 bg-none border-none text-6xl font-mono font-bold opacity-80 transition-opacity z-10 left-[50px] max-sm:text-white max-sm:text-2xl max-sm:left-2"
onClick={() => setActive((prev) => (prev - 1 >= 0 ? prev - 1 : prev))}
whileHover={{ x: -10, color: '#00B2CA', opacity: 1 }}
>
{' '}
{'<<'}
</motion.button>
</div>
</div>
);
Expand Down
Loading