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

feat(actionsheet): harmony cpp adaption #2796

Open
wants to merge 5 commits into
base: feat_v3.x
Choose a base branch
from

Conversation

Alex-huxiyang
Copy link
Collaborator

@Alex-huxiyang Alex-huxiyang commented Nov 25, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • 多个组件(如 Icon、Tabbar、Checkbox 等)版本更新至 3.0.0,可能带来功能增强。
    • CountDown 组件新增属性 "v14": true,可能引入特定功能。
  • 样式

    • 更新了 Actionsheet 组件的样式,增强了元素状态的一致性和可读性。
    • Popup 组件的样式进行了条件调整,以适应不同平台(React Native 与非 React Native)的需求。
  • 测试

    • 更新了 Actionsheet 组件的测试用例,增强了类名验证的准确性。

Copy link

coderabbitai bot commented Nov 25, 2024

Walkthrough

此次更改主要集中在多个组件的版本升级和样式调整上。src/config.json文件中的多个组件版本从2.0.0更新至3.0.0,并且CountDown组件新增了属性"v14": true。此外,actionsheet.scssactionsheet相关文件的样式和类名结构也进行了优化,提升了代码的可读性和一致性。多个演示文件中的组件结构进行了小幅调整,以适应新的样式和功能需求。

Changes

文件路径 更改摘要
src/config.json 版本更新:多个组件(Icon, Tabbar, TabbarItem, Checkbox, CheckboxGroup, Rate, ActionSheet, Dialog, AnimatingNumbers, ImagePreview, Video)从2.0.0更新至3.0.0CountDown新增属性"v14": true
src/packages/actionsheet/actionsheet.scss 新增类选择器.nut-actionsheet-item-name;更新.nut-actionsheet-item-description的样式;类选择器.danger.disabled的语法更改。
src/packages/actionsheet/actionsheet.taro.tsx 引入statusClass变量以简化类名逻辑,改进了项的类名处理。
src/packages/actionsheet/actionsheet.tsx 引入statusClass变量以简化类名逻辑,改进了项的类名处理。
src/packages/actionsheet/demos/taro/demo1.tsx 新增pxTransform导入;将<span>替换为<View>;更新样式以使用pxTransform
src/packages/actionsheet/demos/taro/demo2.tsx 新增pxTransform导入;将文本包裹在<View>中,更新样式以使用pxTransform
src/packages/actionsheet/demos/taro/demo3.tsx 新增pxTransform导入;将文本包裹在<View>中,更新样式以使用pxTransform
src/packages/actionsheet/demos/taro/demo4.tsx 新增View导入;将文本从<span>更改为<View>
src/packages/actionsheet/demos/taro/demo5.tsx 新增CSSProperties导入,定义viewStyle常量,替换内联样式。
src/packages/actionsheet/demos/taro/demo6.tsx 新增View导入;将文本从<span>更改为<View>
src/packages/popup/popup.scss 根据平台条件更新样式,调整.nut-popup和相关类的positionheight属性。
src/packages/actionsheet/__test__/actionsheet.spec.tsx 更新测试用例以检查更具体的类名组合,增强测试的准确性。

Possibly related PRs

Suggested labels

size/M

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

🧹 Outside diff range and nitpick comments (14)
src/packages/actionsheet/demos/taro/demo4.tsx (1)

20-20: 组件替换实现恰当!

将 span 替换为 View 组件:

  • 符合 Taro 框架的最佳实践
  • 与其他 demo 文件保持一致
  • 有助于提高组件在不同平台的兼容性
src/packages/actionsheet/demos/taro/demo6.tsx (1)

25-25: 组件替换优化得当!

将 span 替换为 View 组件是很好的改进:

  • 符合 Taro 的跨平台组件规范
  • 与其他 demo 文件保持一致
  • 提升了组件在不同平台上的兼容性
src/packages/actionsheet/demos/taro/demo5.tsx (3)

1-1: 导入声明优化建议

引入 pxTransform 工具函数有助于实现响应式布局,这是一个很好的改进。建议考虑将所有工具函数的导入统一放在第三方库导入之后,以保持代码组织的一致性。

import React, { CSSProperties, useState } from 'react'
import { ActionSheet, Cell } from '@nutui/nutui-react-taro'
import { View } from '@tarojs/components'
+
import pxTransform from '@/utils/px-transform'

Also applies to: 4-4


8-12: 样式集中管理的改进

将样式对象集中定义是一个很好的实践,提高了代码的可维护性。建议考虑以下优化:

  1. 使用更具描述性的变量名,如 contentStyle 替代 viewStyle
  2. 考虑将这些样式提取到单独的样式文件中,特别是如果这些样式会在其他组件中复用
-const viewStyle: CSSProperties = {
+const contentStyle: CSSProperties = {
  textAlign: 'left',
  paddingLeft: pxTransform(20),
  paddingTop: pxTransform(10),
}

16-16: 组件结构优化

span 替换为 View 组件,并统一使用样式对象是正确的改进方向。不过建议添加适当的注释来解释这些选项的用途。

-<View>自定义内容</View>
+<View>
+  {/* 点击展示自定义内容面板 */}
+  自定义内容
+</View>

-<View style={viewStyle}>新建表格</View>
-<View style={viewStyle}>新建文档</View>
+{/* 自定义面板选项 */}
+<View style={contentStyle}>新建表格</View>
+<View style={contentStyle}>新建文档</View>

Also applies to: 26-27

src/packages/actionsheet/demos/taro/demo1.tsx (1)

29-32: 建议统一使用 Taro 的样式单位

代码结构清晰,使用 View 组件替换 span 是正确的做法。不过建议将内联样式抽离为独立的样式类,以提高代码的可维护性。

建议改为:

+import styles from './demo1.module.scss'
// ...
-<View style={{ marginLeft: pxTransform(10), color: '#999' }}>
+<View className={styles.valueText}>
   {val}
 </View>

然后在 demo1.module.scss 中:

.valueText {
  margin-left: 10px;
  color: #999;
}
src/packages/actionsheet/demos/taro/demo2.tsx (2)

27-27: 建议添加语义化的类名

为了提高代码的可维护性和样式的重用性,建议为 View 组件添加具有语义的类名。

-<View>展示取消按钮</View>
+<View className="demo-label">展示取消按钮</View>

28-30: 建议将内联样式迁移到样式文件中

当前的内联样式可以移至独立的样式文件中,以提高代码的可维护性和重用性。

建议创建样式文件并应用如下更改:

-<View style={{ marginLeft: pxTransform(10), color: '#999' }}>
+<View className="demo-value">
  {val}
</View>

创建对应的样式文件 demo2.scss

.demo-value {
  margin-left: pxTransform(10);
  color: #999;
}
src/packages/actionsheet/demos/taro/demo3.tsx (1)

28-31: 优化视图结构和样式处理

将 span 元素替换为 View 组件,并使用 pxTransform 处理边距,这些改动都符合 Taro 框架的最佳实践。建议考虑以下优化:

  1. 可以将样式抽取到独立的样式文件中
  2. 考虑使用 Taro 的主题变量来处理颜色值

建议这样重构:

-        <View style={{ marginLeft: pxTransform(10), color: '#999' }}>
+        <View className='demo3-value'>

然后在样式文件中添加:

.demo3-value {
  margin-left: var(--nutui-margin-xs);
  color: var(--nutui-gray-6);
}
src/packages/actionsheet/actionsheet.scss (2)

32-37: 建议优化样式继承结构

当前 item-name 类中的样式属性与父级完全相同。建议移除重复的样式定义,直接继承父级样式。

建议修改如下:

    &-name {
-      text-align: $actionsheet-item-text-align;
-      line-height: $actionsheet-item-line-height;
-      font-size: $font-size-base;
-      color: $actionsheet-item-color;
    }

46-52: 类名修改符合 BEM 规范

将状态类从 &.danger&.disabled 改为 &-danger&-disabled 的修改符合 BEM 命名规范,提高了代码的可维护性。

不过建议考虑添加注释说明这些状态类的具体用途:

+    // 危险状态,用于展示删除等危险操作
    &-danger {
      color: $actionsheet-item-danger;
    }

+    // 禁用状态,用于无法点击的选项
    &-disabled {
      color: $color-text-disabled !important;
      cursor: not-allowed;
    }
src/packages/actionsheet/actionsheet.tsx (1)

85-90: 建议优化类名的层级结构

目前 statusClass 被重复应用到了父元素和子元素上,这可能会导致:

  • CSS 选择器的重复
  • 样式继承的混乱
  • 不必要的 DOM 属性

建议将状态类名只应用于父元素,然后通过 CSS 选择器控制子元素样式:

-<div className={`${classPrefix}-item-name ${statusClass}`}>
+<div className={`${classPrefix}-item-name`}>
   {item[optionKey.name]}
 </div>
-<div className={`${classPrefix}-item-description ${statusClass}`}>
+<div className={`${classPrefix}-item-description`}>
   {item[optionKey.description]}
 </div>

然后在 SCSS 中使用嵌套选择器:

.nut-actionsheet-item {
  &.nut-actionsheet-item-disabled {
    .nut-actionsheet-item-name,
    .nut-actionsheet-item-description {
      // disabled styles
    }
  }
  
  &.nut-actionsheet-item-danger {
    .nut-actionsheet-item-name,
    .nut-actionsheet-item-description {
      // danger styles
    }
  }
}
src/packages/actionsheet/actionsheet.taro.tsx (1)

82-82: 建议使用 classnames 库来处理类名组合

当前的类名组合方式虽然可行,但使用 classnames 库可以让代码更加简洁和健壮。

建议这样重构:

- className={`${classPrefix}-item ${statusClass}`}
+ className={classNames(`${classPrefix}-item`, statusClass)}

需要先引入:

import classNames from 'classnames';
src/config.json (1)

Line range hint 1-1199: 建议完善组件文档

配置文件中的多个组件进行了版本升级,建议:

  1. 更新每个升级组件的使用文档
  2. 补充新版本的示例代码
  3. 确保文档中的版本号与配置文件保持一致
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9332996 and 8f31029.

📒 Files selected for processing (11)
  • src/config.json (11 hunks)
  • src/packages/actionsheet/actionsheet.scss (1 hunks)
  • src/packages/actionsheet/actionsheet.taro.tsx (1 hunks)
  • src/packages/actionsheet/actionsheet.tsx (1 hunks)
  • src/packages/actionsheet/demos/taro/demo1.tsx (2 hunks)
  • src/packages/actionsheet/demos/taro/demo2.tsx (2 hunks)
  • src/packages/actionsheet/demos/taro/demo3.tsx (2 hunks)
  • src/packages/actionsheet/demos/taro/demo4.tsx (2 hunks)
  • src/packages/actionsheet/demos/taro/demo5.tsx (2 hunks)
  • src/packages/actionsheet/demos/taro/demo6.tsx (2 hunks)
  • src/packages/popup/popup.scss (0 hunks)
💤 Files with no reviewable changes (1)
  • src/packages/popup/popup.scss
🔇 Additional comments (10)
src/packages/actionsheet/demos/taro/demo4.tsx (1)

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

从 @tarojs/components 导入 View 组件符合 Taro 开发规范。

src/packages/actionsheet/demos/taro/demo6.tsx (1)

3-3: 导入变更符合 Taro 最佳实践!

从 @tarojs/components 导入 View 组件是符合 Taro 跨平台开发规范的做法。

src/packages/actionsheet/demos/taro/demo1.tsx (1)

4-4: 导入 pxTransform 工具函数符合 Taro 开发规范

引入 pxTransform 用于像素值转换是符合 Taro 最佳实践的做法,可以确保在不同设备上具有一致的显示效果。

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

4-4: 导入 pxTransform 工具函数符合最佳实践!

引入 pxTransform 工具函数有助于确保在不同设备上保持一致的像素单位转换。

src/packages/actionsheet/demos/taro/demo3.tsx (1)

4-4: 导入 pxTransform 工具函数以统一像素处理

引入 pxTransform 工具函数有助于在不同设备上保持一致的像素单位转换,这是一个很好的改进。

src/packages/actionsheet/actionsheet.scss (1)

42-43: 样式对齐优化符合预期

为描述文本添加的文本对齐和行高属性有助于保持组件的视觉一致性,这是个不错的改进。

src/packages/actionsheet/actionsheet.tsx (1)

78-78: 代码重构提高了可读性!

将状态类名的逻辑抽取到 statusClass 变量中是个很好的改进,这样可以:

  • 减少代码重复
  • 提高可维护性
  • 使状态类名的应用更加统一

Also applies to: 81-81

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

79-79: 代码重构改进了可读性!

将状态类名的逻辑整合到 statusClass 变量中是个很好的改进,使代码更加清晰和易于维护。

src/config.json (2)

108-108: 请验证组件版本升级的兼容性

多个组件从 2.0.0 升级到 3.0.0 版本,这是一个重大版本升级。建议:

  1. 确保所有升级组件的 breaking changes 已在迁移指南中说明
  2. 验证依赖这些组件的上层组件是否需要适配

Also applies to: 356-356, 367-367, 462-462, 473-473, 624-624, 708-708, 730-730, 905-905, 1005-1005

✅ Verification successful

Let me analyze the migration guide to understand the breaking changes. Let me generate a script to check the content.


根据迁移指南的内容,我可以生成最终的响应了。

组件版本升级已有明确的迁移指南

迁移指南中已详细说明了从 2.x 到 3.0.0 版本的所有变更:

  • 所有组件的 breaking changes 都有清晰的文档说明
  • 提供了 codemod 工具 @nutui/nutui-react-codemod 协助自动化升级
  • 主题变量命名规范化,如 primary-color 更名为 color-primary

建议:

  1. 使用 codemod 工具进行自动化升级
  2. 对照迁移指南检查每个组件的变更
  3. 特别注意配置文件中涉及的组件属性名变更
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否存在迁移指南文档
fd -t f "migrate.*md|upgrade.*md|migration.*md" 

# 搜索这些组件的使用情况
rg -l "Icon|Tabbar|TabbarItem|Checkbox|CheckboxGroup|Rate|ActionSheet|Dialog|AnimatingNumbers|ImagePreview"

Length of output: 20418


Script:

#!/bin/bash
# Check migration guide content for version 3.0.0 changes
cat migrate-from-v2.md

Length of output: 25470


990-991: 验证 CountDown 组件的 v14 标记

CountDown 组件新增了 "v14": true 属性,需要确认:

  1. v14 版本的功能特性是否已完整实现
  2. 是否需要在文档中说明 v14 版本的使用注意事项

src/packages/actionsheet/actionsheet.taro.tsx Show resolved Hide resolved
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.99%. Comparing base (9332996) to head (476fd36).

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2796   +/-   ##
==========================================
  Coverage      83.99%   83.99%           
==========================================
  Files            220      220           
  Lines          17885    17887    +2     
  Branches        2679     2678    -1     
==========================================
+ Hits           15023    15025    +2     
  Misses          2857     2857           
  Partials           5        5           

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

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/actionsheet/__test__/actionsheet.spec.tsx (2)

66-68: 类名断言更新符合新的命名规范

类名断言的更新与组件样式重构保持一致,采用了更规范的 BEM 命名方式。建议同时添加一个测试用例,验证当 danger 属性为 false 时不应该包含 nut-actionsheet-item-danger 类。


106-108: 禁用状态类名断言更新合理

类名更新保持了与危险状态相同的命名模式,有助于保持一致性。建议补充测试用例验证:

  1. 多个状态同时存在时的类名组合(如同时禁用且危险)
  2. 状态切换时类名的变化
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8f31029 and 9e84df7.

📒 Files selected for processing (1)
  • src/packages/actionsheet/__test__/actionsheet.spec.tsx (2 hunks)

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

1 participant