Skip to content

Commit e8c1874

Browse files
committed
docs(ai-chat-log): added scollable example
1 parent a0f40c3 commit e8c1874

File tree

5 files changed

+470
-9
lines changed

5 files changed

+470
-9
lines changed

packages/paste-core/components/ai-chat-log/src/utils.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React, { useEffect, useState } from "react";
22

33
// Hook to animate text content of React elements
4-
export const useAnimatedText = (children: React.ReactNode, speed = 10): React.ReactNode => {
4+
export const useAnimatedText = (
5+
children: React.ReactNode,
6+
speed = 10,
7+
enabled = true,
8+
): { animatedChildren: React.ReactNode; isAnimating: boolean } => {
59
const [animatedChildren, setAnimatedChildren] = useState<React.ReactNode>();
610
const [textIndex, setTextIndex] = useState(0);
711

@@ -58,13 +62,18 @@ export const useAnimatedText = (children: React.ReactNode, speed = 10): React.Re
5862

5963
// Effect to update animated children based on the current text index
6064
useEffect(() => {
61-
const totaLength = calculateTotalTextLength(children);
62-
if (textIndex <= totaLength) {
63-
setAnimatedChildren(cloneChildren(children, textIndex));
65+
if (enabled) {
66+
const totaLength = calculateTotalTextLength(children);
67+
if (textIndex <= totaLength) {
68+
setAnimatedChildren(cloneChildren(children, textIndex));
69+
}
6470
}
65-
}, [children, textIndex]);
71+
}, [children, textIndex, enabled]);
6672

67-
return animatedChildren;
73+
return {
74+
animatedChildren: enabled ? animatedChildren : children,
75+
isAnimating: enabled && textIndex < calculateTotalTextLength(children),
76+
};
6877
};
6978

7079
export default useAnimatedText;

packages/paste-core/components/ai-chat-log/stories/composer.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const BotMessage = (props): JSX.Element => {
5959
) : (
6060
<AIChatMessage variant="bot">
6161
<AIChatMessageAuthor aria-label="Bot said">Good Bot</AIChatMessageAuthor>
62-
<AIChatMessageBody>{props.message as string}</AIChatMessageBody>
62+
<AIChatMessageBody animated>{props.message as string}</AIChatMessageBody>
6363
</AIChatMessage>
6464
);
6565
};

0 commit comments

Comments
 (0)