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: v15 popup #2844

Merged
merged 19 commits into from
Dec 24, 2024
Merged

feat: v15 popup #2844

merged 19 commits into from
Dec 24, 2024

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Dec 9, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新特性

    • 更新了多个组件的弹出框样式和功能,包括添加新状态变量和修改现有状态管理。
    • 新增居中弹出框功能,支持更灵活的布局。
    • 弹出框组件的标题和描述属性已更新,提升用户界面体验。
    • 弹出框的溢出行为已调整,改善内容展示。
    • 引入了版本更新属性,指示弹出框组件的新特性。
  • 样式

    • 调整了弹出框的样式变量,包括边框半径和字体大小,以提升视觉一致性。
    • 移除了多个组件的内联样式,允许更灵活的样式控制。
    • 增加了弹出框的最小高度和最大高度,改善布局表现。
    • 弹出框的滚动区域高度已调整,提升用户体验。
  • 文档

    • 更新了组件演示,反映了新的弹出框特性和样式变化。
  • 测试

    • 为弹出框组件新增了多项测试,增强功能覆盖率。
    • 更新了时间选择组件的测试,改进事件处理和交互测试。

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

此次更改主要集中在Popup组件及其相关演示组件的样式和功能上。Cascader组件添加了新的样式属性,以控制弹出层内容的溢出行为。多个演示组件的状态变量和标题进行了重命名和修改,同时引入了新的弹出层功能。整体上,组件的核心逻辑和事件处理保持不变,但样式和呈现方式有所调整。

Changes

文件路径 更改摘要
src/packages/cascader/cascader.taro.tsx 添加style={{ overflowY: 'hidden' }}Popup组件的样式属性。
src/packages/popup/demos/h5/demo1.tsx 组件重命名为Demo,状态变量showBasic改为showIcon,更新了Popup的多个属性。
src/packages/popup/demos/h5/demo2.tsx 添加新状态变量showText,并引入新的Cell组件和弹出层,简化了现有弹出层的样式。
src/packages/popup/demos/taro/demo1.tsx 组件重命名为Demo,状态变量showBasic改为showIcon,更新了Popup的多个属性,简化了内容。
src/packages/popup/demos/taro/demo2.tsx 添加新状态变量showText,引入新的Cell组件和弹出层,更新底部弹层的标题和样式。
src/packages/popup/demos/taro/demo8.tsx 更新Popuptitle属性为"禁止滚动穿透",并将ScrollView的高度从'200px'增加到'300px'。
src/packages/popup/popup.scss 调整.nut-popup及其子元素的样式,增加min-height,移除overflow-y属性,更新文本颜色等。
src/packages/popup/popup.taro.tsx 修改renderNode函数的渲染逻辑,简化了useEffect中的条件逻辑,保持其他功能不变。
src/packages/popup/popup.tsx 重构renderNode函数,简化useEffect逻辑,调整onHandleClickOverlayclose函数的逻辑。
src/packages/timeselect/demos/taro/demo1.tsx 移除TimeSelect组件的内联样式,影响其显示。
src/packages/timeselect/demos/taro/demo2.tsx 移除TimeSelect组件的内联样式,影响其显示。
src/packages/timeselect/demos/taro/demo3.tsx 移除TimeSelect组件的内联样式,影响其显示。
src/packages/timeselect/timeselect.taro.tsx 移除Popup组件的widthheight属性,保持逻辑不变。
src/packages/timeselect/timeselect.tsx 设置Popup组件的width为'100%'和height为'20%',保持逻辑不变。
src/styles/variables.scss 更新多个CSS变量的定义,特别是与弹出层相关的变量,调整边框半径和字体大小等。
src/packages/popup/demo.taro.tsx 简化ScrollView组件的className逻辑,始终包含demo类并根据环境条件添加web类。
src/packages/overlay/overlay.scss 移动.nut-overlay类的RTL样式到文件末尾,保持其他样式不变。
src/packages/popup/__tests__/popup.spec.tsx 添加多个新测试用例以增强Popup组件的测试覆盖率。
src/packages/address/address.tsx 简化renderLeftOnCustomSwitch函数的逻辑,直接返回JSX元素。
src/packages/address/__test__/address.spec.tsx 添加多个新测试用例以验证Address组件的渲染和交互。
src/packages/timeselect/__test__/timeselect.spec.tsx 更新测试以增强TimeSelect组件的测试能力,添加新的事件处理函数。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Demo
    participant Popup

    User->>Demo: Click to open popup
    Demo->>Popup: Set visible to true
    Popup-->>User: Display popup
    User->>Popup: Interact with popup
    Popup-->>Demo: Trigger onClose if necessary
