-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathhearts.tsx
44 lines (38 loc) · 904 Bytes
/
hearts.tsx
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
import { useSpring, animated } from "react-spring";
import React from "react";
import styles from "../styles/hearts.module.scss";
interface HeartProps {
have: boolean;
}
function Heart(props: HeartProps) {
const { have } = props;
const { opacity } = useSpring({
opacity: have ? 1 : 0.4,
config: { duration: 300 },
});
const { scale } = useSpring({
scale: have ? 1 : 0.8,
config: { mass: 1, tension: 200, friction: 20, duration: 300 },
delay: 200,
});
return (
<animated.img
className={styles.heart}
style={{ opacity, scale }}
src="/images/heart.svg"
/>
);
}
interface Props {
lives: number;
}
export default function Hearts(props: Props) {
const { lives } = props;
return (
<div className={styles.hearts}>
<Heart have={lives >= 1} />
<Heart have={lives >= 2} />
<Heart have={lives >= 3} />
</div>
);
}