-
Notifications
You must be signed in to change notification settings - Fork 983
/
Copy pathanimate-text.tsx
55 lines (50 loc) · 1.24 KB
/
animate-text.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
import { forwardRef, type ElementRef } from "react";
const easings = {
linear: true,
easeIn: true,
easeInCubic: true,
easeInQuart: true,
easeOut: true,
easeOutCubic: true,
easeOutQuart: true,
ease: true,
easeInOutCubic: true,
easeInOutQuart: true,
};
const split = {
char: true,
space: true,
'symbol "#"': true,
'symbol "~"': true,
};
type AnimateChildrenProps = {
/**
* Size of the sliding window for the animation:
* - 0: Typewriter effect (no animation).
* - (0..1]: Animates one part of the text at a time.
* - (1..n]: Animates multiple parts of the text within the sliding window.
*/
slidingWindow?: number;
/**
* Easing function applied within the sliding window.
*/
easing?: keyof typeof easings;
/**
* Text content to animate.
*/
children: React.ReactNode;
/**
* Defines how the text is split for animation (e.g., by character, space, or symbol).
*/
splitBy?: keyof typeof split;
};
export const AnimateText = forwardRef<ElementRef<"div">, AnimateChildrenProps>(
(
{ slidingWindow = 5, easing = "linear", splitBy = "char", ...props },
ref
) => {
return <div ref={ref} {...props} />;
}
);
const displayName = "AnimateText";
AnimateText.displayName = displayName;