Loading

Possibly related PRs

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 f2f8712 and 196d4a3.

📒 Files selected for processing (2)
  • src/config.json (1 hunks)
  • src/packages/popup/__tests__/popup.spec.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/popup/tests/popup.spec.tsx
🔇 Additional comments (1)
src/config.json (1)

857-857: 确认 v15 标记添加正确

Popup 组件添加 v15 标记符合预期。经过检查,其他具有 v15 标记的组件包括:

  • Grid (布局组件)
  • BackTop (导航组件)
  • Rate (数据录入)
  • Switch (数据录入)
  • Empty (操作反馈)
  • ResultPage (操作反馈)
  • CountDown (展示组件)
  • Pagination (展示组件)
  • Segmented (展示组件)
  • Toast (操作反馈)
✅ Verification successful

Let me get more context about the components to verify their categorization and ensure the v15 flag is consistently applied across related components.


v15 标记添加验证完成,确认符合预期

经过验证,Popup 组件添加 v15 标记是合理的。目前带有 v15 标记的组件包括:

  • Grid(宫格)- 布局组件
  • BackTop(返回顶部)- 导航组件
  • Rate(评分)- 数据录入
  • Switch(开关)- 数据录入
  • Empty(空状态)- 操作反馈
  • ResultPage(结果反馈)- 操作反馈
  • Popup(弹出层)- 操作反馈
  • Toast(吐司)- 操作反馈
  • CountDown(倒计时)- 展示组件
  • Pagination(分页)- 展示组件
  • Segmented(分段选择器)- 展示组件

所有组件都具有完整的中文名称、描述和分类,v15 标记使用统一且合理。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证所有带有 v15 标记的组件

# 搜索所有带有 v15 标记的组件配置
rg '"v15":\s*true' -A 5

Length of output: 2558


Script:

#!/bin/bash
# 获取更多上下文来确认组件类型和分类
rg -B 5 '"v15":\s*true' src/config.json

Length of output: 1769


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Dec 9, 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 (8)
src/packages/popup/demos/h5/demo1.tsx (1)

16-20: 建议优化弹出层标题和描述的可配置性

当前的标题和描述是硬编码的,建议考虑通过属性传递这些值,以提高组件的复用性。

const Demo = () => {
  const [showIcon, setShowIcon] = useState(false)
+ const popupConfig = {
+   title: "标题",
+   description: "这里是副标题这是副标题"
+ }

  return (
    <>
      <Cell
        title="基础弹框"
        onClick={() => setShowIcon(true)}
      />
      <Popup
        closeable
        visible={showIcon}
-       title="标题"
-       description="这里是副标题这是副标题"
+       title={popupConfig.title}
+       description={popupConfig.description}
        position="bottom"
        onClose={() => setShowIcon(false)}
      />
    </>
  )
}
src/packages/popup/demos/taro/demo1.tsx (1)

1-28: 建议重构以减少H5和Taro demo之间的代码重复

H5版本和Taro版本的demo代码几乎完全相同,建议考虑以下重构方案:

  1. 创建一个共享的基础组件
  2. 使用高阶组件或自定义hook处理平台特定的逻辑

建议的目录结构:

src/packages/popup/demos/
  ├── shared/
  │   └── BasicPopup.tsx    # 共享的基础组件
  ├── h5/
  │   └── demo1.tsx         # H5特定的包装器
  └── taro/
      └── demo1.tsx         # Taro特定的包装器
src/packages/popup/demos/taro/demo8.tsx (1)

Line range hint 22-27: 建议优化滚动列表的实现方式

当前实现存在以下几个问题:

  1. 使用 Array.from 创建200个元素的数组性能欠佳
  2. 固定的滚动区域高度可能在不同设备上表现不一致

建议的优化方案:

