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

refactor: Bubble style #314

Merged
merged 6 commits into from
Dec 9, 2024
Merged

refactor: Bubble style #314

merged 6 commits into from
Dec 9, 2024

Conversation

YumoImer
Copy link
Collaborator

@YumoImer YumoImer commented Dec 6, 2024

变更点

  1. 优化了对 .ant-bubble-content-wrapper 以及 .ant-bubble-content 的最大宽度限制,并保证其不出现溢出现象,稳定给子节点提供宽度属性用于继承。
  2. 优化了在 placement: 'end' 时的样式问题
  3. 增加了穷举式的 debug demo

修复

fix: #318

其他背景

目前 Bubble 组件的 dom 结构会根据 props 动态调整, 这会导致开发者不太容易进行样式复写「比如面对内容样式溢出的场景」。

image

image

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能
    • 更新了气泡组件的样式,确保内容包装器的最大宽度不超过其父容器。
    • 添加了默认令牌的准备功能,以优化气泡组件的样式生成。
    • 在气泡组件的文档中新增了调试示例,提供了中英文的调试内容。

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

此次变更主要集中在 components/bubble/style/index.ts 文件中,对 genBubbleStyle 函数进行了修改,更新了 content-wrapper 类的样式定义,确保其可以适当收缩并遵循最大宽度限制。同时,新增了 prepareComponentToken 函数,用于返回一个空对象作为气泡组件的默认令牌,并更新了 genStyleHooks 函数以利用该令牌。此外,debug.md 文件中新增了中文和英文的调试内容,debug.tsx 文件引入了一个新的 React 组件 App,用于演示气泡组件的用法,最后在中英文文档中添加了调试示例代码。

Changes

文件路径 更改摘要
components/bubble/style/index.ts - 修改 genBubbleStyle 函数,添加 minWidth: 0maxWidth: '100%' 属性。
- 新增 prepareComponentToken 函数,返回空对象。
- 更新 genStyleHooks 函数以使用 prepareComponentToken
components/bubble/demo/debug.md - 新增中文(zh-CN)和英文(en-US)调试内容。
components/bubble/demo/debug.tsx - 新增 React 组件 App,用于演示气泡组件。
- 导出 App 组件。
components/bubble/index.en-US.md - 在文档中新增调试示例代码。
components/bubble/index.zh-CN.md - 在文档中新增调试示例代码。

Assessment against linked issues

