-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
105 lines (96 loc) · 3.02 KB
/
App.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { stagger, useAnimate, animate } from "framer-motion";
import "./index.css";
const randomNumberBetween = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1) + min);
};
type AnimationSequence = Parameters<typeof animate>[0];
function App() {
const [scope, animate] = useAnimate();
const onButtonClick = () => {
const sparkles = Array.from({ length: 20 });
const sparklesAnimation: AnimationSequence = sparkles.map((_, index) => [
`.sparkle-${index}`,
{
x: randomNumberBetween(-100, 100),
y: randomNumberBetween(-100, 100),
scale: randomNumberBetween(1.5, 2.5),
opacity: 1,
},
{
duration: 0.4,
at: "<",
},
]);
const sparklesFadeOut: AnimationSequence = sparkles.map((_, index) => [
`.sparkle-${index}`,
{
opacity: 0,
scale: 0,
},
{
duration: 0.3,
at: "<",
},
]);
const sparklesReset: AnimationSequence = sparkles.map((_, index) => [
`.sparkle-${index}`,
{
x: 0,
y: 0,
},
{
duration: 0.000001,
},
]);
animate([
...sparklesReset,
[".letter", { y: -32 }, { duration: 0.2, delay: stagger(0.05) }],
["button", { scale: 0.8 }, { duration: 0.1, at: "<" }],
["button", { scale: 1 }, { duration: 0.1 }],
...sparklesAnimation,
[".letter", { y: 0 }, { duration: 0.000001 }],
...sparklesFadeOut,
]);
};
return (
<div ref={scope}>
<button
onClick={onButtonClick}
className="relative rounded-full border-2 border-blue-600 px-6 py-2 text-2xl text-blue-600 transition-colors hover:bg-blue-100"
>
<span className="sr-only">Motion</span>
<span className="block h-8 overflow-hidden" aria-hidden>
{["M", "o", "t", "i", "o", "n"].map((letter, index) => (
<span
data-letter={letter}
className="letter relative inline-block h-8 leading-8 after:absolute after:left-0 after:top-full after:h-8 after:content-[attr(data-letter)]"
key={`${letter}-${index}`}
>
{letter}
</span>
))}
</span>
<span
aria-hidden
className="pointer-events-none absolute inset-0 -z-10 block"
>
{Array.from({ length: 20 }).map((_, index) => (
<svg
className={`absolute left-1/2 top-1/2 opacity-0 sparkle-${index}`}
key={index}
viewBox="0 0 122 117"
width="10"
height="10"
>
<path
className="fill-blue-600"
d="M64.39,2,80.11,38.76,120,42.33a3.2,3.2,0,0,1,1.83,5.59h0L91.64,74.25l8.92,39a3.2,3.2,0,0,1-4.87,3.4L61.44,96.19,27.09,116.73a3.2,3.2,0,0,1-4.76-3.46h0l8.92-39L1.09,47.92A3.2,3.2,0,0,1,3,42.32l39.74-3.56L58.49,2a3.2,3.2,0,0,1,5.9,0Z"
/>
</svg>
))}
</span>
</button>
</div>
);
}
export default App;