- <ScrollView scrollY style={{ height: '300px' }}>
-   {Array.from({ length: 200 })
-     .fill('')
-     .map((_, i) => (
-       <Cell key={i}>禁止滚动穿透-{i}</Cell>
-     ))}
- </ScrollView>
+ const ITEMS_COUNT = 200
+ const SCROLL_HEIGHT = '50vh'
+ 
+ <ScrollView scrollY style={{ height: SCROLL_HEIGHT }}>
+   {[...new Array(ITEMS_COUNT)].map((_, i) => (
+     <Cell key={i}>禁止滚动穿透-{i}</Cell>
+   ))}
+ </ScrollView>
src/packages/popup/demos/h5/demo2.tsx (1)

72-86: 优化居中弹出层的滚动实现

当前实现可能在大量数据时存在性能问题。建议考虑以下优化:

  1. 使用虚拟列表来优化长列表渲染
  2. 添加加载状态指示器
-        <div style={{ height: '100px', overflowY: 'auto' }}>
-          {Array.from({ length: 10 })
-            .fill('')
-            .map((_, i) => (
-              <Cell key={i}>正文</Cell>
-            ))}
-        </div>
+        <VirtualList
+          height={100}
+          itemCount={10}
+          itemSize={44}
+          renderItem={({ index }) => (
+            <Cell key={index}>正文</Cell>
+          )}
+        />
src/packages/popup/demos/taro/demo2.tsx (2)

3-3: ScrollView 组件使用建议

ScrollView 的实现符合 Taro 规范,但建议添加以下属性以提升用户体验:

  1. 添加下拉刷新功能
  2. 添加触底加载更多功能
-        <ScrollView style={{ height: '100px' }} scrollY>
+        <ScrollView
+          style={{ height: '100px' }}
+          scrollY
+          refresherEnabled
+          onRefresherRefresh={onRefresh}
+          onScrollToLower={onLoadMore}
+        >

Also applies to: 84-92


55-61: 底部弹出层样式优化建议

建议将固定高度改为相对高度,以适应不同屏幕尺寸。

-        style={{ height: '300px' }}
+        style={{ height: '50vh' }}
src/packages/popup/popup.scss (2)

5-5: 弹出层最小高度调整建议

固定的最小高度可能在某些场景下不够灵活,建议使用更灵活的方式。

-  min-height: 46%;
+  min-height: min(46%, 460px);

31-31: 颜色变量使用建议

建议将颜色值统一到设计规范中,避免使用散落的颜色变量。

-      color: $color-text;
+      color: var(--nutui-color-text);

-      color: $color-title;
-      cursor: pointer;
+      color: var(--nutui-color-title);
+      cursor: pointer;

Also applies to: 49-50

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f042dc2 and 808e9cc.

📒 Files selected for processing (15)
  • src/packages/cascader/cascader.taro.tsx (0 hunks)
  • src/packages/popup/demos/h5/demo1.tsx (1 hunks)
  • src/packages/popup/demos/h5/demo2.tsx (3 hunks)
  • src/packages/popup/demos/taro/demo1.tsx (1 hunks)
  • src/packages/popup/demos/taro/demo2.tsx (3 hunks)
  • src/packages/popup/demos/taro/demo8.tsx (1 hunks)
  • src/packages/popup/popup.scss (3 hunks)
  • src/packages/popup/popup.taro.tsx (1 hunks)
  • src/packages/popup/popup.tsx (1 hunks)
  • src/packages/timeselect/demos/taro/demo1.tsx (0 hunks)
  • src/packages/timeselect/demos/taro/demo2.tsx (0 hunks)
  • src/packages/timeselect/demos/taro/demo3.tsx (0 hunks)
  • src/packages/timeselect/timeselect.taro.tsx (0 hunks)
  • src/packages/timeselect/timeselect.tsx (0 hunks)
  • src/styles/variables.scss (1 hunks)
💤 Files with no reviewable changes (6)
  • src/packages/timeselect/demos/taro/demo3.tsx
  • src/packages/timeselect/demos/taro/demo1.tsx
  • src/packages/timeselect/demos/taro/demo2.tsx
  • src/packages/timeselect/timeselect.tsx
  • src/packages/cascader/cascader.taro.tsx
  • src/packages/timeselect/timeselect.taro.tsx
🔇 Additional comments (9)
src/packages/popup/demos/h5/demo1.tsx (1)

4-6: 组件重命名和状态变量更新符合最佳实践

组件名称从 Demo1 更改为 Demo 使代码更简洁。状态变量的命名 showIcon 清晰地表达了其用途。

