Skip to content

fix(image): 组件内部的style处理覆盖传入的className#3165

Merged
oasis-cloud merged 3 commits intojdf2e:feat_v3.xfrom
Miles-hxy:fix_image
Apr 11, 2025
Merged

fix(image): 组件内部的style处理覆盖传入的className#3165
oasis-cloud merged 3 commits intojdf2e:feat_v3.xfrom
Miles-hxy:fix_image

Conversation

@Miles-hxy
Copy link
Collaborator

@Miles-hxy Miles-hxy commented Apr 10, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 新增了图片全尺寸展示模式,使图片能够自动填满其父容器。
  • 改进

    • 优化了图片组件的样式逻辑,提升了不同平台下显示的一致性和稳定性。

@coderabbitai
Copy link

coderabbitai bot commented Apr 10, 2025

Walkthrough

该 PR 包含两个文件的更新。首先,在 src/packages/image/image.scss 中为 .nut-image 类添加了一个新的修饰符 -basic,设置宽度和高度均为 100%。其次,在 src/packages/image/image.taro.tsx 中重构了 containerStyle 对象,通过扩展操作符取代了嵌套三元表达式,同时在非 WEB 环境下为 View 组件添加了条件类名,以简化样式逻辑。

Changes

文件 变更总结
src/.../image.scss .nut-image 类添加新的 -basic 修饰符,宽高均设为 100%
src/.../image.taro.tsx 重构 containerStyle 条件逻辑,使用扩展操作符,并在非 WEB 环境下为 View 添加条件类名

Sequence Diagram(s)

sequenceDiagram
  participant ImageComp as Image Component
  participant Env as Environment Checker
  participant Style as ContainerStyle Builder
  participant View as View Renderer

  ImageComp->>Env: 检查环境 (是否为 WEB)
  Env-->>ImageComp: 返回环境信息
  ImageComp->>Style: 根据环境条件构建 containerStyle
  Style-->>ImageComp: 返回样式对象
  ImageComp->>View: 传递 containerStyle 和条件类名,渲染 View
Loading

Suggested reviewers

  • oasis-cloud

Poem

嗨,我是小兔,代码间欢腾跳跃,
新的样式悄然降临,如花开放无悔。
扩展逻辑化繁为简,代码清晰又明快,
条件判断在行间舞动,环境分明趣味多。
更新像晨曦洒满林间,愿你我共赏快乐的代码!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cc94ce3 and 07f382e.

📒 Files selected for processing (2)
  • src/packages/image/image.scss (1 hunks)
  • src/packages/image/image.taro.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/packages/image/image.taro.tsx (1)
src/utils/px-check.ts (1)
  • pxCheck (1-5)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (3)
src/packages/image/image.scss (1)

15-18: 新增的样式类提供了更好的基础布局控制

这个新增的 .nut-image-basic 样式类设置宽高为 100%,有助于确保图片容器在不同环境下保持一致的布局行为。这是一个很好的改进,解决了样式覆盖的问题。

src/packages/image/image.taro.tsx (2)

57-64: 代码结构优化,使用展开运算符提高可读性

使用展开运算符(spread operator)替代嵌套的三元表达式来构建 containerStyle 对象,使代码更加清晰易读。这是一个很好的重构,使样式逻辑更加直观。


103-112: 根据环境条件应用基础样式类,解决了样式覆盖问题

为非 WEB 环境添加 ${classPrefix}-basic 类名,配合新增的 CSS 样式,有效解决了 image 的 style 覆盖 className 的问题。这种方法可以确保在不同环境中保持一致的布局行为。

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Apr 10, 2025
@codecov
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.19%. Comparing base (cc94ce3) to head (07f382e).
Report is 3 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #3165      +/-   ##
=============================================
+ Coverage      87.18%   87.19%   +0.01%     
=============================================
  Files            279      279              
  Lines          18537    18537              
  Branches        2820     2821       +1     
=============================================
+ Hits           16161    16164       +3     
+ Misses          2371     2368       -3     
  Partials           5        5              

☔ 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.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Apr 10, 2025
@Miles-hxy Miles-hxy changed the title fix: image的style覆盖className fix(imgage): 组件内部的style处理覆盖className Apr 10, 2025
@Miles-hxy Miles-hxy requested a review from oasis-cloud April 10, 2025 04:01
@Miles-hxy Miles-hxy changed the title fix(imgage): 组件内部的style处理覆盖className fix(image): 组件内部的style处理覆盖className Apr 10, 2025
@Miles-hxy Miles-hxy changed the title fix(image): 组件内部的style处理覆盖className fix(image): 组件内部的style处理覆盖传入的className Apr 10, 2025
@github-actions github-actions bot added action:merge This PR has received sufficient approvals (2+ approvals) and is ready to merge and removed action:review This PR needs more reviews (less than 2 approvals) labels Apr 11, 2025
@oasis-cloud oasis-cloud merged commit d2b14a2 into jdf2e:feat_v3.x Apr 11, 2025
8 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jun 7, 2025
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:merge This PR has received sufficient approvals (2+ approvals) and is ready to merge size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants