Skip to content

Commit c3f5a7b

Browse files
committed
tilt animation
1 parent cfc45ab commit c3f5a7b

4 files changed

Lines changed: 64 additions & 9 deletions

File tree

app/collections/page.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import CollectionCard from "@/components/CollectionCard";
22
import fetchData from "@/lib/sanity/fetchData";
33
import dayjs from "dayjs";
44
import _ from "lodash";
5+
import TiltWrapper from "@/components/TiltWrapper";
56

67
export default async function Collections() {
78
const collections = await fetchData("collection");
89

910
const collectionGroups = _.groupBy(collections, (collection) =>
10-
dayjs(collection.date).year()
11+
dayjs(collection.date).year(),
1112
);
1213

1314
const sortedCollectionGroups = Object.entries(collectionGroups).sort(
14-
([yearA], [yearB]) => yearB - yearA
15+
([yearA], [yearB]) => yearB - yearA,
1516
);
1617

1718
return (
@@ -28,7 +29,9 @@ export default async function Collections() {
2829
<div className="m-7 text-center text-3xl">{year}</div>
2930
<div className="flex flex-wrap items-center justify-around gap-20">
3031
{sortedCollections.map((collection) => (
31-
<CollectionCard key={collection._id} collection={collection} />
32+
<TiltWrapper key={collection._id}>
33+
<CollectionCard collection={collection} />
34+
</TiltWrapper>
3235
))}
3336
</div>
3437
</div>

components/TiltWrapper.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use client";
2+
import { Tilt } from 'react-tilt';
3+
4+
const defaultOptions = {
5+
reverse: false,
6+
max: 15,
7+
perspective: 1000,
8+
scale: 1.05,
9+
speed: 1000,
10+
transition: true,
11+
axis: null,
12+
reset: true,
13+
easing: "cubic-bezier(.03,.98,.52,.99)",
14+
}
15+
16+
export default function TiltWrapper({ children, className }) {
17+
return (
18+
<Tilt options={defaultOptions} className={className}>
19+
{children}
20+
</Tilt>
21+
);
22+
}

package-lock.json

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"react-dom": "18.3.1",
2626
"react-icons": "^4.12.0",
2727
"react-pdf": "^6.2.2",
28+
"react-tilt": "^1.0.2",
2829
"sharp": "^0.32.6",
2930
"swiper": "^10.3.1",
3031
"tailwind-merge": "^1.14.0",

0 commit comments

Comments
 (0)