| 1 | import { Text } from "ink"; |
| 2 | import React, { useEffect, useState } from "react"; |
| 3 | |
| 4 | interface LoadingTextProps { |
| 5 | text: string; |
| 6 | color?: string; |
| 7 | interval?: number; |
| 8 | } |
| 9 | |
| 10 | export const LoadingText: React.FC<LoadingTextProps> = ({ |
| 11 | text, |
| 12 | color = "dim", |
| 13 | interval = 300, |
| 14 | }) => { |
| 15 | const [dotsCount, setDotsCount] = useState(1); |
| 16 | |
| 17 | useEffect(() => { |
| 18 | const timer = setInterval(() => { |
| 19 | setDotsCount((current) => (current % 3) + 1); |
| 20 | }, interval); |
| 21 | |
| 22 | return () => clearInterval(timer); |
| 23 | }, [interval]); |
| 24 | |
| 25 | const dots = ".".repeat(dotsCount); |
| 26 | |
| 27 | return ( |
| 28 | <Text color={color}> |
| 29 | {text} |
| 30 | {dots} |
| 31 | </Text> |
| 32 | ); |
| 33 | }; |