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(rate): 多端适配 #2754

Merged
merged 8 commits into from
Nov 20, 2024
Merged

fix(rate): 多端适配 #2754

merged 8 commits into from
Nov 20, 2024

Conversation

irisSong
Copy link
Collaborator

@irisSong irisSong commented Nov 14, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新特性

    • 更新多个组件至版本 3.0.0,包括 RateCalendarCardInputSearchBar 等。
    • 在演示组件中新增并激活 Rate 组件。
  • 样式调整

    • 调整 .nut-rate-item.nut-rate-item-icon 的边距和颜色属性,优化了 RTL 布局。
  • 演示组件改进

    • 激活多个演示组件,并根据平台能力进行条件渲染。

Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

该拉取请求主要涉及对多个组件版本的更新和相关演示组件的调整。src/config.json 文件中,多个组件的版本被更新至 3.0.0,并将 TimeDetail 组件标记为 exportEmpty: true。在 src/packages/rate/demo.taro.tsx 文件中,演示组件的导入和渲染逻辑进行了修改,激活了之前注释掉的演示组件,并根据平台能力进行了条件渲染。CSS 和 SCSS 文件对布局和样式进行了相应的调整,特别是在 RTL 方向的支持上。

Changes

文件路径 变更摘要
src/config.json 更新多个组件版本至 3.0.0,并将 TimeDetail 标记为 exportEmpty: true
src/packages/rate/demo.taro.tsx 激活之前注释的演示组件,添加条件渲染逻辑,调整组件导入。
src/packages/rate/rate.harmony.css 修改 .nut-rate-item.nut-rate-item-icon 的样式,更新 RTL 样式。
src/packages/rate/rate.scss 调整 .nut-rate-item 的边距和图标颜色样式,更新 RTL 样式。
src/packages/configprovider/demos/taro/demo1.tsx 激活 Rate 组件的导入和渲染。
src/packages/configprovider/demos/taro/demo2.tsx 激活 Rate 组件的导入和渲染。

Possibly related PRs

Suggested reviewers

  • oasis-cloud

🐇 在草地上跳跃,版本更新来临,
新的组件闪耀,演示更生动鲜明。
样式调整如春风,布局更为精致,
让我们欢庆这些变化,兔子们一起欢笑不停! 🌼✨


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

🧹 Outside diff range and nitpick comments (4)
src/packages/rate/rate.scss (1)

44-51: 嵌套结构优化了样式组织

将颜色属性移至 .nut-icon 嵌套选择器中是个很好的改进,提高了样式的可维护性和模块化程度。不过建议考虑添加相关注释说明样式的用途。

