Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bubble): add typing suffix support (#316) #378

Closed
wants to merge 1 commit into from
Closed

Conversation

YumoImer
Copy link
Collaborator

@YumoImer YumoImer commented Dec 20, 2024

  • feat(bubble): add typing suffix support

  • docs(Bubble): improve typing demo documentation

Summary by CodeRabbit

  • 新特性

    • Bubble 组件中新增了 typingSuffix 功能,增强了输入时的视觉反馈。
    • 在演示组件中添加了新的 Bubble 实例,支持显示心形表情作为输入后缀。
  • 文档

    • 更新了 TypingOption 接口,新增可选属性 suffix

* feat(bubble): add typing suffix support

* docs(Bubble): improve typing demo documentation
Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

📝 Walkthrough

概述

演练

此拉取请求(PR)主要修改了 Bubble 组件及其相关钩子和接口,引入了一个新的 typingSuffix 属性。这个属性允许在打字效果期间自定义后缀内容。修改涉及 Bubble.tsxuseTypingConfig.tsinterface.tsdemo/typing.tsx 文件,扩展了组件的打字行为配置。

变更

文件 变更摘要
components/bubble/interface.ts TypingOption 接口中新增 suffix 可选属性
components/bubble/hooks/useTypingConfig.ts 更新返回值,包含 suffix 参数
components/bubble/Bubble.tsx 调整渲染逻辑,支持 typingSuffix 显示
components/bubble/demo/typing.tsx Bubble 组件中添加心形表情后缀示例

可能相关的问题

可能相关的 PR

建议的审阅者

  • afc163

诗歌

兔子敲代码,打字有新意
后缀飞舞动,创意正绽放
打字变魔法,emoji 闪光芒
代码如诗行,创新永不慌
🐰✨ 兔子笑开怀!

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Dec 20, 2024

Preview is ready

Copy link

Walkthrough

This pull request introduces a new feature to the Bubble component by adding support for a typing suffix. It enhances the typing effect by allowing a suffix to be displayed during typing. Additionally, the documentation for the typing demo has been improved.

Changes

Files Changed Summary
Bubble.tsx Added typing suffix support to the Bubble component. Adjusted the logic to include the suffix in the typing effect.
demo/typing.tsx Updated the typing demo to showcase the new suffix feature.
useTypingConfig.ts Modified the typing configuration hook to handle the new suffix option.
interface.ts Updated the TypingOption interface to include the suffix property.
demo-extend.test.ts.snap, demo.test.ts.snap Updated snapshots to reflect the changes in the typing effect and suffix addition.

@@ -101,7 +101,7 @@ const Bubble: React.ForwardRefRenderFunction<BubbleRef, BubbleProps> = (props, r
`${prefixCls}-${placement}`,
{
[`${prefixCls}-rtl`]: direction === 'rtl',
[`${prefixCls}-typing`]: isTyping && !loading && !messageRender,
[`${prefixCls}-typing`]: isTyping && !loading && !messageRender && !typingSuffix,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that typingSuffix is correctly handled when isTyping is false to avoid unnecessary rendering of the suffix.

Copy link

codecov bot commented Dec 20, 2024

Bundle Report

Bundle size has no change ✅

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
components/bubble/hooks/useTypingConfig.ts (2)

5-7: 建议使用更严格的类型定义

建议将返回类型定义为一个独立的类型,以提高代码的可维护性和类型安全性。

+type TypingConfigTuple = [
+  enableTyping: boolean,
+  step: number,
+  interval: number,
+  suffix: React.ReactNode
+];

function useTypingConfig(typing: BubbleProps['typing']) {
  return React.useMemo<
-    [enableTyping: boolean, step: number, interval: number, suffix: React.ReactNode]
+    TypingConfigTuple
  >(() => {

15-16: 注释格式建议

建议使用更规范的 JSDoc 格式来记录默认值。

-      // set default suffix is empty
+      /** @default null */
       suffix: null,
components/bubble/demo/typing.tsx (1)

18-22: 建议添加演示说明

为了更好地展示新增的 suffix 功能,建议在示例代码中添加注释说明该功能的使用场景和效果。

+      {/* 使用 suffix 属性来展示打字时的额外装饰元素 */}
       <Bubble
         content={text.repeat(repeat)}
         typing={{ step: 2, interval: 50, suffix: <>💗</> }}
         avatar={{ icon: <UserOutlined /> }}
       />
components/bubble/interface.ts (1)

12-15: 建议完善类型文档

建议在 JSDoc 中添加更详细的说明,包括属性的用途和示例。

   /**
+   * 打字效果的后缀装饰元素
+   * @example
+   * suffix: <>💗</>
    * @default null
    */
   suffix?: React.ReactNode;
components/bubble/Bubble.tsx (1)

119-124: 验证打字后缀的渲染逻辑

内容渲染逻辑的改动看起来合理,但建议:

  1. 考虑将后缀渲染逻辑抽取为一个独立的组件,以提高代码的可维护性
  2. 为后缀添加特定的类名,便于样式定制

建议如下重构:

-    contentNode = (
-      <>
-        {mergedContent as React.ReactNode}
-        {isTyping && typingSuffix}
-      </>
-    );
+    const TypingSuffix = () => (
+      <span className={`${prefixCls}-typing-suffix`}>
+        {typingSuffix}
+      </span>
+    );
+
+    contentNode = (
+      <>
+        {mergedContent as React.ReactNode}
+        {isTyping && typingSuffix && <TypingSuffix />}
+      </>
+    );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49b6c89 and f4c7cc2.

⛔ Files ignored due to path filters (2)
  • components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/bubble/__tests__/__snapshots__/demo.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • components/bubble/Bubble.tsx (3 hunks)
  • components/bubble/demo/typing.tsx (2 hunks)
  • components/bubble/hooks/useTypingConfig.ts (1 hunks)
  • components/bubble/interface.ts (1 hunks)
🔇 Additional comments (3)
components/bubble/hooks/useTypingConfig.ts (1)

23-23: 代码逻辑正确

返回值包含了所有必要的配置项,且保持了与接口定义的一致性。

components/bubble/Bubble.tsx (2)

104-104: 优化类名条件判断逻辑

类名条件判断中增加了 !typingSuffix 检查,这样可以避免在使用自定义后缀时出现默认的打字动画样式。这个改动很合理。


64-64: 确认 useTypingConfig 钩子的返回值更新

从钩子函数中解构新增的 typingSuffix 值,这个改动与 PR 的目标相符。建议确保 useTypingConfig 的类型定义也已相应更新。

✅ Verification successful

useTypingConfig 钩子的类型定义已正确更新

useTypingConfig 钩子函数的返回类型已经正确定义为包含四个元素的元组:[enableTyping: boolean, step: number, interval: number, suffix: React.ReactNode],完全符合当前的使用场景。类型定义和实现都已经包含了对 typingSuffix 的支持。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 useTypingConfig 钩子的类型定义
ast-grep --pattern 'export function useTypingConfig($_: $_): [$_]'

Length of output: 68


Script:

#!/bin/bash
# 搜索 useTypingConfig 的定义和使用
rg "useTypingConfig" -A 5

# 搜索包含 typing 的类型定义文件
fd "typing.*\.ts" --type f

Length of output: 1472


Script:

#!/bin/bash
# 检查 useTypingConfig 钩子的完整实现
cat components/bubble/hooks/useTypingConfig.ts

Length of output: 751

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.74%. Comparing base (0cafa79) to head (f4c7cc2).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #378      +/-   ##
==========================================
+ Coverage   91.36%   91.74%   +0.38%     
==========================================
  Files          66       66              
  Lines        1447     1550     +103     
  Branches      368      419      +51     
==========================================
+ Hits         1322     1422     +100     
- Misses        125      128       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

size-limit report 📦

Path Size
dist/antdx.min.js 40.67 KB (-4 B 🔽)

@YumoImer YumoImer requested a review from a team December 20, 2024 04:27
@YumoImer YumoImer closed this Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants