Skip to content

feat(bubble): add extra content support to Bubble component #930

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

Open
wants to merge 3 commits into
base: feature
Choose a base branch
from

Conversation

coding-ice
Copy link
Member

@coding-ice coding-ice commented Jun 17, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature

🔗 Related Issues

close: #889

Language Changelog
🇺🇸 English add extra content support to Bubble component
🇨🇳 Chinese 为气泡组件增加额外元素

Summary by CodeRabbit

  • 新功能
    • Bubble 组件新增 extra 插槽属性,支持自定义扩展内容,可为 React 节点或渲染函数。
    • 文档和演示新增对 extra 属性的说明与示例。
  • 样式
    • 增加了 extra 插槽的样式,支持在气泡两侧正确定位扩展内容。
  • 文档
    • API 文档同步新增 extra 属性及类型说明,完善英文和中文文档。
  • 测试
    • 新增针对 extra 属性的单元测试用例,确保其渲染正确。

Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

本次更改为 Bubble 组件引入了新的 extra 属性,允许通过 ReactNode 或渲染函数自定义扩展内容。类型定义、主组件、样式、文档及测试均已同步支持该属性,并新增了相关演示和多语言文档说明。

Changes

文件/分组 变更简述
components/bubble/Bubble.tsx 新增 extra 属性支持,统一 slot 类型,完善渲染逻辑
components/bubble/interface.ts 新增 SlotRenderType 类型别名,BubbleProps 增加 extra 属性,相关类型调整
components/bubble/style/index.ts 新增 .ant-bubble-extra 相关样式及定位
components/bubble/tests/index.test.tsx 新增 extra 属性相关的渲染测试用例
components/bubble/demo/extra.md 新增 extra 属性的中英文说明文档
components/bubble/demo/extra.tsx 新增 extra 属性的演示代码
components/bubble/demo/_semantic.tsx 语义预览中增加 extra 相关内容,演示中使用 extra 属性
components/bubble/index.en-US.md
components/bubble/index.zh-CN.md
文档 API 新增 extra 属性,统一 slot 类型定义,增加版本说明及演示

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Bubble
    participant ExtraSlot

    User->>Bubble: 传递 extra 属性(ReactNode 或函数)
    Bubble->>Bubble: 判断是否存在 extra
    alt extra 存在
        Bubble->>ExtraSlot: 渲染 extra 内容
        ExtraSlot-->>Bubble: 返回 extra 节点
    end
    Bubble->>User: 渲染完整 Bubble 组件(含 extra 区域)
Loading

Assessment against linked issues

