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 #312

Closed
wants to merge 1 commit into from

Conversation

BQXBQX
Copy link
Contributor

@BQXBQX BQXBQX commented Dec 5, 2024

PR introduce

  • New feature (non-breaking change which adds functionality)

test pass

image

new behavior

Bubble Component Enhancements

  • Added new suffix option to typing configuration, allowing dynamic content display during typing animation
  • Suffix is displayed while typing is in progress and hidden when typing completes
  • Set empty string as default suffix value for backward compatibility
  • Updated demo to showcase the typing suffix feature with emoji example

Test Utilities Improvements

When I lint, I encounter a problem
image

I solved it in the following way

  • Added type assertion utilities in tests to pass lint check

Example Usage

<Bubble
  content="Hello World"
  typing={{ 
    step: 2, 
    interval: 50, 
    suffix: <>💗</> 
  }}
/>

I want to move the PR to the feature branch, just like the contribution document says, but I found that the project does not have a feature branch, so I moved it to the main branch.

Summary by CodeRabbit

  • 新功能

    • 在气泡组件中添加了打字指示符后缀,提升了用户体验。
    • 在打字效果中加入了心形表情符号,增强了视觉效果。
  • 文档

    • 更新了相关接口以支持新的打字后缀属性。
  • 测试

    • 改进了测试工具的类型定义和导入组织,提升了代码可读性。

- Add suffix option to typing configuration
- Display suffix while typing is in progress
- Update demo and tests to showcase typing suffix feature
- Set default suffix to empty string
- Add type assertions in test utils to pass lint check
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

📝 Walkthrough

Walkthrough

此次更改涉及对 Bubble 组件及其相关功能的修改。主要更新包括在 useTypingConfig 钩子中添加了一个新的返回值 typingSuffix,并在 Bubble 组件中根据 isTyping 状态渲染该后缀。此外,typing 属性的结构也进行了更新,以支持用户自定义的打字机效果后缀。测试文件中的类型定义和导入语句也得到了改进,以增强代码的可读性和类型安全性。

Changes

文件路径 更改摘要
components/bubble/Bubble.tsx 添加 typingSuffix 变量,更新内容渲染逻辑以包含后缀。onUpdate 函数在 useEffect 中调用。
components/bubble/demo/typing.tsx 更新 Bubble 组件的 typing 属性,添加 suffix 属性并设置为心形表情。
components/bubble/hooks/useTypingConfig.ts 更新返回类型,添加 suffix,并在条件下返回 null
components/bubble/interface.ts TypingOption 接口中添加可选属性 suffix
tests/utils.tsx 更新导入语句,修改 customRender 函数签名以返回 RenderResult

Possibly related issues

Possibly related PRs

Suggested reviewers

  • YumoImer
  • afc163

兔子欢跳庆新生,
打字后缀显心情。
💗 文字舞动如春风,
组件更美乐无穷。
代码更新乐无边,
测试齐全保安然。
兔子祝福伴你行!


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 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 5, 2024

Preview is ready

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

🧹 Outside diff range and nitpick comments (3)
components/bubble/hooks/useTypingConfig.ts (1)

15-16: 建议完善默认值注释

当前注释 "set default suffix is empty" 可以更加专业和详细。

建议修改为:

-      // set default suffix is empty
+      // 默认后缀为空字符串,用于保持向后兼容性
components/bubble/interface.ts (1)

12-15: 建议增强属性文档说明

虽然已添加了默认值说明,但建议补充更多使用说明和示例。

建议修改为:

   /**
-   * @default ""
+   * 打字动画过程中显示的后缀内容
+   * @default ""
+   * @example
+   * ```tsx
+   * suffix: <>💗</> // 显示心形图标
+   * suffix: "..." // 显示省略号
+   * ```
    */
components/bubble/Bubble.tsx (1)

119-124: 建议增加对 typingSuffix 的空值处理

当前实现在 isTyping 为 true 时直接渲染 typingSuffix,建议添加空值检查以提高代码健壮性。

建议修改如下:

  contentNode = (
    <>
      {mergedContent as React.ReactNode}
-     {isTyping && typingSuffix}
+     {isTyping && typingSuffix != null && typingSuffix}
    </>
  );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0cafa79 and 5e8c881.

⛔ 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 (5)
  • components/bubble/Bubble.tsx (2 hunks)
  • components/bubble/demo/typing.tsx (2 hunks)
  • components/bubble/hooks/useTypingConfig.ts (1 hunks)
  • components/bubble/interface.ts (1 hunks)
  • tests/utils.tsx (2 hunks)
🔇 Additional comments (7)
tests/utils.tsx (2)

