|
@@ -0,0 +1,257 @@
|
|
1
|
+import { motion, Variants } from "framer-motion";
|
|
2
|
+import { StepProps } from "./stepProps.ts";
|
|
3
|
+import Masked from "../components/mask/Masked.tsx";
|
|
4
|
+import React, { useState, useEffect, useRef } from "react";
|
|
5
|
+
|
|
6
|
+type VariantProps = {
|
|
7
|
+ delay: number;
|
|
8
|
+};
|
|
9
|
+
|
|
10
|
+const leftSideVariants: Variants = {
|
|
11
|
+ "1": (props: VariantProps) => ({
|
|
12
|
+ width: 1,
|
|
13
|
+ transition: {
|
|
14
|
+ duration: 1.5,
|
|
15
|
+ repeat: 0,
|
|
16
|
+ type: "spring",
|
|
17
|
+ ease: "easeInOut",
|
|
18
|
+ delay: 0.5 + props.delay,
|
|
19
|
+ },
|
|
20
|
+ }),
|
|
21
|
+ "2": (props: VariantProps) => ({
|
|
22
|
+ width: 10,
|
|
23
|
+ transition: {
|
|
24
|
+ duration: 1,
|
|
25
|
+ repeat: 0,
|
|
26
|
+ delay: 0,
|
|
27
|
+ },
|
|
28
|
+ }),
|
|
29
|
+ "3": (props: VariantProps) => ({
|
|
30
|
+ width: 100 + props.delay * 400,
|
|
31
|
+ transition: {
|
|
32
|
+ duration: 2,
|
|
33
|
+ repeat: 0,
|
|
34
|
+ ease: "easeInOut",
|
|
35
|
+ delay: 0,
|
|
36
|
+ },
|
|
37
|
+ }),
|
|
38
|
+};
|
|
39
|
+
|
|
40
|
+const textAreaVariants: Variants = {
|
|
41
|
+ "1": {
|
|
42
|
+ opacity: 1,
|
|
43
|
+ width: "80%",
|
|
44
|
+ height: "80%",
|
|
45
|
+ transition: {
|
|
46
|
+ duration: 0.5,
|
|
47
|
+ },
|
|
48
|
+ },
|
|
49
|
+ "2": {
|
|
50
|
+ opacity: 1,
|
|
51
|
+ width: "80%",
|
|
52
|
+ height: "80%",
|
|
53
|
+ transition: {
|
|
54
|
+ duration: 1.5,
|
|
55
|
+ },
|
|
56
|
+ },
|
|
57
|
+ "3": {
|
|
58
|
+ opacity: 1,
|
|
59
|
+ width: "80%",
|
|
60
|
+ height: "80%",
|
|
61
|
+ transition: {
|
|
62
|
+ duration: 1,
|
|
63
|
+ },
|
|
64
|
+ },
|
|
65
|
+};
|
|
66
|
+
|
|
67
|
+type RunningAnimations = {
|
|
68
|
+ [key: string]: number;
|
|
69
|
+};
|
|
70
|
+
|
|
71
|
+function usePrevious(value: any) {
|
|
72
|
+ const ref = useRef();
|
|
73
|
+ useEffect(() => {
|
|
74
|
+ ref.current = value;
|
|
75
|
+ }, [value]);
|
|
76
|
+ return ref.current;
|
|
77
|
+}
|
|
78
|
+
|
|
79
|
+function GlobalTop({ progress }: StepProps) {
|
|
80
|
+ const [starVariant, setStarVariant] = useState("1");
|
|
81
|
+ const [runningAnimations, setRunningAnimations] = useState<RunningAnimations>(
|
|
82
|
+ {}
|
|
83
|
+ );
|
|
84
|
+ const previousRunningAnimations = usePrevious(runningAnimations);
|
|
85
|
+
|
|
86
|
+ // implement the logic of "animationComplete" in a useEffect
|
|
87
|
+ // Consider an animation just completed when the associated number of running animations just reached 0
|
|
88
|
+
|
|
89
|
+ useEffect(() => {
|
|
90
|
+ for (const variant in runningAnimations) {
|
|
91
|
+ if (
|
|
92
|
+ runningAnimations[variant] === 0 &&
|
|
93
|
+ previousRunningAnimations[variant] !== 0
|
|
94
|
+ ) {
|
|
95
|
+ if (variant === "1") {
|
|
96
|
+ setStarVariant("2");
|
|
97
|
+ } else if (variant === "2") {
|
|
98
|
+ setStarVariant("3");
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+ }
|
|
102
|
+ }, [runningAnimations]);
|
|
103
|
+
|
|
104
|
+ const animationComplete = (variant: string) => {
|
|
105
|
+ console.log("animationComplete", variant);
|
|
106
|
+ decrementAnimation(variant);
|
|
107
|
+ };
|
|
108
|
+
|
|
109
|
+ const animationStarted = (variant: string) => {
|
|
110
|
+ console.log("animationStarted", variant);
|
|
111
|
+ incrementAnimation(variant);
|
|
112
|
+ };
|
|
113
|
+
|
|
114
|
+ const incrementAnimation = (animation: string) => {
|
|
115
|
+ setRunningAnimations((prev: RunningAnimations) => {
|
|
116
|
+ const newRunningAnimations = { ...prev };
|
|
117
|
+ if (!newRunningAnimations[animation]) {
|
|
118
|
+ newRunningAnimations[animation] = 1;
|
|
119
|
+ } else {
|
|
120
|
+ newRunningAnimations[animation]++;
|
|
121
|
+ }
|
|
122
|
+ return newRunningAnimations;
|
|
123
|
+ });
|
|
124
|
+ };
|
|
125
|
+
|
|
126
|
+ const decrementAnimation = (animation: string) => {
|
|
127
|
+ setRunningAnimations((prev: RunningAnimations) => {
|
|
128
|
+ const newRunningAnimations = { ...prev };
|
|
129
|
+ if (newRunningAnimations[animation] > 0) {
|
|
130
|
+ newRunningAnimations[animation]--;
|
|
131
|
+ }
|
|
132
|
+ return newRunningAnimations;
|
|
133
|
+ });
|
|
134
|
+ };
|
|
135
|
+
|
|
136
|
+ return (
|
|
137
|
+ <div style={pageStyle as React.CSSProperties}>
|
|
138
|
+ <div
|
|
139
|
+ style={{
|
|
140
|
+ display: "flex",
|
|
141
|
+ position: "absolute",
|
|
142
|
+ top: 0,
|
|
143
|
+ bottom: 0,
|
|
144
|
+ left: 0,
|
|
145
|
+ right: 0,
|
|
146
|
+ flexDirection: "column",
|
|
147
|
+ alignItems: "start",
|
|
148
|
+ justifyContent: "start",
|
|
149
|
+ }}
|
|
150
|
+ >
|
|
151
|
+ {Array.from({ length: 7 }).map((_, i) => (
|
|
152
|
+ <motion.div
|
|
153
|
+ key={i}
|
|
154
|
+ variants={leftSideVariants}
|
|
155
|
+ style={baseStyle as React.CSSProperties}
|
|
156
|
+ animate={starVariant}
|
|
157
|
+ custom={{ delay: i * 0.05 }}
|
|
158
|
+ onAnimationStart={() => animationStarted(starVariant)}
|
|
159
|
+ onAnimationComplete={() => animationComplete(starVariant)}
|
|
160
|
+ >
|
|
161
|
+ <div style={starStyle as React.CSSProperties}></div>
|
|
162
|
+ </motion.div>
|
|
163
|
+ ))}
|
|
164
|
+ </div>
|
|
165
|
+ <div
|
|
166
|
+ style={{
|
|
167
|
+ display: "flex",
|
|
168
|
+ position: "absolute",
|
|
169
|
+ top: 0,
|
|
170
|
+ bottom: 0,
|
|
171
|
+ left: 0,
|
|
172
|
+ right: 0,
|
|
173
|
+ flexDirection: "column",
|
|
174
|
+ alignItems: "end",
|
|
175
|
+ justifyContent: "end",
|
|
176
|
+ }}
|
|
177
|
+ >
|
|
178
|
+ {Array.from({ length: 7 }).map((_, i) => (
|
|
179
|
+ <motion.div
|
|
180
|
+ key={i}
|
|
181
|
+ variants={leftSideVariants}
|
|
182
|
+ style={baseStyle as React.CSSProperties}
|
|
183
|
+ animate={starVariant}
|
|
184
|
+ custom={{ delay: i * 0.05 }}
|
|
185
|
+ onAnimationStart={() => animationStarted(starVariant)}
|
|
186
|
+ onAnimationComplete={() => animationComplete(starVariant)}
|
|
187
|
+ >
|
|
188
|
+ <div style={starStyle as React.CSSProperties}></div>
|
|
189
|
+ </motion.div>
|
|
190
|
+ ))}
|
|
191
|
+ </div>
|
|
192
|
+
|
|
193
|
+ <div style={bgSquareStyle as React.CSSProperties}></div>
|
|
194
|
+
|
|
195
|
+ <motion.div
|
|
196
|
+ variants={textAreaVariants}
|
|
197
|
+ animate={starVariant}
|
|
198
|
+ style={textAreaStyle as React.CSSProperties}
|
|
199
|
+ >
|
|
200
|
+ Coucou ! {starVariant}
|
|
201
|
+ </motion.div>
|
|
202
|
+ </div>
|
|
203
|
+ );
|
|
204
|
+}
|
|
205
|
+
|
|
206
|
+const pageStyle = {
|
|
207
|
+ position: "relative",
|
|
208
|
+ width: "100%",
|
|
209
|
+ height: "100%",
|
|
210
|
+ display: "flex",
|
|
211
|
+ justifyContent: "center",
|
|
212
|
+ alignItems: "center",
|
|
213
|
+ overflow: "hidden",
|
|
214
|
+};
|
|
215
|
+
|
|
216
|
+const baseStyle = {
|
|
217
|
+ zIndex: 1,
|
|
218
|
+ width: "50%",
|
|
219
|
+ flex: 1,
|
|
220
|
+};
|
|
221
|
+
|
|
222
|
+const starStyle = {
|
|
223
|
+ position: "relative",
|
|
224
|
+ width: "100%",
|
|
225
|
+ height: "100%",
|
|
226
|
+ backgroundBlendMode: "multiply",
|
|
227
|
+ background:
|
|
228
|
+ "linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(195,203,56,1) 86%)",
|
|
229
|
+};
|
|
230
|
+
|
|
231
|
+const textAreaStyle = {
|
|
232
|
+ background:
|
|
233
|
+ "linear-gradient(194deg, rgba(255,255,255,0.3650366748166259) 0%, rgba(195,203,56,0.2885085574572127) 86%)",
|
|
234
|
+ backdropFilter: "blur(10px)",
|
|
235
|
+ color: "#000000FF",
|
|
236
|
+ opacity: 0,
|
|
237
|
+ padding: "2",
|
|
238
|
+ width: "200px",
|
|
239
|
+ height: "100px",
|
|
240
|
+ zIndex: 0,
|
|
241
|
+ borderRadius: "10px",
|
|
242
|
+};
|
|
243
|
+
|
|
244
|
+const bgSquareStyle = {
|
|
245
|
+ width: "80%",
|
|
246
|
+ height: "70%",
|
|
247
|
+ position: "absolute",
|
|
248
|
+ top: 300,
|
|
249
|
+ left: 5,
|
|
250
|
+ backgroundImage:
|
|
251
|
+ "linear-gradient(#07b503 1px, transparent 1px, transparent calc(100% - 1px), rgba(195,203,56,1) calc(100% - 1px)), linear-gradient(90deg, rgba(195,203,56,1) 1px, transparent 1px, transparent calc(100% - 1px), rgba(195,203,56,1) calc(100% - 1px))",
|
|
252
|
+ backgroundSize: "3.3333333333333335% 3.3333333333333335%",
|
|
253
|
+ border: "1px solid rgba(195,203,56,1)",
|
|
254
|
+ zIndex: 0,
|
|
255
|
+};
|
|
256
|
+
|
|
257
|
+export default GlobalTop;
|