| 1 |
import { customComponents } from '@agent/lib/markdown'; |
| 2 |
import { AnimatePresence, motion } from 'framer-motion'; |
| 3 |
import ReactMarkdown from 'react-markdown'; |
| 4 |
|
| 5 |
export const AnimateChunks = ({ words, delay = 0.4, duration = 0.25 }) => { |
| 6 |
const isChars = words.every((word) => word.length === 1); |
| 7 |
|
| 8 |
return ( |
| 9 |
<AnimatePresence> |
| 10 |
{words.map((word, i) => ( |
| 11 |
<motion.span |
| 12 |
key={i} |
| 13 |
initial={{ opacity: 0, y: 8 }} |
| 14 |
animate={{ opacity: 1, y: 0 }} |
| 15 |
exit={{ opacity: 0 }} |
| 16 |
transition={{ duration, delay: i * delay }} |
| 17 |
> |
| 18 |
{isChars ? ( |
| 19 |
word |
| 20 |
) : ( |
| 21 |
<ReactMarkdown components={customComponents}>{word}</ReactMarkdown> |
| 22 |
)} |
| 23 |
</motion.span> |
| 24 |
))} |
| 25 |
</AnimatePresence> |
| 26 |
); |
| 27 |
}; |
| 28 |
|