Objective Addressed Explanation
支持 Bubble 组件新增 extra: ReactNode 属性 (#889)

Assessment against linked issues: Out-of-scope changes

(未发现超出关联 issue 889 需求范围的代码变更)

Suggested labels

documentation, lgtm

Suggested reviewers

  • afc163

Poem

气泡新添 extra 款,
内容自定义不一般。
图标旋转添趣味,
文档测试齐完善。
代码如画兔儿跳,
新功能上线乐开颜!
૮₍ ˶ᵔ ᵕ ᵔ˶ ₎ა

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this 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
Contributor

github-actions bot commented Jun 17, 2025

Preview is ready

@coding-ice coding-ice changed the base branch from main to feature June 17, 2025 14:52
@dosubot dosubot bot added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 17, 2025
Copy link

codecov bot commented Jun 17, 2025

Bundle Report

Changes will increase total bundle size by 2.43kB (1.78%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antdx-array-push 138.67kB 2.43kB (1.78%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: antdx-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antdx.min.js 2.43kB 138.67kB 1.78%

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: 3

🧹 Nitpick comments (11)
components/bubble/demo/extra.md (1)

1-8: 中英文描述缺少完整句号,建议补全以保持文档风格一致

当前中英文描述均无结尾标点,AntD 现有 demo 多数在句末使用句号或感叹号,建议保持一致。

-自定义扩展内容。
+自定义扩展内容。
 ...
-Customize extra content
+Customize extra content.
components/bubble/demo/extra.tsx (1)

1-18: demo 代码整体 OK,仅建议为列表子项显式添加 key(可选)

虽然此处 Flex 嵌套两个静态 Bubble 不会触发 React 列表 diff 警告,但示例通常遵循最佳实践,添加 key 能避免用户拷贝后遗漏。

-  <Flex vertical gap="small">
-    <Bubble content="Hello ice !" extra={<LoadingOutlined spin />} />
-    <Bubble
+  <Flex vertical gap="small">
+    <Bubble key="example-1" content="Hello ice !" extra={<LoadingOutlined spin />} />
+    <Bubble
+      key="example-2"
       placement="end"
@@
-    />
+    />
   </Flex>
components/bubble/__tests__/index.test.tsx (1)

74-85: 函数式 extra 断言类型同样应放宽

为一致性,建议将 HTMLSpanElement 改为 HTMLElement,以免实际节点类型变化导致 TS 不匹配,但并非阻塞问题。

-    const element = container.querySelector<HTMLSpanElement>(
+    const element = container.querySelector<HTMLElement>(
       '.ant-bubble .ant-bubble-extra .test-extra',
     );
components/bubble/Bubble.tsx (2)

21-24: 使用 SlotRenderType 可减少冗余类型定义

RenderSlotNode 实际上只是把三个完全相同的字段联合在一起,等价于 SlotRenderType<any> | undefined。直接复用公共类型可以少维护一层别名。

-type RenderSlotNode =
-  | BubbleProps<any>['footer']
-  | BubbleProps<any>['header']
-  | BubbleProps<any>['extra'];
+type RenderSlotNode = SlotRenderType<any> | undefined;

这样后续如果再增加槽位,只需在 BubbleProps 中声明即可,无需同步修改这里。


126-128: renderSlot 的参数类型遗漏 undefined

当前的 RenderSlotNode 已包含 undefined,但 renderSlot 形参未显式接收可空类型,TypeScript 会推断为 never → 编译通过但 IDE 提示不友好。建议补充可空标注,或在函数体内提前返回。

-const renderSlot = (node: RenderSlotNode) =>
+const renderSlot = (node: RenderSlotNode | undefined) =>
   typeof node === 'function' ? node(typedContent, { key: _key }) : node;
components/bubble/index.en-US.md (2)

24-24: 示例顺序建议保持语义一致

Demo 列表一直以功能复杂度递增排序,extra 功能应放到 “Header and footer” 之后更自然,可考虑调整。


50-52: 参数顺序建议统一为 header → footer → extra

文档与代码接口中均是 headerfooterextra 的语义顺序,这里将 footer 放在第一列容易造成阅读困惑。

components/bubble/index.zh-CN.md (2)

25-25: 示例排序保持一致性

同英文文档,extra 示例建议放在“头和尾”之后,保持阅读节奏一致。


51-53: 属性顺序保持一致

建议将表格列顺序调整为 headerfooterextra,与实现及英文文档保持一致。

components/bubble/interface.ts (2)

27-30: 范型参数在联合类型左侧未被使用

SlotRenderType<ContentType> 左侧的 React.ReactNode 无法携带范型信息,实际编译后 ContentType 只对函数分支生效。可以接受,但如需严格类型,可改为:

type SlotRenderType<ContentType> =
  | React.ReactElement
  | string
  | number
  | boolean
  | null
  | undefined
  | ((content: ContentType, info: SlotInfoType) => React.ReactNode);

或直接使用 ReactNode 并在函数分支上做范型约束。


48-51: 接口字段顺序建议保持一致

保持 headerfooterextra 的先后顺序,便于查阅与文档对应。当前顺序与文档不一致。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bb6aa8d and 0cc296d.

⛔ 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 (9)
  • components/bubble/Bubble.tsx (4 hunks)
  • components/bubble/__tests__/index.test.tsx (1 hunks)
  • components/bubble/demo/_semantic.tsx (4 hunks)
  • components/bubble/demo/extra.md (1 hunks)
  • components/bubble/demo/extra.tsx (1 hunks)
  • components/bubble/index.en-US.md (3 hunks)
  • components/bubble/index.zh-CN.md (3 hunks)
  • components/bubble/interface.ts (2 hunks)
  • components/bubble/style/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
components/bubble/Bubble.tsx (1)
components/bubble/interface.ts (1)
  • BubbleProps (31-51)
components/bubble/__tests__/index.test.tsx (1)
components/bubble/interface.ts (1)
  • BubbleContentType (21-21)
components/bubble/interface.ts (1)
components/_util/type.ts (1)
  • AnyObject (1-1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test / react component workflow
  • GitHub Check: build preview
  • GitHub Check: size
🔇 Additional comments (4)
components/bubble/demo/_semantic.tsx (3)

14-22: 语义字段新增 “extra” 👍

新增的中英文语义字段与 semantics 数组保持一致,未发现问题。


38-39: semantics 顺序保持一致性

目前顺序为 avatar→header→content→footer→extra,与组件视觉自左至右/上至下顺序一致,可读性良好。无动作建议。


51-52: demo 中 extra 使用 LoadingOutlined 直观易懂

实现方式清晰,无明显问题。

components/bubble/interface.ts (1)

19-20: SemanticType 扩展后需同步文档锚点

已经增加 'extra',请确认样式文档及 Design Token 表格是否也同步包含该语义节点,避免漏掉主题变量。

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.53%. Comparing base (8222eee) to head (0888fa0).

Additional details and impacted files
@@             Coverage Diff             @@
##           feature     #930      +/-   ##
===========================================
- Coverage    92.78%   92.53%   -0.26%     
===========================================
  Files           69       69              
  Lines         1608     1554      -54     
  Branches       411      419       +8     
===========================================
- Hits          1492     1438      -54     
  Misses         116      116              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coding-ice
Copy link
Member Author

@afc163 有空帮忙 CR 下,刚好我司有这个需求

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bubble 增加 extra prop
1 participant