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

fix(radio): color of icon #2768

Closed
wants to merge 1 commit into from

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Nov 19, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新特性

    • 更新了单选按钮的视觉表现,根据状态和平台能力应用不同的颜色样式。
    • 增强了水平布局的单选组,使其子元素能够灵活排列。
  • 样式

    • 为水平单选组添加了 display: flex; 属性,优化了布局行为。

Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

该拉取请求对src/packages/radio/radio.taro.tsx中的Radio组件进行了多项修改,新增了从@/utils/platform-taro导入的harmonyrenderIcon函数根据harmony()的结果有条件地应用颜色样式,增强了单选按钮在不同状态下的视觉表现。同时,src/packages/radiogroup/radiogroup.scss文件中对.nut-radiogroup类添加了display: flex;属性,以改善水平布局的表现。

Changes

文件路径 修改摘要
src/packages/radio/radio.taro.tsx 新增import { harmony } from '@/utils/platform-taro',更新renderIcon函数以根据状态应用颜色样式。修改CheckDisabledCheckCheckedCheckNormal组件以接收颜色样式作为props。
src/packages/radiogroup/radiogroup.scss .nut-radiogroup类的&-horizontal修饰符下添加display: flex;属性,以改善水平布局。

Possibly related PRs

  • fix(radio): lint fixed #2635: 此PR修改了Radio组件,与本PR中对src/packages/radio/radio.taro.tsx的更改直接相关。
  • feat: radio adaptation #2721: 此PR处理了Radio组件的适配,与本PR中增强单选按钮视觉表现的更改一致。
  • fix: radio type #2735: 此PR涉及对Radio组件的修改,特别是移除了Radio.Group导出,与本PR中关于Radio组件功能的更改相关。

Suggested labels

size/M, 3.x

Poem

在兔子窝里欢声笑,
单选按钮色彩妙。
灵动布局如春风,
轻松选择乐无穷。
兔子跳跃心欢畅,
新功能来真是棒! 🐇✨


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.

@github-actions github-actions bot added the 3.x label Nov 19, 2024
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (6213d88) to head (69ce5fc).

Additional details and impacted files
@@           Coverage Diff           @@
##             V3.0    #2768   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         221      221           
  Lines       17879    17879           
  Branches     2676     2676           
=======================================
  Hits        15016    15016           
  Misses       2858     2858           
  Partials        5        5           

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


🚨 Try these New Features:

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

🧹 Outside diff range and nitpick comments (2)
src/packages/radiogroup/radiogroup.scss (1)

33-34: 建议在组件文档中说明布局行为

为了帮助其他开发者理解组件的行为,建议在组件文档中说明水平布局使用了 flex 布局。

src/packages/radio/radio.taro.tsx (1)

93-94: 建议将颜色值提取为常量

为了提高可维护性和一致性,建议将颜色值 #c2c4cc 提取为组件级或主题级的常量。

+const DISABLED_COLOR = '#c2c4cc'
+
 const renderIcon = () => {
   if (disabled && !checkedStatement) {
-    const colors = harmony() ? { color: '#c2c4cc' } : {}
+    const colors = harmony() ? { color: DISABLED_COLOR } : {}
     return <CheckDisabled className={classNames(color())} {...colors} />
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6213d88 and 69ce5fc.

📒 Files selected for processing (2)
  • src/packages/radio/radio.taro.tsx (2 hunks)
  • src/packages/radiogroup/radiogroup.scss (1 hunks)
🔇 Additional comments (3)
src/packages/radiogroup/radiogroup.scss (1)

33-34: 布局更改看起来合理!

添加 display: flex 有助于改善水平布局的对齐方式。建议在不同屏幕尺寸下测试此更改,以确保布局行为符合预期。

✅ Verification successful

布局更改已验证安全

经过验证,添加 display: flex 的更改是安全的:

  • 该更改仅影响 .nut-radiogroup-horizontal 的直接布局
  • 现有的子元素已经使用 display: inline-flex,与新增的 flex 布局完全兼容
  • RTL(从右到左)支持也已经正确处理
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否有其他组件依赖于 radio 组件的布局行为
rg -l "nut-radiogroup-horizontal" 

Length of output: 80


Script:

#!/bin/bash
# 检查 radiogroup.harmony.css 中的相关样式
cat src/packages/radiogroup/radiogroup.harmony.css

# 搜索其他可能使用 radiogroup 的组件
rg -l "nut-radiogroup"

# 检查是否有测试用例涉及水平布局
rg "horizontal" src/packages/radiogroup/

Length of output: 1802

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

13-13: 导入语句正确添加!

从平台工具中导入 harmony 函数用于处理不同平台的颜色样式,符合代码组织规范。


110-118: 请验证颜色值的一致性

注意到正常状态和禁用状态使用了相同的灰色值 (#c2c4cc),请确认这是否符合设计规范。同时建议检查这些颜色值是否与设计系统中的其他组件保持一致。

✅ Verification successful

颜色值使用符合设计规范

根据搜索结果,#c2c4cc 是设计系统中定义的灰色变量 $color-text-disabled$color-border-disabled,用于禁用状态的文本和边框颜色。这个颜色值在多个组件中都有一致的使用。

理由:

  1. src/styles/variables.scss 中明确定义了这个颜色值用于禁用状态
  2. Radio 组件中使用该颜色值来表示禁用状态是符合设计规范的
  3. 该颜色值在整个组件库中被一致使用,包括 Button、Input、Checkbox 等组件的禁用状态
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索代码库中其他组件使用的颜色值,以确保一致性
rg -i '#c2c4cc|#ffadbe|#ff0f23' --type tsx --type scss

Length of output: 84


Script:

#!/bin/bash
# 搜索所有文件中的颜色值
rg -i '#c2c4cc|#ffadbe|#ff0f23'

# 搜索颜色相关的常量或变量定义
ast-grep --pattern 'const $_ = { color: $_ }'

# 搜索颜色主题或变量定义文件
fd -e ts -e tsx -e scss -e css -e less | grep -i "color\|theme\|style"

Length of output: 166663

Comment on lines +97 to +107
const colors = harmony()
? { color: disabled ? '#ffadbe' : '#ff0f23' }
: {}
return React.isValidElement(activeIcon) ? (
React.cloneElement<any>(activeIcon, {
...activeIcon.props,
className: classNames(color()),
...colors,
})
) : (
<CheckChecked className={classNames(color())} />
<CheckChecked className={classNames(color())} {...colors} />
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议优化选中状态的颜色处理逻辑

当前代码在多处重复处理颜色逻辑,建议将颜色计算逻辑提取到单独的函数中,以提高代码的可维护性和复用性。

+const getCheckedStateColors = (disabled: boolean) => {
+  if (!harmony()) return {}
+  return {
+    color: disabled ? '#ffadbe' : '#ff0f23'
+  }
+}

 if (checkedStatement) {
-  const colors = harmony()
-    ? { color: disabled ? '#ffadbe' : '#ff0f23' }
-    : {}
+  const colors = getCheckedStateColors(disabled)
   return React.isValidElement(activeIcon) ? (
     React.cloneElement<any>(activeIcon, {
       ...activeIcon.props,
       className: classNames(color()),
       ...colors,
     })
   ) : (
     <CheckChecked className={classNames(color())} {...colors} />
   )
 }

Committable suggestion skipped: line range outside the PR's diff.

@oasis-cloud oasis-cloud changed the title feat(radio): fix color of icon fix(radio): color of icon Nov 19, 2024
@xiaoyatong
Copy link
Collaborator

已支持了,无需再做。关了~

@xiaoyatong xiaoyatong closed this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants