Skip to content

Conversation

@kiner-tang
Copy link
Contributor

@kiner-tang kiner-tang commented Jul 13, 2025

image image image

Summary by CodeRabbit

  • 新功能

    • 图片预览支持自定义覆盖层(cover)的内容及其位置,可选择顶部、底部或居中显示。
    • 新增图片覆盖层的样式和结构,提升内容展示的灵活性。
    • 新增演示文档和示例,展示覆盖层位置控制功能。
  • 测试

    • 增加了针对覆盖层位置切换的测试用例,确保功能稳定。
  • 文档

    • 新增了关于覆盖层位置功能的使用说明和示例文档。
  • 杂项

    • 新增测试快照更新脚本,便于维护测试用例。

@vercel
Copy link

vercel bot commented Jul 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
image ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 13, 2025 9:13am

@coderabbitai
Copy link

coderabbitai bot commented Jul 13, 2025

Walkthrough

本次变更为图片组件的预览遮罩(cover)引入了位置自定义功能,包括样式、组件逻辑、文档和测试的同步更新。新增了 cover 配置的 placement 属性,可选择 top、bottom 或 center,相关样式和交互逻辑均已适配,并补充了演示和测试用例。

Changes

文件/分组 变更摘要
assets/index.less 新增和增强图片遮罩(cover)相关的 CSS,包括位置和布局样式。
src/Image.tsx 支持 cover 配置 placement 属性,重构 cover 渲染逻辑,类型增强。
docs/examples/coverPlacement.tsx 新增演示组件,支持动态切换 cover 的位置。
docs/demo/coverPlacement.md 新增文档页面,展示 cover 位置功能的 demo。
tests/basic.test.tsx 增加 cover 位置相关的测试用例,完善测试流程。
package.json 新增 test:update 脚本,便于更新测试快照。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ImageComponent
    participant PreviewOverlay

    User->>ImageComponent: 选择 cover 位置(top/bottom/center)
    ImageComponent->>PreviewOverlay: 渲染带 placement 的 cover 配置
    PreviewOverlay-->>User: 按指定位置展示遮罩内容
Loading

Suggested reviewers

  • thinkasany

Poem

🐰
遮罩轻舞随风转,
顶底居中任我选。
代码新添灵活意,
预览一笑映春天。
兔子挥爪庆更新,
CSS 变幻展新颜!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

docs/examples/coverPlacement.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

tests/basic.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/Image.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a 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.

@codecov
Copy link