Also applies to: 28-28

src/packages/popup/demos/taro/demo8.tsx (1)

16-21: 验证lockScroll属性在不同场景下的效果

需要确保lockScroll属性在各种复杂的滚动场景下都能正常工作。

✅ Verification successful

lockScroll属性实现已经过验证,可以安全使用

根据代码搜索结果,我们可以确认:

  • lockScroll属性在Popup组件中已经完整实现,默认值为true
  • 该属性通过useLockScroll/useLockScrollTaro钩子函数处理滚动锁定逻辑
  • 在Taro环境下,还会自动转换为catchMove属性来阻止滚动穿透
  • 该属性已在多个组件(Dialog、Menu、Toast等)中得到广泛验证
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索其他使用lockScroll的组件,分析实现方式的一致性
rg -l "lockScroll" --type tsx

Length of output: 57


Script:

#!/bin/bash
# 搜索使用lockScroll的组件实现
rg "lockScroll" -A 5

Length of output: 35550


Script:

#!/bin/bash
# 查找所有可能包含lockScroll的文件
fd . -e ts -e tsx -e js -e jsx --exec rg "lockScroll" {}

Length of output: 1988


Script:

#!/bin/bash
# 使用ast-grep搜索包含lockScroll属性的JSX元素
ast-grep --pattern 'lockScroll={$_}'

Length of output: 38

src/packages/popup/demos/h5/demo2.tsx (2)

9-9: 新增状态变量管理居中弹出层

状态管理的实现符合 React Hooks 的最佳实践。


37-42: 新增居中弹出层的触发按钮

Cell 组件的使用恰当,标题和点击事件处理符合规范。

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

286-286: 代码重构优化!

将 Fragment 语法简化为直接渲染 popup 组件,提高了代码的可读性。


292-292: 条件语句优化!

使用三元运算符替代 if-else 语句,使代码更简洁。

src/packages/popup/popup.tsx (2)

288-288: 代码重构优化!

将 Fragment 语法简化为直接渲染 popup 组件,保持与 Taro 版本一致的代码风格。


294-294: 条件语句优化!

使用三元运算符替代 if-else 语句,与 Taro 版本保持一致的代码风格。

src/styles/variables.scss (1)

1065-1065: 样式变量标准化优化!

  1. 弹出层圆角使用设计系统的 $radius-xl 变量
  2. 标题样式更新:
    • 字体大小改用 $font-size-l
    • 新增字体粗细设置为 $font-weight-bold
  3. 描述文本字体大小更新为 $font-size-base

这些更改提高了组件与设计系统的一致性。

Also applies to: 1070-1074, 1078-1078

src/packages/popup/popup.scss Show resolved Hide resolved
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.84%. Comparing base (80bc6b3) to head (196d4a3).
Report is 4 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #2844      +/-   ##
=============================================
+ Coverage      84.56%   85.84%   +1.27%     
=============================================
  Files            273      271       -2     
  Lines          18593    18427     -166     
  Branches        2691     2726      +35     
=============================================
+ Hits           15723    15818      +95     
+ Misses          2865     2604     -261     
  Partials           5        5              

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

@oasis-cloud
Copy link
Collaborator

image image 注意主标题和副标题的间距,关闭按钮的大小

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/popup/demo.taro.tsx (1)

83-83: 类名逻辑优化得当

className 的逻辑变更使得类名分配更加明确和环境特定。建议为 'web' 类添加注释说明其用途。

建议添加如下注释:

+ // web 环境下添加特定样式类
  <ScrollView className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 808e9cc and 39762e1.

