-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnimatedCard.tsx
More file actions
61 lines (53 loc) · 1.3 KB
/
Copy pathAnimatedCard.tsx
File metadata and controls
61 lines (53 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { type FC, useMemo, useRef } from 'react';
import { type Variants, motion, useInView } from 'motion/react';
import { useMasonryItem } from '../../../src';
import getRandomAuthor from './random-author';
interface CardProps {
url: string;
}
const variants: Variants = {
inital: () => ({
y: 50,
opacity: 0,
}),
animate: (column: number) => ({
y: 0,
opacity: 1,
transition: {
duration: 1,
delay: column * 0.2,
},
}),
exit: (column: number) => ({
y: -50,
opacity: 0,
transition: {
duration: 1,
delay: column * 0.2,
},
}),
};
const Card: FC<CardProps> = ({ url }) => {
const { column } = useMasonryItem();
const ref = useRef(null);
const inView = useInView(ref);
const author = useMemo(getRandomAuthor, []);
return (
<motion.div
variants={variants}
custom={column}
initial="inital"
animate={inView ? 'animate' : false}
exit="exit"
className="flex flex-col gap-4"
ref={ref}
>
<img className="rounded-md shadow-md max-w-full h-full" src={url} alt="" />
<div className="flex flex-col !m-0">
<span className="text-lg">{author.name}</span>
<span className="text-sm text-slate-500">{author.company}</span>
</div>
</motion.div>
);
};
export default Card;