Objective Addressed Explanation
确保内容块在右侧显示,挨着头像 (#318) 变更未明确说明如何解决样式错误。

Possibly related PRs

Poem

在草地上蹦跳的兔子,
新样式让气泡更美丽。
最大宽度不再受限,
令牌准备如春风轻。
让我们欢庆这变化,
兔子们一起跳跃欢笑! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ba766a8 and 4e767d7.

⛔ 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 (1)
  • components/bubble/demo/debug.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/bubble/demo/debug.tsx

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

Preview is ready

@YumoImer YumoImer requested a review from a team December 6, 2024 03:56
Copy link

codecov bot commented Dec 6, 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

🧹 Outside diff range and nitpick comments (1)
components/bubble/style/index.ts (1)

Line range hint 146-146: 建议添加组件 Token 相关文档

虽然目前 prepareComponentToken 返回空对象是合理的,但建议添加相关注释说明这个函数的用途,以及未来可能会支持的自定义 token。这样可以帮助其他开发者更好地理解和扩展组件样式系统。

建议添加如下注释:

+// 为气泡组件预设默认 token。
+// 当前返回空对象,未来可能会支持更多自定义样式 token。
export const prepareComponentToken: GetDefaultToken<'Bubble'> = () => ({});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5321c19 and 729ee44.

📒 Files selected for processing (1)
  • components/bubble/style/index.ts (1 hunks)
🔇 Additional comments (2)
components/bubble/style/index.ts (2)

97-97: 添加 maxWidth 限制是个合适的解决方案!

通过设置 maxWidth: '100%' 可以有效防止内容溢出父容器,这是一个简单但有效的修复方案。


97-97: 建议验证样式变更的影响范围

这次更改虽然解决了宽度溢出问题,但建议验证是否会影响现有的使用场景。

Also applies to: 146-146

✅ Verification successful

样式变更的影响范围可控

根据代码分析,这个宽度限制的修改是安全的:

  1. 该修改仅影响气泡组件的基础样式,不会影响其他组件
  2. 从示例代码和测试用例来看,气泡组件已经考虑了多种布局场景
  3. maxWidth: '100%' 是一个标准的响应式约束,可以防止内容溢出
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索项目中使用到 Bubble 组件的地方
rg -l "(?:import|from).*['\"].*bubble" --type ts --type tsx

# 检查是否有自定义样式覆盖
rg "ant-bubble-content-wrapper" --type css --type less --type scss

Length of output: 187


Script:

#!/bin/bash
# 搜索使用 Bubble 组件的文件
rg -l "(?:import|from).*['\"].*[Bb]ubble"

# 搜索样式相关的文件
fd -e css -e less -e scss | xargs rg "bubble"

# 检查组件的使用方式
rg -A 3 "<.*[Bb]ubble"

Length of output: 66877

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.36%. Comparing base (9c2bf53) to head (4e767d7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #314   +/-   ##
=======================================
  Coverage   91.36%   91.36%           
=======================================
  Files          66       66           
  Lines        1447     1447           
  Branches      368      383   +15     
=======================================
  Hits         1322     1322           
  Misses        125      125           

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

Copy link

github-actions bot commented Dec 6, 2024

size-limit report 📦

Path Size
dist/antdx.min.js 40.66 KB (-6 B 🔽)

Copy link

cloudflare-workers-and-pages bot commented Dec 6, 2024

Deploying ant-design-x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4e767d7
Status: ✅  Deploy successful!
Preview URL: https://549b9dca.ant-design-x.pages.dev
Branch Preview URL: https://fix-bubble-style.ant-design-x.pages.dev

View logs

@YumoImer YumoImer closed this Dec 6, 2024
 - docs: add debug demo
@YumoImer YumoImer reopened this Dec 7, 2024
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/demo/debug.tsx (3)

37-49: 建议:优化自定义属性的类型定义

customizationProps 的类型定义可以更严格:

-  const customizationProps: BubbleProps = {
+  const customizationProps: Required<Pick<BubbleProps, 'header' | 'footer' | 'avatar' | 'classNames'>> = {

这样可以:

  1. 明确表示这些属性是必需的
  2. 提供更好的类型检查
  3. 减少可能的运行时错误

51-76: 建议:将气泡变体配置抽离为常量

bubbleDict 包含了重要的测试用例,建议:

  1. 将其抽离为单独的常量文件
  2. 添加更多边界情况的测试用例
  3. 为每个测试用例添加注释说明其目的
+ // 建议创建新文件:bubble-test-cases.ts
+ export const BUBBLE_TEST_CASES = {
+   string: {
+     content: 'string bubble',
+     variant: 'filled',
+     shape: 'corner',
+   },
+   // ... 其他测试用例
+ } as const;

97-118: 建议:增强列表测试用例

当前的 Bubble.List 测试用例可以更全面:

  1. 测试 autoScroll 属性的行为
  2. 添加更多的交互场景
  3. 验证长列表的性能表现
  <Bubble.List
+   autoScroll={true}
    items={[
      // 现有项目...
+     // 建议添加更多测试项
+     {
+       ...bubbleDict.string,
+       content: '测试超长文本自动滚动...',
+       key: 'scroll-test'
+     },
    ]}
+   // 建议添加性能测试用例
  />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 729ee44 and ba766a8.

📒 Files selected for processing (5)
  • components/bubble/demo/debug.md (1 hunks)
  • components/bubble/demo/debug.tsx (1 hunks)
  • components/bubble/index.en-US.md (1 hunks)
  • components/bubble/index.zh-CN.md (1 hunks)
  • components/bubble/style/index.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/bubble/demo/debug.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/bubble/style/index.ts
🔇 Additional comments (3)
components/bubble/index.zh-CN.md (1)

22-22: 调试示例添加正确!

调试示例的位置放在所有示例的最前面是合适的,这样可以方便开发者快速找到并验证气泡组件的行为。

components/bubble/index.en-US.md (1)

21-21: 文档同步更新完成!

中英文文档保持了良好的一致性,调试示例在两个文档中的位置相同。

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

28-31: 注意:固定宽度可能导致溢出问题

fixedWidthBlock 样式中使用固定宽度(1000px)可能会在某些视口大小下导致溢出。建议:

  1. 考虑使用相对单位(如 %vw
  2. 添加 max-width 属性
  3. 确保内容可以正确换行

让我们验证一下这个宽度设置在不同场景下的表现:

@YumoImer
Copy link
Collaborator Author

YumoImer commented Dec 7, 2024

@tabzzz1 看下是否也可以解决你的问题

@YumoImer YumoImer changed the title fix: Bubble width overflow problem refactor: Bubble style Dec 7, 2024
@YumoImer
Copy link
Collaborator Author

YumoImer commented Dec 7, 2024

@ant-design/ant-design-x 需要大家帮 CR 下~感谢

@tabzzz1
Copy link
Contributor

tabzzz1 commented Dec 7, 2024

@tabzzz1 看下是否也可以解决你的问题

可以的!效果非常好:)

@YumoImer YumoImer merged commit 32ddbe7 into main Dec 9, 2024
15 checks passed
@YumoImer YumoImer deleted the fix/bubble-style branch December 9, 2024 02:39
@YumoImer YumoImer linked an issue Dec 15, 2024 that may be closed by this pull request
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.

Not work placement with header and footer Bubble内容区增加header后,样式错误
3 participants