⛔ Files ignored due to path filters (1)
  • src/packages/timeselect/__test__/__snapshots__/timeselect.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • src/packages/popup/demo.taro.tsx (1 hunks)
  • src/packages/popup/demos/taro/demo2.tsx (3 hunks)
  • src/packages/popup/popup.scss (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/packages/popup/demos/taro/demo2.tsx
🔇 Additional comments (5)
src/packages/popup/popup.scss (5)

25-25: 标题和描述文本的颜色层次优化合理

使用 $color-title 和 $color-text 变量改善了文本的视觉层次,符合设计规范。

Also applies to: 31-33


36-41: 左侧标题定位方式合理

使用绝对定位和设计系统变量控制左侧内容位置,实现了更精确的布局控制。


44-51: 右侧图标样式优化合理

  1. 使用与左侧一致的定位方式
  2. 颜色更新为标题色值,提升视觉一致性
  3. 添加鼠标手型提升交互体验

88-88: 建议优化底部弹出层最大高度设置

当前设置可能在某些机型上出现底部安全区域遮挡问题。

建议参考之前的优化建议:

-    max-height: 87%;
+    max-height: calc(87% - env(safe-area-inset-bottom));

5-5: 建议验证最小高度增加的影响

最小高度从 26% 增加到 46% 的变更可能会影响在小屏幕设备上的显示效果。

请验证此更改在各种屏幕尺寸下的表现:

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/overlay/overlay.scss (1)

64-69: 建议添加RTL相关注释

为了提高代码的可维护性,建议在RTL样式块之前添加注释说明。

+// RTL support
 [dir='rtl'] .nut-overlay,
 .nut-rtl .nut-overlay {
   left: auto;
   right: 0;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dce1bc6 and 563271c.

📒 Files selected for processing (5)
  • src/packages/overlay/overlay.scss (1 hunks)
  • src/packages/popup/popup.scss (4 hunks)
  • src/packages/popup/popup.taro.tsx (4 hunks)
  • src/packages/popup/popup.tsx (4 hunks)
  • src/styles/variables.scss (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/packages/popup/popup.scss
  • src/packages/popup/popup.taro.tsx
  • src/packages/popup/popup.tsx
  • src/styles/variables.scss
🔇 Additional comments (1)
src/packages/overlay/overlay.scss (1)

65-69: RTL样式实现正确!

RTL样式选择器和属性设置符合右到左布局的要求,同时支持了属性选择器和类选择器两种方式。

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3654237 and e70cef6.

⛔ Files ignored due to path filters (2)
  • src/packages/address/__test__/__snapshots__/address.spec.tsx.snap is excluded by !**/*.snap
  • src/packages/timeselect/__test__/__snapshots__/timeselect.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • src/packages/cascader/cascader.taro.tsx (0 hunks)
  • src/packages/popup/__tests__/popup.spec.tsx (2 hunks)
  • src/packages/popup/demo.taro.tsx (1 hunks)
  • src/packages/popup/popup.scss (4 hunks)
  • src/packages/popup/popup.taro.tsx (3 hunks)
  • src/packages/popup/popup.tsx (3 hunks)
  • src/styles/variables.scss (1 hunks)
💤 Files with no reviewable changes (1)
  • src/packages/cascader/cascader.taro.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/packages/popup/tests/popup.spec.tsx
  • src/packages/popup/demo.taro.tsx
  • src/packages/popup/popup.taro.tsx
  • src/packages/popup/popup.scss
  • src/styles/variables.scss
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/packages/popup/popup.tsx

[warning] 292-295: src/packages/popup/popup.tsx#L292-L295
Added lines #L292 - L295 were not covered by tests


[warning] 299-301: src/packages/popup/popup.tsx#L299-L301
Added lines #L299 - L301 were not covered by tests

🔇 Additional comments (2)
src/packages/popup/popup.tsx (2)

194-203: 关于关闭图标渲染的重构

将关闭图标的渲染逻辑抽离成独立函数是个很好的改进,提高了代码的可维护性。


284-284: 可见性控制逻辑优化

使用三元运算符简化了可见性控制逻辑,提高了代码可读性。

Comment on lines +216 to +223
<div className={`${classPrefix}-title-wrapper`}>
{title && (
<div className={`${classPrefix}-title-title`}>{title}</div>
)}
{description && (
<div className={`${classPrefix}-title-description`}>
<div
className={`${classPrefix}-title-description ${title ? `${classPrefix}-title-description-gap` : ''}`}
>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

标题结构优化建议

新增的 title-wrapper 结构改进了布局,但根据PR评论中提到的间距问题,建议调整以下样式:

  <div className={`${classPrefix}-title-description ${
-   title ? `${classPrefix}-title-description-gap` : ''
+   title ? `${classPrefix}-title-description-gap-v15` : ''
  }`}>

请确保在对应的 SCSS 文件中定义新的间距类。

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

Comment on lines +198 to +200
<div className={closeClasses} onClick={onHandleClickCloseIcon}>
{React.isValidElement(closeIcon) ? closeIcon : <Close />}
</div>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

关闭按钮样式调整建议

根据PR评论反馈,关闭按钮的尺寸需要调整。

建议在样式中添加以下调整:

+ .nut-popup-title-right .nutui-icon {
+   font-size: 16px;
+ }

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

Comment on lines +291 to +303
const resolveContainer = (getContainer: Teleport | undefined) => {
const container =
typeof getContainer === 'function' ? getContainer() : getContainer
return container || document.body
}

const renderToContainer = (getContainer: Teleport, node: ReactElement) => {
if (getContainer) {
const container = resolveContainer(getContainer)
return createPortal(node, container) as ReactPortal
}
return node
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要补充容器处理相关的测试用例

经过验证,当前 popup.spec.tsx 中虽然有测试 portal 相关的基本功能,但缺少对新增的 resolveContainerrenderToContainer 函数的完整测试覆盖。

建议添加以下测试场景:

  • 使用函数返回自定义容器元素
  • 直接传入 DOM 元素作为容器
  • 未传入容器时使用 document.body
  • 容器为 null 时的处理
🔗 Analysis chain

容器处理逻辑需要补充测试

新增的容器处理逻辑 resolveContainerrenderToContainer 函数缺少测试覆盖。

建议添加以下测试场景:

  1. 自定义容器函数
  2. 自定义容器元素
  3. 默认容器(document.body)
  4. portal 为 null 的情况
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否已存在相关测试
rg -l "resolveContainer|renderToContainer" "src/packages/popup/__tests__"

Length of output: 73


Script:

#!/bin/bash
# 检查测试文件是否存在
fd -t f . "src/packages/popup/__tests__"

# 检查是否有其他相关测试文件
rg -l "popup.*test" .

# 检查当前的测试覆盖情况
rg -A 5 "test|describe|it" "src/packages/popup/__tests__"

Length of output: 12884

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 292-295: src/packages/popup/popup.tsx#L292-L295
Added lines #L292 - L295 were not covered by tests


[warning] 299-301: src/packages/popup/popup.tsx#L299-L301
Added lines #L299 - L301 were not covered by tests

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

🧹 Nitpick comments (1)
src/packages/address/address.tsx (1)

124-135: 小建议:考虑避免使用硬编码颜色。

这里使用了 "#cccccc" 作为箭头图标的颜色,可能会与其他主题或样式冲突。建议使用主题变量或通过 CSS classes 统一管理颜色值,从而提高可维护性和灵活性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e70cef6 and 307fc95.

⛔ Files ignored due to path filters (1)
  • src/packages/address/__test__/__snapshots__/address.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/packages/address/address.tsx (1 hunks)

Comment on lines +124 to +135
if (custom) {
return (
<div className={`${classPrefix}-left-icon`} onClick={onSwitchModule}>
{React.isValidElement(backIcon) ? (
backIcon
) : (
<ArrowLeft color="#cccccc" />
)}
</div>
)
}
return null
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

建议:在回调中使用最新状态以避免逻辑错误

当前的 onSwitchModule 函数在更新 currentType 之后,才调用了 onSwitch 回调,但回调参数仍然是之前旧的 currentType 值,这可能导致不符合预期的行为。建议先用一个局部变量存储新的类型,再统一更新并调用回调,以确保回调函数拿到最新的类型值。

可以参考以下修正示例:

-const onSwitchModule = () => {
-  if (currentType === 'exist') {
-    setCurrentType('custom')
-  } else {
-    setCurrentType('exist')
-  }
-  onSwitch && onSwitch({ type: currentType })
+const onSwitchModule = () => {
+  const newType = currentType === 'exist' ? 'custom' : 'exist'
+  setCurrentType(newType)
+  onSwitch && onSwitch({ type: newType })
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (custom) {
return (
<div className={`${classPrefix}-left-icon`} onClick={onSwitchModule}>
{React.isValidElement(backIcon) ? (
backIcon
) : (
<ArrowLeft color="#cccccc" />
)}
</div>
)
}
return null
if (custom) {
return (
<div className={`${classPrefix}-left-icon`} onClick={onSwitchModule}>
{React.isValidElement(backIcon) ? (
backIcon
) : (
<ArrowLeft color="#cccccc" />
)}
</div>
)
}
return null

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/packages/address/__test__/address.spec.tsx (1)

120-125: 测试用例命名重复,建议在语义层面进行区分
当前新增的测试用例与上面已存在的“Address: show custom”同名,仅在内部添加了“custom”属性。建议在命名上进一步细化,比如“Address: show custom prop enabled”,以避免混淆、提高可读性和可维护性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 307fc95 and f565985.

⛔ Files ignored due to path filters (1)
  • src/packages/address/__test__/__snapshots__/address.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/packages/address/__test__/address.spec.tsx (1 hunks)

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

🧹 Nitpick comments (5)
src/packages/timeselect/__test__/timeselect.spec.tsx (3)

32-32: 快照测试可加大场景覆盖

现仅对容器进行一次快照测试,可以考虑补充更多场景(例如组件关闭后)对 UI 状态进行快照,以更全面地保障组件变更的可预期性。


38-38: handleSelect 的测试逻辑建议补充

新增的 handleSelect 回调目前仅在组件中声明,尚未在测试中断言其调用场景或参数。若需要确保此回调功能有效,可在测试中模拟触发并断言其调用次数与传参。

+ expect(handleSelect).toHaveBeenCalled()
+ // 或校验参数
+ expect(handleSelect).toHaveBeenCalledWith(/* ... */)

64-70: 对关闭按钮的选择器和可见性断言可考虑更多边界情况

当前通过固定类名 .nut-popup-title-right-top-right 找到关闭按钮并触发点击,测试用例能正确验证弹层 display 的更新。但若类名后续改动,可能导致测试失效。可以增加更语义化的选择器或容错处理。此外,若要严格断言“关闭弹层”,可再验证组件整体的 DOM 结构是否有相应掉或触发了 onSelect 回调。

src/packages/address/__test__/address.spec.tsx (2)

121-126: 建议增强自定义属性的测试覆盖

当前测试仅验证了快照匹配,建议添加更具体的断言来验证自定义属性的实际效果。

 test('Address: show custom', async () => {
   const { container } = render(
     <Address visible options={optionsDemo1} custom title="选择地址" />
   )
+  const customElement = container.querySelector('.nut-address-custom')
+  expect(customElement).toBeTruthy()
+  expect(customElement?.textContent).toBe('选择地址')
   expect(container.innerHTML).toMatchSnapshot()
 })

128-139: 建议完善自定义图标的测试用例

当前测试仅验证了快照匹配,建议添加具体的断言来验证 Star 图标是否正确渲染。

 test('Address: show custom icon', async () => {
   const { container } = render(
     <Address
       visible
       options={optionsDemo1}
       custom
       backIcon={<Star />}
       title="选择地址"
     />
   )
+  const iconElement = container.querySelector('.nut-icon-star')
+  expect(iconElement).toBeTruthy()
   expect(container.innerHTML).toMatchSnapshot()
 })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f565985 and f2f8712.

⛔ Files ignored due to path filters (1)
  • src/packages/address/__test__/__snapshots__/address.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/packages/address/__test__/address.spec.tsx (2 hunks)
  • src/packages/timeselect/__test__/timeselect.spec.tsx (3 hunks)
🔇 Additional comments (3)
src/packages/timeselect/__test__/timeselect.spec.tsx (2)

2-2: 使用 waitFor 位置恰当但请留意测试覆盖场景

目前在同一测试用例中存在两种方式(直接 expect、异步等待)的混合使用,整体测试流程合理,但建议确保在断言前后,都有足够的时间让渲染与事件完成。保持测试中的一致性有助于避免间歇性失败。


46-46: onSelect 属性增加后请核对业务逻辑

代码正确地将 handleSelect 传递给 onSelect,但需确认 TimeSelect 组件内部对 onSelect 的调用时机及入参是否与预期一致,并在业务层充分使用该回调。

src/packages/address/__test__/address.spec.tsx (1)

4-4: 确认图标组件的导入使用情况

导入了 Star 图标组件,但仅在一个测试用例中使用。建议检查是否需要在其他测试用例中也使用该图标,以提高测试覆盖率。

✅ Verification successful

Star 图标组件的使用是合理的

根据代码库分析,Star 图标组件在多个组件和测试文件中都有使用,包括 Button、Loading、Table 等组件。在 address.spec.tsx 中,Star 图标仅用于测试自定义返回图标的功能,这是一个合理且常见的测试用例,不需要在其他测试用例中重复使用。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查其他测试文件中是否也需要使用 Star 图标
rg "import.*Star.*from.*@nutui/icons-react" --type tsx

Length of output: 84


Script:

#!/bin/bash
# 使用更通用的搜索方式查找 Star 图标的使用情况
rg "import.*Star.*from.*@nutui/icons-react"

# 查找 Star 组件在测试文件中的使用
rg "Star" "src/packages/address/__test__/address.spec.tsx" -A 5

Length of output: 3810

expect(container.innerHTML).toMatchSnapshot()
})

