Skip to content

Commit 0de3a1b

Browse files
committed
Update useAnimations.stories.tsx
1 parent 5aa2bb6 commit 0de3a1b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

stories/hooks/useAnimations.stories.tsx

+60
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,66 @@ export const Countdown: StoryObj = {
161161
},
162162
};
163163

164+
const Block = ({ i, length: n }: { i: number; length: number }) => {
165+
const timing: AnimationOptions = {
166+
duration: 250,
167+
};
168+
const animate = useAnimations({
169+
one: [
170+
[{ backgroundColor: "#eee" }, { backgroundColor: "steelblue" }],
171+
{ ...timing, endDelay: 1000 },
172+
],
173+
two: [
174+
[{ backgroundColor: "steelblue" }, { backgroundColor: "orange" }],
175+
{ ...timing, endDelay: 1000 },
176+
],
177+
three: [
178+
[{ backgroundColor: "orange" }, { backgroundColor: "#eee" }],
179+
{ ...timing, endDelay: n },
180+
],
181+
});
182+
183+
useEffect(() => {
184+
const run = async () => {
185+
animate.cancelAll();
186+
await animate.play("one").end("one");
187+
animate.cancel("one");
188+
await animate.play("two").end("two");
189+
animate.cancel("two");
190+
await animate.play("three").end("three");
191+
run();
192+
};
193+
setTimeout(run, i + (Math.random() * n) / 4);
194+
}, []);
195+
196+
return (
197+
<div
198+
ref={animate.ref}
199+
style={{
200+
width: 10,
201+
height: 10,
202+
margin: " 1px 0 0 1px",
203+
float: "left",
204+
background: "#eee",
205+
display: "inline-block",
206+
}}
207+
/>
208+
);
209+
};
210+
211+
export const Chained: StoryObj = {
212+
render: () => {
213+
const length = 4002;
214+
return (
215+
<div style={{ maxWidth: 960 }}>
216+
{Array.from({ length: length }).map((_, i) => (
217+
<Block key={i} i={i} length={length} />
218+
))}
219+
</div>
220+
);
221+
},
222+
};
223+
164224
export const Sequence: StoryObj = {
165225
render: () => {
166226
const timing: AnimationOptions = { duration: 600, easing: "ease-out" };

0 commit comments

Comments
 (0)