建议添加如下注释:

 &-icon {
   display: flex;
   cursor: pointer;

+  // 图标默认颜色
   .nut-icon {
     color: $rate-icon-color;
   }

   &-disabled {
+    // 禁用状态图标颜色
     .nut-icon {
       color: $rate-icon-inactive-color;
     }
   }
src/packages/rate/rate.harmony.css (1)

35-39: 建议优化图标颜色的设置方式

当前的颜色值是直接硬编码的。建议将这些颜色值抽取为CSS变量,以便于主题定制和维护。

建议修改如下:

+:root {
+  --nut-rate-active-color: #ff0f23;
+  --nut-rate-disabled-color: #c2c4cc;
+}
 .nut-rate-item-icon .nut-icon {
-  color: #ff0f23;
+  color: var(--nut-rate-active-color);
 }
 .nut-rate-item-icon-disabled .nut-icon {
-  color: #c2c4cc;
+  color: var(--nut-rate-disabled-color);
 }
src/packages/rate/demo.taro.tsx (1)

124-136: 建议添加平台特定功能的说明文档

Demo11 和 Demo12 是基于平台能力进行条件渲染的,建议在代码中添加注释说明为什么这些触摸事件演示组件只在特定平台下显示。

+        {/* 触摸事件相关演示仅在非鸿蒙平台显示 */}
         {harmony() ? null : (
src/config.json (1)

Line range hint 1-1127: 建议更新组件文档以反映多端适配支持

多个组件升级到了 3.0.0 版本,包括:

  • CalendarCard
  • Input
  • InputNumber
  • SearchBar
  • Switch
  • TextArea
  • Video
  • Radio
  • RadioGroup

建议在组件文档中明确说明多端适配支持情况。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9d0b4b2 and a534a5e.

📒 Files selected for processing (4)
  • src/config.json (1 hunks)
  • src/packages/rate/demo.taro.tsx (3 hunks)
  • src/packages/rate/rate.harmony.css (2 hunks)
  • src/packages/rate/rate.scss (2 hunks)
🔇 Additional comments (7)
src/packages/rate/rate.scss (1)

21-24: 边距调整优化了 RTL 布局支持

边距方向的调整和选择器的更改使得组件在 RTL(从右到左)布局中能够更好地工作,同时保持了原有的视觉间距。这是一个很好的改进。

src/packages/rate/rate.harmony.css (2)

15-18: 边距调整逻辑更加合理

将右边距改为左边距,并使用:first-child选择器处理第一个元素的边距,这样的调整更符合从左到右的布局逻辑。


Line range hint 53-77: RTL支持实现完善

RTL(从右到左)布局的支持非常全面,同时使用了[dir=rtl]属性选择器和.nut-rtl类选择器,确保了最大的兼容性。边距和定位的调整也很合理。

src/packages/rate/demo.taro.tsx (3)

7-19: 导入语句结构清晰,符合要求!

所有的演示组件导入都已激活使用,代码组织合理。


124-124: 验证 harmony() 函数的返回值是否符合预期

建议验证 harmony() 函数在不同平台环境下的行为是否正确。

#!/bin/bash
# 检查 harmony 函数的实现和使用情况
echo "检查 harmony 函数实现:"
rg "harmony.*=.*\(\).*=>" ./src/utils/

echo "\n检查 harmony 函数的调用位置:"
rg "harmony\(\)" ./src/packages/

77-79: 请确认图标相关问题是否已解决

之前的 TODO 注释提到存在图标问题,现在直接渲染 Demo1。建议验证图标显示是否正常。

✅ Verification successful

Let me gather more information about Demo1 and icon implementation.


Let me check the Demo1 implementation to verify the icon usage:


图标问题已得到解决

基于代码验证结果:

  • Rate 组件已正确集成了图标功能,使用 StarFill 作为默认图标
  • Demo1 实现简洁清晰,使用默认图标且运行正常
  • 未发现任何与图标相关的遗留问题或 TODO 注释
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否存在未解决的图标相关问题
rg -i "icon.*?(issue|todo|fix)" ./src/packages/rate/

Length of output: 1554


Script:

#!/bin/bash
# Check Demo1 implementation and icon usage
echo "Checking Demo1 implementation:"
rg -A 10 "Demo1" ./src/packages/rate/demo.taro.tsx

echo -e "\nChecking icon related code in Rate component:"
rg -i "icon" ./src/packages/rate/rate.taro.tsx

Length of output: 2412


Script:

#!/bin/bash
# Check Demo1 implementation details
echo "Checking Demo1 implementation:"
cat ./src/packages/rate/demos/taro/demo1.tsx

echo -e "\nChecking if there are any icon related issues in demo files:"
rg -i "icon.*?(issue|todo|fix)" ./src/packages/rate/demos/

Length of output: 469

src/config.json (1)

Line range hint 624-633: 组件版本升级可能带来重大变更

Rate 组件升级到 3.0.0 版本,这是一个主版本更新。建议:

  1. 确保更新日志中记录了所有破坏性变更
  2. 验证使用 Rate 组件的页面是否需要适配
✅ Verification successful

Let me gather more information about the Rate component changes.


Let me check the specific changes in the Rate component implementation.


Rate 组件的重大变更已得到验证

根据代码变更和迁移指南的分析,Rate 组件的变更主要涉及:

  1. API 重命名:

    • minimizeValue 改为 min
    • readonly 改为 readOnly
    • modelValue 改为受控的 value 和非受控的 defaultValue
  2. 移除的属性:

    • spacing (改用 CSS 变量 --nutui-rate-item-margin)
    • activeColorvoidColoriconSize (改用 checkedIconuncheckedIcon 实现)

这些变更都已在测试用例和文档中得到验证,且提供了明确的迁移方案。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 Rate 组件的使用情况

# 搜索 Rate 组件的使用
rg -l "Rate" --type tsx --type jsx

# 检查组件变更记录
if [ -f "CHANGELOG.md" ]; then
  rg "Rate" CHANGELOG.md
fi

Length of output: 145


Script:

#!/bin/bash
# Search for Rate component usage with ripgrep in all files
rg -l "Rate" 

# Check PR details for Rate component changes
gh pr view --json files

# Look for Rate component implementation files
fd -t f "rate" -i

# Check commit messages related to Rate
git log --grep="Rate"

Length of output: 3323


Script:

#!/bin/bash
# 检查 Rate 组件的具体改动
git show dabeea8b54c4ccbc666fd602c43f1f2b83792007

# 检查迁移指南中的相关说明
rg "Rate" migrate-from-v2.md -A 5 -B 5

# 查看组件测试文件的变化
cat src/packages/rate/__test__/rate.spec.tsx

Length of output: 61773

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (4b427a1) to head (3316fc9).
Report is 3 commits behind head on V3.0.

Additional details and impacted files
@@           Coverage Diff           @@
##             V3.0    #2754   +/-   ##
=======================================
  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
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

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

另外 configprovider 和 form 里是不是都有用到 rate,可以同步改下

@@ -18,10 +18,10 @@
display: flex;
flex-shrink: 0;
position: relative;
margin-right: $rate-item-margin;
margin-left: $rate-item-margin;
Copy link
Collaborator

Choose a reason for hiding this comment

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

很神奇的改动~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

configprovider 已修改

@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 20, 2024
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

🧹 Outside diff range and nitpick comments (2)
src/packages/configprovider/demos/taro/demo1.tsx (1)

9-11: 建议增强 Rate 组件的演示效果

当前的 Rate 组件实现过于简单,建议添加更多的属性演示,以便更好地展示组件的功能。

建议按照以下方式增强演示:

 <Cell>
-  <Rate defaultValue={3} />
+  <Rate
+    defaultValue={3}
+    count={5}
+    onChange={(val) => console.log('当前值:', val)}
+    size={18}
+    activeColor="#fa2c19"
+  />
 </Cell>
src/packages/configprovider/demos/taro/demo2.tsx (1)

14-16: 建议增加无障碍支持

为了提高组件的可访问性,建议添加 aria-label 属性来描述评分组件的用途。

建议按照以下方式修改代码:

  <Cell>
-   <Rate defaultValue={3} />
+   <Rate defaultValue={3} aria-label="评分" />
  </Cell>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 18a06ee and 3316fc9.

📒 Files selected for processing (2)
  • src/packages/configprovider/demos/taro/demo1.tsx (1 hunks)
  • src/packages/configprovider/demos/taro/demo2.tsx (2 hunks)
🔇 Additional comments (3)
src/packages/configprovider/demos/taro/demo1.tsx (2)

2-2: 导入语句整合得当

导入语句简洁明了,将相关组件统一从 @nutui/nutui-react-taro 包中导入。


Line range hint 1-24: 验证组件版本兼容性

根据变更记录,Rate 组件已升级到 3.0.0 版本,需要确保当前实现与新版本的 API 完全兼容。

✅ Verification successful

Let me gather more information about the Rate component's API by checking its documentation and implementation.


Rate 组件 API 验证通过

根据文档和示例代码验证,当前实现中使用的 defaultValue 属性是完全兼容的,且用法正确。Rate 组件的核心 API 保持稳定,没有发生破坏性变更。ConfigProvider 中的使用方式符合组件设计规范。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 Rate 组件的版本和 API 变更

# 检查 package.json 中的版本
echo "检查 nutui-react-taro 包版本:"
cat package.json | jq '.dependencies["@nutui/nutui-react-taro"]'

# 搜索其他使用 Rate 组件的示例
echo "搜索其他 Rate 组件用例:"
rg -l "import.*Rate.*from.*@nutui/nutui-react-taro"

Length of output: 824


Script:

#!/bin/bash
# 检查 Rate 组件的文档和实现

# 查看 Rate 组件的文档
echo "Rate 组件文档内容:"
cat src/packages/rate/doc.taro.md

# 查看 Rate 组件的其他示例用法
echo -e "\nRate 组件示例用法:"
cat src/packages/rate/demos/taro/demo1.tsx

Length of output: 2261

src/packages/configprovider/demos/taro/demo2.tsx (1)

2-2: 导入声明看起来不错!

导入声明简洁明了,遵循了最佳实践。

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

🧹 Outside diff range and nitpick comments (1)
src/packages/configprovider/demos/taro/demo2.tsx (1)

14-16: 建议增强Rate组件的实现

当前实现可以考虑添加以下改进:

  1. 添加错误处理和输入验证
  2. 考虑增加无障碍支持(aria标签)
  3. 建议添加onChange事件处理

建议按照以下方式优化代码:

 <Cell>
-  <Rate defaultValue={3} />
+  <Rate
+    defaultValue={3}
+    onChange={(val) => console.log('当前值:', val)}
+    aria-label="评分"
+    min={0}
+    max={5}
+  />
 </Cell>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 18a06ee and 3316fc9.

📒 Files selected for processing (2)
  • src/packages/configprovider/demos/taro/demo1.tsx (1 hunks)
  • src/packages/configprovider/demos/taro/demo2.tsx (2 hunks)
🔇 Additional comments (4)
src/packages/configprovider/demos/taro/demo1.tsx (2)

2-2: 导入声明看起来不错!

导入声明简洁明了,遵循了最佳实践。


9-11: 请确认移除平台特定渲染的影响

之前的代码中包含了平台特定的条件渲染(harmonyAndRn 检查)。请确认在所有支持的平台上 Rate 组件都能正常工作。

运行以下脚本来检查其他相关组件的平台适配实现:

✅ Verification successful

Let me analyze the Rate component's platform-specific behavior by checking its implementation.


根据代码分析,我可以生成最终响应了。

Rate 组件在所有平台上都可以正常工作

Rate 组件的实现中没有使用 harmonyAndRn 进行平台特定的渲染逻辑。组件的核心功能(评分、半星、禁用等)在所有平台上都使用相同的实现。唯一的平台差异是在 demo 展示页面中对触摸特性的展示,这不影响组件本身的功能。

移除原有的平台检查是安全的,不会影响组件在任何平台上的正常使用。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查其他组件中的平台特定渲染逻辑

# 搜索其他使用 harmonyAndRn 的组件
rg -A 3 "harmonyAndRn"

# 搜索 Rate 组件在其他演示文件中的使用方式
fd -e tsx -e ts "demo.*\.tsx?$" | xargs rg -l "Rate.*defaultValue"

Length of output: 41633


Script:

#!/bin/bash
# Check Rate component implementation for platform-specific code
ast-grep --pattern 'class Rate {
  $$$
}'

# Search for platform checks in Rate component
rg -A 3 "harmonyAndRn|harmony|rn" "src/packages/rate/"

Length of output: 10561

src/packages/configprovider/demos/taro/demo2.tsx (2)

2-2: 导入声明看起来不错!

导入语句简洁明了,遵循了最佳实践。


Line range hint 1-24: 验证组件在不同端的兼容性

由于这是多端适配相关的改动,建议验证Rate组件在不同端(Web、小程序等)的表现是否一致。

✅ Verification successful

Rate组件在多端表现一致,无需额外适配

基于代码分析结果,Rate组件在多端实现上是兼容的:

  1. 组件在H5和Taro端都有对应的demo实现,功能表现一致
  2. 样式文件(rate.scss)采用统一的样式定义,确保了跨端的一致性
  3. 组件支持触摸事件(touch-action)和RTL布局,保证了在不同场景下的正常使用

因此该组件在ConfigProvider的使用场景下是安全的,不需要进行额外的端适配工作。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查Rate组件在不同端的实现差异

# 搜索Rate组件相关的平台特定代码
rg -t tsx -t ts "Rate" src/packages/rate/

# 检查是否存在平台特定的样式
rg -t scss "rate" src/packages/rate/

Length of output: 135


Script:

#!/bin/bash
# 搜索Rate组件相关的代码实现
rg "Rate" --type-add 'web:*.{tsx,ts,jsx,js}' --type web src/

# 搜索Rate组件的样式文件
fd -e scss -e css . src/ --exec grep -l "rate"

# 查找可能的平台特定实现
rg "Rate.*\b(web|h5|taro|weapp|alipay)" --type-add 'web:*.{tsx,ts,jsx,js}' --type web src/

Length of output: 10935


Script:

#!/bin/bash
# 检查Rate组件在不同端的具体实现差异
diff <(cat src/packages/rate/rate.tsx) <(cat src/packages/rate/rate.taro.tsx) || true

# 检查样式文件中的差异
cat src/packages/rate/rate.scss

Length of output: 1763

@coderabbitai coderabbitai bot mentioned this pull request Dec 13, 2024
20 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 26, 2024
20 tasks
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