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

Enhance Homepage Components with Framer Motion Animations #177

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0",
"react-intersection-observer": "^9.5.3",
"react-leaflet": "^4.2.1",
"react-responsive": "^9.0.2",
"react-router-dom": "^6.3.0",
Expand Down
30 changes: 25 additions & 5 deletions src/components/EventCard/EventCard.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { motion, useAnimation } from "framer-motion";
import Image from "next/image";
import Link from "next/link";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { FaCalendarAlt } from "react-icons/fa";
import { useInView } from "react-intersection-observer";

import Button from "../Buttons/Button";

const EventCard = ({ t }) => {
const controls = useAnimation();
const [ref, inView] = useInView({ triggerOnce: true });
const data = [
{
id: 1,
Expand Down Expand Up @@ -38,18 +43,33 @@ const EventCard = ({ t }) => {
},
];
const [event, setEvent] = useState(data);
useEffect(() => {
if (inView) {
controls.start({ opacity: 1, x: 0, y: 0 });
}
}, [controls, inView]);
return (
<section className='p-4'>
<section className='p-4' ref={ref}>
<div className='flex flex-col justify-center items-center shadow-lg border-t-2 bg-gray-200 pt-10 pb-5'>
<h1 className='mb-10 text-3xl font-bold text-[#585785]'>
{t("Upcoming Events")}
</h1>
<div className='mx-auto lg:flex-row flex-col text-center flex items-center overflow-hidden'>
{event.map((event, eventIndex) => {
{event.map((event, i) => {
const { id, image, title, description, date, link } =
event;
return (
<div key={id} className='p-4 w-120 h-120 flex-1'>
<motion.div
key={id}
className='p-4 w-120 h-120 flex-1'
initial={{
opacity: 0,
x: i % 2 === 0 ? -50 : 50,
y: -50,
}}
animate={controls}
transition={{ duration: 0.8, delay: i * 0.7 }}
>
<article
className={` w-full rounded-lg bg-white shadow-lg `}
>
Expand Down Expand Up @@ -90,7 +110,7 @@ const EventCard = ({ t }) => {
</Button>
</footer>
</article>
</div>
</motion.div>
);
})}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ exports[`renders correctly 1`] = `
>
<div
className="p-4 w-120 h-120 flex-1"
style={
Object {
"opacity": 0,
"transform": "translateX(-50px) translateY(-50px) translateZ(0)",
}
}
>
<article
className=" w-full rounded-lg bg-white shadow-lg "
Expand Down Expand Up @@ -106,6 +112,12 @@ exports[`renders correctly 1`] = `
</div>
<div
className="p-4 w-120 h-120 flex-1"
style={
Object {
"opacity": 0,
"transform": "translateX(50px) translateY(-50px) translateZ(0)",
}
}
>
<article
className=" w-full rounded-lg bg-white shadow-lg "
Expand Down Expand Up @@ -195,6 +207,12 @@ exports[`renders correctly 1`] = `
</div>
<div
className="p-4 w-120 h-120 flex-1"
style={
Object {
"opacity": 0,
"transform": "translateX(-50px) translateY(-50px) translateZ(0)",
}
}
>
<article
className=" w-full rounded-lg bg-white shadow-lg "
Expand Down
27 changes: 24 additions & 3 deletions src/components/LatestProducts/LatestProducts.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { collection, onSnapshot, orderBy, query } from "firebase/firestore";
import { motion, useAnimation } from "framer-motion";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useInView } from "react-intersection-observer";

import { db } from "@/util/firebase";

Expand All @@ -9,6 +11,8 @@ import ProductCard from "../ProductCard/ProductCard";

export default function LatestProducts({ t }) {
const [products, setProducts] = useState([]);
const controls = useAnimation();
const [ref, inView] = useInView({ triggerOnce: true });
useEffect(() => {
const colRef = collection(db, "products");
const q = query(colRef, orderBy("createdAt", "desc"));
Expand All @@ -21,14 +25,31 @@ export default function LatestProducts({ t }) {
setProducts(latestProducts);
});
}, []);
useEffect(() => {
if (inView) {
controls.start({ opacity: 1, x: 0, y: 0 });
}
}, [controls, inView]);
return (
<div className='flex flex-col justify-center items-center shadow-lg border-t-2 bg-gray-200 pt-10 pb-5'>
<div
ref={ref}
className='flex flex-col justify-center items-center shadow-lg border-t-2 bg-gray-200 pt-10 pb-5'
>
<h1 className='mb-10 text-3xl font-bold text-[#585785]'>
{t("Recently Added")}
</h1>
<div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 mx-auto gap-4 lg:gap-8 place-items-center'>
{products?.map((product) => {
return <ProductCard key={product.id} product={product} />;
{products?.map((product, i) => {
return (
<motion.div
key={product.id}
initial={{ opacity: 0, x: -50, y: -50 }}
animate={controls}
transition={{ duration: 0.4, delay: i * 0.3 }}
>
<ProductCard product={product} />
</motion.div>
);
})}
</div>
<Link href='/products'>
Expand Down
14 changes: 12 additions & 2 deletions src/components/ProductsList/ProductsList.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { motion } from "framer-motion";
import { useEffect, useState } from "react";

import ProductCard from "../ProductCard/ProductCard";

export default function ProductsList({ products, t }) {
Expand All @@ -13,13 +15,21 @@ export default function ProductsList({ products, t }) {
clearTimeout(timeoutId);
};
}, []);

return (
<div className='w-full sm:w-[80%] sm:mx-auto md:w-[70%] lg:w-[80%] xl:max-w-[1000px] py-5'>
{products && products.length > 0 ? (
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 place-items-center gap-x-3 gap-y-4 md:gap-x-0'>
{products?.map((product) => {
{products?.map((product, i) => {
return (
<ProductCard key={product.id} product={product} />
<motion.div
key={product.id}
initial={{ opacity: 0, x: -50, y: -50 }}
animate={{ opacity: 1, x: 0, y: 0 }}
transition={{ duration: 0.4, delay: i * 0.3 }}
>
<ProductCard product={product} />
</motion.div>
);
})}
</div>
Expand Down
Loading