MCPcopy Create free account
hub / github.com/braposo/react-text-loop / TextLoop

Class TextLoop

src/components/TextLoop.tsx:36–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34};
35
36class TextLoop extends React.PureComponent<Props, State> {
37 isUnMounting = false;
38
39 tickDelay: RequestTimeout = 0;
40
41 tickLoop: RequestTimeout = 0;
42
43 wordBox: HTMLDivElement | null = null;
44
45 static defaultProps: Props = {
46 interval: 3000,
47 delay: 0,
48 adjustingSpeed: 150,
49 springConfig: { stiffness: 340, damping: 30 },
50 fade: true,
51 mask: false,
52 noWrap: true,
53 };
54
55 constructor(props: Props) {
56 super(props);
57 const elements = React.Children.toArray(props.children);
58
59 this.state = {
60 elements,
61 currentEl: elements[0],
62 currentWordIndex: 0,
63 wordCount: 0,
64 currentInterval: Array.isArray(props.interval)
65 ? props.interval[0]
66 : props.interval,
67 };
68 }
69
70 componentDidMount(): void {
71 // Starts animation
72 const { delay } = this.props;
73 const { currentInterval, elements } = this.state;
74
75 if (currentInterval > 0 && elements.length > 1) {
76 this.tickDelay = requestTimeout(() => {
77 this.tickLoop = requestTimeout(this.tick, currentInterval);
78 }, delay);
79 }
80 }
81
82 componentDidUpdate(prevProps: Props, prevState: State): void {
83 const { interval, children, delay } = this.props as Props;
84 const { currentWordIndex } = this.state;
85
86 const currentInterval = Array.isArray(interval)
87 ? interval[currentWordIndex % interval.length]
88 : interval;
89
90 if (prevState.currentInterval !== currentInterval) {
91 this.clearTimeouts();
92
93 if (currentInterval > 0 && React.Children.count(children) > 1) {

Callers

nothing calls this directly

Calls 4

getDimensionsMethod · 0.95
getOpacityMethod · 0.95
clearTimeoutsMethod · 0.95
requestTimeoutFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…