From 78691267b6cda7470a7be460347da0431a2be2dc Mon Sep 17 00:00:00 2001 From: bqxbqx <132878537+BQXBQX@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:57:57 +0800 Subject: [PATCH] feat(bubble): add typing suffix support (#316) * feat(bubble): add typing suffix support * docs(Bubble): improve typing demo documentation --- components/bubble/Bubble.tsx | 11 ++++-- .../__snapshots__/demo-extend.test.ts.snap | 36 ++++++++++++++++++ .../__tests__/__snapshots__/demo.test.ts.snap | 38 +++++++++++++++++++ components/bubble/demo/typing.tsx | 7 +++- components/bubble/hooks/useTypingConfig.ts | 10 +++-- components/bubble/interface.ts | 4 ++ 6 files changed, 99 insertions(+), 7 deletions(-) diff --git a/components/bubble/Bubble.tsx b/components/bubble/Bubble.tsx index 1ef00ed6..f0f4eacc 100644 --- a/components/bubble/Bubble.tsx +++ b/components/bubble/Bubble.tsx @@ -61,7 +61,7 @@ const Bubble: React.ForwardRefRenderFunction = (props, r const contextConfig = useXComponentConfig('bubble'); // ============================ Typing ============================ - const [typingEnabled, typingStep, typingInterval] = useTypingConfig(typing); + const [typingEnabled, typingStep, typingInterval, typingSuffix] = useTypingConfig(typing); const [typedContent, isTyping] = useTypedEffect( content, @@ -101,7 +101,7 @@ const Bubble: React.ForwardRefRenderFunction = (props, r `${prefixCls}-${placement}`, { [`${prefixCls}-rtl`]: direction === 'rtl', - [`${prefixCls}-typing`]: isTyping && !loading && !messageRender, + [`${prefixCls}-typing`]: isTyping && !loading && !messageRender && !typingSuffix, }, ); @@ -116,7 +116,12 @@ const Bubble: React.ForwardRefRenderFunction = (props, r if (loading) { contentNode = loadingRender ? loadingRender() : ; } else { - contentNode = mergedContent as React.ReactNode; + contentNode = ( + <> + {mergedContent as React.ReactNode} + {isTyping && typingSuffix} + + ); } let fullContent: React.ReactNode = ( diff --git a/components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap index 6df281c9..9b97babf 100644 --- a/components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1918,6 +1918,42 @@ exports[`renders components/bubble/demo/typing.tsx extend context correctly 1`] A +
+
+ + + + + +
+
+ A💗 +
+