codecov bot commented Jul 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.41%. Comparing base (e5a5685) to head (833573c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #433   +/-   ##
=======================================
  Coverage   99.40%   99.41%           
=======================================
  Files          17       17           
  Lines         504      510    +6     
  Branches      146      152    +6     
=======================================
+ Hits          501      507    +6     
  Misses          3        3           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@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 (1)
src/Image.tsx (1)

128-134: 简化提取逻辑以提高可读性。

当前的提取逻辑存在冗余检查,可以简化为更清晰的实现:

-  const coverPlacement = typeof cover === 'object' && (cover as CoverConfig).placement ?
-    (cover as CoverConfig).placement || 'center' :
-    'center';
-
-  const coverNode = typeof cover === 'object' && (cover as CoverConfig).coverNode ?
-    (cover as CoverConfig).coverNode :
-    cover as React.ReactNode;
+  const isCoverConfig = cover && typeof cover === 'object' && 'placement' in cover;
+  const coverPlacement = isCoverConfig ? (cover as CoverConfig).placement || 'center' : 'center';
+  const coverNode = isCoverConfig ? (cover as CoverConfig).coverNode : cover as React.ReactNode;

这样可以避免重复的类型断言,提高代码可读性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e5a5685 and 833573c.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/basic.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • assets/index.less (2 hunks)
  • docs/demo/coverPlacement.md (1 hunks)
  • docs/examples/coverPlacement.tsx (1 hunks)
  • package.json (1 hunks)
  • src/Image.tsx (3 hunks)
  • tests/basic.test.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
docs/examples/coverPlacement.tsx (2)
src/Image.tsx (1)
  • CoverConfig (22-25)
docs/examples/common.tsx (1)
  • defaultIcons (14-24)
tests/basic.test.tsx (1)
src/Image.tsx (1)
  • CoverConfig (22-25)
src/Image.tsx (1)
src/Preview/index.tsx (1)
  • InternalPreviewConfig (70-108)
🔇 Additional comments (14)
package.json (1)

39-39: LGTM! 标准的测试快照更新脚本。

这个新增的npm脚本是用于更新测试快照的标准配置,与新增的封面位置功能测试用例配套使用。

assets/index.less (2)

31-31: LGTM! 适当的溢出控制。

为图片元素添加 overflow: hidden 可以防止内容溢出,这对于新的封面覆盖层功能是必要的。


40-78: LGTM! 封面位置样式实现完善。

CSS样式实现了三种封面位置选项的完整支持:

  • 基础 .rc-image-cover 类提供了合理的默认样式(绝对定位、弹性布局、过渡效果)
  • 三个位置变体(-top-bottom-center)都有正确的定位逻辑
  • 使用弹性布局实现了良好的内容对齐
  • 半透明背景和过渡效果提升了用户体验

样式设计与组件逻辑完美配合。

src/Image.tsx (4)

22-25: LGTM! 接口设计合理。

CoverConfig 接口设计简洁明确,支持可选的封面节点和位置配置。类型定义准确支持三种位置选项。


27-27: LGTM! 类型扩展向后兼容。

cover 属性扩展为支持 React.ReactNode | CoverConfig 的联合类型,既保持了向后兼容性,又支持新的配置对象功能。


252-252: LGTM! 动态类名应用正确。

正确地将封面位置应用到CSS类名中,实现了动态的样式切换功能。


258-258: LGTM! 渲染逻辑更新得当。

使用提取出的 coverNode 替代原始的 cover,正确支持了新的配置对象结构。

docs/demo/coverPlacement.md (1)

1-8: LGTM! 标准的演示文档结构。

文档结构标准,正确引用了示例代码,为新功能提供了清晰的演示页面。

docs/examples/coverPlacement.tsx (3)

8-8: LGTM! 正确的类型使用。

使用 CoverConfig["placement"] 类型确保了状态与接口定义的一致性。


15-19: LGTM! 选项值与类型定义匹配。

下拉选择器的选项值完全匹配 CoverConfig.placement 的类型定义,确保了类型安全。


34-37: LGTM! 新功能演示完整。

正确展示了新的封面配置对象用法,包括:

  • coverNode 属性设置封面内容
  • placement 属性设置位置选择
  • 与状态管理的正确绑定

这是一个很好的功能演示示例。

tests/basic.test.tsx (3)

1-3: 导入语句更新合理

新增的act导入用于处理异步状态更新,CoverConfig类型导入用于类型安全,这些都是测试新功能所必需的。


6-12: 计时器设置实现正确

使用jest.useFakeTimers()jest.useRealTimers()的beforeEach/afterEach模式是测试异步行为的最佳实践,确保每个测试都有干净的计时器环境。


112-159: cover placement测试用例实现全面

这个测试用例很好地验证了新的cover placement功能:

  • 正确使用了受控组件模式来测试动态placement变化
  • 适当地使用act()jest.runAllTimers()来处理状态更新
  • 覆盖了所有三种placement选项(center、top、bottom)
  • 验证了对应的CSS类名是否正确应用

测试逻辑清晰,断言准确,是一个高质量的集成测试。

{cover !== false && canPreview && (
<div
className={classnames(`${prefixCls}-cover`, classNames.cover)}
className={classnames(`${prefixCls}-cover`, classNames.cover, `${prefixCls}-cover-${coverPlacement}`)}
Copy link
Member

Choose a reason for hiding this comment

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

这里有支持语义化结构,可以直接在 antd 里通过 classNames.cover 来扩展

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不需要在rc支持placement么

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不需要再 rc 组件支持 placement api 的话,我周末直接在 antd 上搞吧

@afc163 afc163 merged commit 651c080 into react-component:master Jul 17, 2025
9 checks passed
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.

3 participants