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) #380

Merged
merged 1 commit into from
Dec 20, 2024
Merged

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

merged 1 commit into from
Dec 20, 2024

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,增强了打字效果的视觉表现。
    • typing 属性中添加了一个心形表情符号的 suffix,使第二个 Bubble 组件的文本显示更为丰富。
  • Bug 修复

  • 文档

  • 重构

    • 更新了 useTypingConfig 钩子以返回新的 suffix 配置选项。
  • 样式

  • 测试

  • 杂项

* feat(bubble): add typing suffix support

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

coderabbitai bot commented Dec 20, 2024

📝 Walkthrough

概述

演练

此次更改主要扩展了 Bubble 组件的打字机效果功能。通过在 useTypingConfig 钩子中引入 typingSuffix,开发者现在可以为打字效果添加自定义后缀。修改涉及 Bubble 组件、演示文件、接口定义和钩子实现,以支持在打字过程中显示额外的内容。

变更

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

可能相关的问题

可能相关的 PR

诗歌

🐰 打字兔子轻轻跳,
后缀魔法随风飘,
文字跳动带心跳,
代码如诗妙无比,
创意在指尖绽放! 💗

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 appended during typing. Additionally, the typing demo documentation has been improved to reflect these changes.

Changes

File Summary
components/bubble/Bubble.tsx Updated to include typing suffix in the typing configuration and rendering logic.
components/bubble/hooks/useTypingConfig.ts Modified to return typing suffix in the typing configuration.
components/bubble/interface.ts Added suffix property to the TypingOption interface.
components/bubble/demo/typing.tsx Enhanced demo to include examples of typing with suffix.
components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap
components/bubble/__tests__/__snapshots__/demo.test.ts.snap
Updated snapshots to reflect changes in typing behavior.

@@ -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 true. If typingSuffix is a React component, ensure it is rendered correctly and does not cause any rendering issues.

Copy link
Member

Choose a reason for hiding this comment

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

这句话还是不太好理解,有 typingSuffix 应该也是输入中,现在的逻辑是反的。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

// 默认的打字效果:输入中 且 没有配置 typingSuffix
const isDefaultTyping = isTyping && !typingSuffix;

// css
[`${prefixCls}-typing`]: isDefaultTyping && !loading && !messageRender,

改成这样:多一步解释代码,方便后人理解是不好点~

想了下 typingSuffix 确实只代表一个后缀,不代表输入中。或者有啥建议没~

Copy link
Member

Choose a reason for hiding this comment

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

typing: { suffix: 'x' } API 这么设计的话当然就代表是输入中。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

有道理,那感觉这里先不合并,我们后续再议

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

或者 typingSuffix -> customSuffix 怎么样,这样语义是正确的。

[${prefixCls}-typing]: isTyping && !loading && !messageRender && !customSuffix,

然后我在想,先合并我再提 PR 把这改了,因为 feature 是保护分支,不能直接 push

Copy link
Member

Choose a reason for hiding this comment

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

我先合了,不是很大的问题。

Copy link

codecov bot commented Dec 20, 2024

Bundle Report

Changes will decrease total bundle size by 74 bytes (-0.05%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antdx-array-push 156.23kB 74 bytes (-0.05%) ⬇️

Copy link

Deploying ant-design-x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7869126
Status: ✅  Deploy successful!
Preview URL: https://6ef1319c.ant-design-x.pages.dev
Branch Preview URL: https://feature.ant-design-x.pages.dev

View logs

Copy link

size-limit report 📦

Path Size
dist/antdx.min.js 40.81 KB (+21 B 🔺)

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.37%. Comparing base (876f7d4) to head (7869126).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #380      +/-   ##
==========================================
- Coverage   91.48%   91.37%   -0.11%     
==========================================
  Files          66       66              
  Lines        1468     1450      -18     
  Branches      395      369      -26     
==========================================
- Hits         1343     1325      -18     
  Misses        125      125              

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

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 (4)
components/bubble/demo/typing.tsx (1)

18-22: 建议丰富示例内容

当前示例展示了基本的 suffix 用法,建议添加更多样化的示例,比如:

  • 使用不同类型的 suffix(文本、图标等)
  • 展示不同打字速度下的 suffix 效果
  • 动态切换 suffix 的场景
components/bubble/interface.ts (1)

12-15: 建议完善属性文档

当前的 JSDoc 注释仅说明了默认值,建议补充以下信息:

  • 属性的具体用途说明
  • 可接受的值类型示例
  • 使用场景建议

示例文档格式:

/**
 * 打字效果完成后显示的后缀内容
 * @default null
 * @example
 * // 使用文本
 * suffix: "✨"
 * // 使用 React 组件
 * suffix: <Icon type="check" />
 */
suffix?: React.ReactNode;
components/bubble/Bubble.tsx (2)

104-104: 优化打字动画的类名逻辑

类名条件判断中加入了 !typingSuffix 检查,这样可以在有后缀时避免显示打字动画。建议添加注释说明这个逻辑的目的。

-      [`${prefixCls}-typing`]: isTyping && !loading && !messageRender && !typingSuffix,
+      // 当存在后缀时不显示打字动画,以避免视觉干扰
+      [`${prefixCls}-typing`]: isTyping && !loading && !messageRender && !typingSuffix,

119-124: 内容渲染逻辑优化

使用 Fragment 包装内容和打字后缀的实现方式很好。建议考虑以下改进:

  1. 为后缀添加特定的类名,便于样式定制
  2. 考虑为后缀添加可访问性支持
     contentNode = (
       <>
         {mergedContent as React.ReactNode}
-        {isTyping && typingSuffix}
+        {isTyping && (
+          <span className={`${prefixCls}-typing-suffix`} aria-hidden="true">
+            {typingSuffix}
+          </span>
+        )}
       </>
     );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 876f7d4 and 7869126.

⛔ 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 (4)
components/bubble/hooks/useTypingConfig.ts (3)

5-7: 返回类型定义清晰且完整

返回类型使用了显式的元组标签,这提高了代码的可读性和类型安全性。


9-9: 默认值处理合理

为新增的 suffix 属性设置了合适的默认值(null),并添加了清晰的注释说明。

Also applies to: 15-16


23-23: 配置合并逻辑完善

返回值中正确包含了 suffix 配置,保持了与其他配置项一致的处理方式。

components/bubble/Bubble.tsx (1)

64-64: 从 useTypingConfig 钩子中解构新增的 typingSuffix

这个改动扩展了 useTypingConfig 的返回值,新增了 typingSuffix 支持。确保 useTypingConfig 钩子的实现与此更改保持一致。

✅ Verification successful

useTypingConfig 钩子的实现已正确支持 typingSuffix

useTypingConfig 钩子的实现完全符合预期:

  • 返回值类型正确定义了四个参数:[enableTyping: boolean, step: number, interval: number, suffix: React.ReactNode]
  • 默认情况下返回 [false, 0, 0, null]
  • 当提供 typing 配置时,会返回 [true, baseConfig.step, baseConfig.interval, baseConfig.suffix]
  • suffix 属性已在 baseConfig 中正确初始化并处理
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证 useTypingConfig 钩子的实现
ast-grep --pattern 'const useTypingConfig = ($params) => {
  $$$
  return [$$$, $$$, $$$, $$$]
}'

Length of output: 99


Script:

#!/bin/bash
# 搜索 useTypingConfig 的定义和实现
rg "useTypingConfig" -A 10

Length of output: 2101


Script:

#!/bin/bash
# 使用不同的 ast-grep 模式搜索
ast-grep --pattern 'function useTypingConfig($$$) {
  $$$
}'

Length of output: 1642


Script:

#!/bin/bash
# 查找包含 useTypingConfig 的文件
fd useTypingConfig

Length of output: 63

@afc163 afc163 merged commit b02b505 into main Dec 20, 2024
14 of 15 checks passed
@YumoImer YumoImer deleted the feature branch December 25, 2024 09:14
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.

4 participants