test('Address: show custom icon', async () => {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

注意:测试用例命名重复

存在两个同名的测试用例 "Address: show custom icon",这可能会导致测试结果的混淆。建议为第二个测试用例使用更具描述性的名称。

-test('Address: show custom icon', async () => {
+test('Address: show custom icon with exist address', async () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('Address: show custom icon', async () => {
test('Address: show custom icon with exist address', async () => {

Comment on lines +141 to +161
test('Address: show custom icon', async () => {
const onExistSelect = vi.fn()
const onSwitch = vi.fn()
const { container } = render(
<Address
visible
type="exist"
existList={existList}
options={optionsDemo1}
custom="选择其他地址"
onExistSelect={onExistSelect}
onSwitch={onSwitch}
/>
)
expect(container.innerHTML).toMatchSnapshot()
const btn = container.querySelector('.nut-address-footer-btn') as Element
fireEvent.click(btn)
const leftIcon = container.querySelector('.nut-address-left-icon') as Element
expect(leftIcon).toBeTruthy()
fireEvent.click(leftIcon)
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议优化事件处理函数的测试

当前测试中的事件处理函数 onExistSelectonSwitch 虽然被模拟,但没有验证它们是否被正确调用。建议添加相应的断言。

 test('Address: show custom icon', async () => {
   const onExistSelect = vi.fn()
   const onSwitch = vi.fn()
   const { container } = render(
     <Address
       visible
       type="exist"
       existList={existList}
       options={optionsDemo1}
       custom="选择其他地址"
       onExistSelect={onExistSelect}
       onSwitch={onSwitch}
     />
   )
   expect(container.innerHTML).toMatchSnapshot()
   const btn = container.querySelector('.nut-address-footer-btn') as Element
   fireEvent.click(btn)
+  expect(onSwitch).toHaveBeenCalled()
   const leftIcon = container.querySelector('.nut-address-left-icon') as Element
   expect(leftIcon).toBeTruthy()
   fireEvent.click(leftIcon)
+  expect(onExistSelect).toHaveBeenCalled()
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('Address: show custom icon', async () => {
const onExistSelect = vi.fn()
const onSwitch = vi.fn()
const { container } = render(
<Address
visible
type="exist"
existList={existList}
options={optionsDemo1}
custom="选择其他地址"
onExistSelect={onExistSelect}
onSwitch={onSwitch}
/>
)
expect(container.innerHTML).toMatchSnapshot()
const btn = container.querySelector('.nut-address-footer-btn') as Element
fireEvent.click(btn)
const leftIcon = container.querySelector('.nut-address-left-icon') as Element
expect(leftIcon).toBeTruthy()
fireEvent.click(leftIcon)
})
test('Address: show custom icon', async () => {
const onExistSelect = vi.fn()
const onSwitch = vi.fn()
const { container } = render(
<Address
visible
type="exist"
existList={existList}
options={optionsDemo1}
custom="选择其他地址"
onExistSelect={onExistSelect}
onSwitch={onSwitch}
/>
)
expect(container.innerHTML).toMatchSnapshot()
const btn = container.querySelector('.nut-address-footer-btn') as Element
fireEvent.click(btn)
expect(onSwitch).toHaveBeenCalled()
const leftIcon = container.querySelector('.nut-address-left-icon') as Element
expect(leftIcon).toBeTruthy()
fireEvent.click(leftIcon)
expect(onExistSelect).toHaveBeenCalled()
})

@xiaoyatong xiaoyatong requested a review from irisSong December 24, 2024 03:49
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件不提交

@oasis-cloud oasis-cloud merged commit 71f0a53 into jdf2e:feat_v3.x Dec 24, 2024
4 of 5 checks passed
This was referenced Dec 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.

2 participants