1-1: 导入语句的改进符合最佳实践

导入语句的组织更加清晰,并且添加了必要的类型导入。这些改变提高了代码的类型安全性。

Also applies to: 6-6


32-33: 函数签名的类型注解改进

customRender 函数添加了明确的返回类型注解,这是一个很好的改进:

  • 提高了代码的类型安全性
  • 改善了 IDE 的类型提示支持
  • 使函数接口更加清晰

让我们验证一下这个类型改动是否与测试文件中的使用方式一致:

✅ Verification successful

类型注解改动验证完成

根据代码分析,customRender 函数的返回类型注解是合适的:

  • renderHook 函数中使用 customRender 时,没有直接使用其返回值
  • customRender 作为 render 的别名被导出,其类型与 @testing-library/reactRenderResult 保持一致
  • 类型定义与实际实现相符,不会引起类型不匹配的问题
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 customRender 的使用情况,确保返回值的使用符合新的类型定义

# 搜索测试文件中使用 customRender 返回值的情况
rg -t tsx -t ts "const \w+ = .*customRender\(" -A 2

Length of output: 81


Script:

#!/bin/bash
# 搜索所有包含 customRender 的文件
rg "customRender" --type js --type jsx --type ts --type typescript

# 查看测试文件中的具体使用情况
rg "customRender" -B 2 -A 2 --type js --type jsx --type ts --type typescript

Length of output: 199


Script:

#!/bin/bash
# 使用 fd 查找所有可能的测试文件
fd "\.(test|spec)\.(ts|tsx|js|jsx)$"

# 使用 ast-grep 查找 customRender 的使用情况
ast-grep --pattern 'customRender($$$)'

# 直接查看 utils.tsx 文件的完整内容
cat tests/utils.tsx

Length of output: 5228

components/bubble/demo/typing.tsx (1)

15-15: 代码示例实现得当!

示例中使用表情符号作为打字后缀的方式直观且易于理解,很好地展示了新功能的使用方法。

components/bubble/hooks/useTypingConfig.ts (2)

5-7: 类型定义清晰完整!

返回元组的类型定义准确且易于理解,很好地支持了新增的suffix功能。


23-23: 返回值处理恰当!

返回元组包含了所有必要的配置项,且保持了良好的代码结构。

components/bubble/Bubble.tsx (2)

64-64: 钩子返回值解构符合预期!

useTypingConfig 钩子的返回值扩展符合组件需求,保持了代码的一致性和可读性。


Line range hint 64-124: 确认实现符合需求规范

实现完全满足 PR 目标:

  1. 成功添加了 typing suffix 支持
  2. 保持了向后兼容性
  3. 实现方式简洁且符合组件设计模式

建议在合并前验证以下场景:

Copy link

codecov bot commented Dec 5, 2024

Bundle Report

Changes will decrease total bundle size by 262.65kB (-62.78%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antdx-array-push 155.72kB 262.65kB (-62.78%) ⬇️

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.37%. Comparing base (0cafa79) to head (5e8c881).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #312      +/-   ##
==========================================
+ Coverage   91.36%   91.37%   +0.01%     
==========================================
  Files          66       66              
  Lines        1447     1449       +2     
  Branches      368      369       +1     
==========================================
+ Hits         1322     1324       +2     
  Misses        125      125              

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

@YumoImer
Copy link
Collaborator

YumoImer commented Dec 5, 2024

When I lint, I encounter a problem

似乎只有通过 pnpm i 的方式安装依赖后运行 pnpm lint 才会遇到这个问题。

我试了下,使用 bun i 然后 bun lint 是可以正常在 main 分支上执行的。

对于这个问题,你的解决方案是可以的。

@YumoImer
Copy link
Collaborator

YumoImer commented Dec 5, 2024

对于实现后的效果,我之前没有在 issues 里描述清楚,抱歉~

期望是:替换原有的 typing 效果,现在看起来是在原有基础上额外添加了一个后缀:

image

举一个期望的效果的示例(该效果可以参考现在 ChatGPT 的交互)

image

@YumoImer
Copy link
Collaborator

YumoImer commented Dec 5, 2024

I want to move the PR to the feature branch, just like the contribution document says, but I found that the project does not have a feature branch, so I moved it to the main branch.

这是我的问题,抱歉~已添加 feature 分支。

@BQXBQX
Copy link
Contributor Author

BQXBQX commented Dec 6, 2024

那我先把这个 pr 关掉?提一个 pnpm lint fix 到 main,一个 typing suffix 到 feature 🤔

@BQXBQX BQXBQX closed this Dec 6, 2024
@BQXBQX BQXBQX deleted the feat/suffix branch December 6, 2024 07:49
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