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(Dialog): v15 #2845

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

feat(Dialog): v15 #2845

wants to merge 2 commits into from

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

本次变更涉及多个组件的样式和功能更新,主要集中在按钮和对话框的样式调整。按钮的样式在 button.scss 中进行了修改,特别是针对不同尺寸按钮的边框半径和字体权重进行了更新。对话框的样式在 dialog.scss 中也进行了重构,增强了其最小宽度和最大高度的定义,并调整了按钮的布局逻辑。此外,样式变量在 variables.scss 中进行了全面更新,以确保设计的一致性。

Changes

文件路径 变更摘要
src/packages/button/button.scss 修改了 .nut-button 类的样式,注释掉了不同尺寸按钮的边框半径,并为大型按钮添加了新的样式和字体权重调整。
src/packages/button/demos/taro/demo8.tsx 更新了 Demo8 组件中的按钮文本,添加了一个新的大型按钮,保持了按钮的边距样式不变。
src/packages/dialog/demos/taro/demo2.tsx 修改了 Dialog 组件的标题和确认文本,添加了隐藏取消按钮的属性。
src/packages/dialog/dialog.scss 添加了 .nut-dialog 的最小宽度和最大高度,调整了关闭按钮的位置和对话框内容的文本颜色,重构了对话框底部的样式。
src/packages/dialog/dialog.taro.tsx 修改了 BaseDialog 组件的底部按钮渲染逻辑,支持根据 footerDirection 属性动态渲染按钮。
src/packages/dialog/dialog.tsx 添加了 footerDirection 属性,更新了底部按钮的渲染逻辑以支持垂直和水平布局。
src/styles/variables.scss 更新了多个样式变量,特别是与按钮和对话框相关的变量,确保样式的一致性和可读性。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Button
    participant Dialog

    User->>Button: 点击操作按钮
    Button->>Dialog: 打开对话框
    Dialog->>User: 显示对话框内容
    User->>Dialog: 点击确认
    Dialog->>User: 关闭对话框
Loading

Possibly related PRs

Suggested labels

3.x

Suggested reviewers

  • oasis-cloud

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 Dec 9, 2024
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.15%. Comparing base (f042dc2) to head (f643585).

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2845   +/-   ##
==========================================
  Coverage      84.14%   84.15%           
==========================================
  Files            273      273           
  Lines          18103    18114   +11     
  Branches        2690     2694    +4     
==========================================
+ Hits           15232    15243   +11     
  Misses          2866     2866           
  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: 3

🧹 Outside diff range and nitpick comments (1)
src/packages/dialog/dialog.tsx (1)

87-89: 代码优化建议:btnClass 逻辑可以简化

建议使用模板字符串简化类名拼接逻辑。

-    const btnClass =
-      hideCancelButton || hideConfirmButton ? `${classPrefix}-footer-block` : ''
+    const btnClass = classNames({
+      [`${classPrefix}-footer-block`]: hideCancelButton || hideConfirmButton
+    })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 Files selected for processing (7)
  • src/packages/button/button.scss (5 hunks)
  • src/packages/button/demos/taro/demo8.tsx (1 hunks)
  • src/packages/dialog/demos/taro/demo2.tsx (1 hunks)
  • src/packages/dialog/dialog.scss (5 hunks)
  • src/packages/dialog/dialog.taro.tsx (1 hunks)
  • src/packages/dialog/dialog.tsx (2 hunks)
  • src/styles/variables.scss (8 hunks)
🧰 Additional context used
🪛 GitHub Check: build
src/packages/dialog/dialog.tsx

[failure] 97-97:
Argument of type 'MouseEvent<HTMLDivElement, MouseEvent>' is not assignable to parameter of type 'MouseEvent<HTMLButtonElement, MouseEvent>'.

src/packages/dialog/dialog.taro.tsx

[failure] 128-128:
Argument of type 'ITouchEvent' is not assignable to parameter of type 'MouseEvent<HTMLButtonElement, MouseEvent>'.

🔇 Additional comments (26)
src/styles/variables.scss (11)

210-211: 优化按钮的圆角和边框宽度变量

将按钮的圆角设置为 $radius-s,边框宽度设置为 0.5px,增强了按钮样式的一致性和可维护性。


234-234: 调整默认按钮的字体大小

$button-default-font-size 更新为 $font-size-base,提高了按钮文字的可读性。


247-250: 统一超大按钮的圆角设置变量

$button-xlarge-border-radius 设置为 $radius-base,确保了超大按钮的圆角样式一致。


256-256: 调整大按钮的字体大小

$button-large-font-size 更新为 $font-size-l,符合大按钮的视觉要求。


264-264: 统一大按钮的圆角设置变量

$button-large-border-radius 设置为 $radius-s,确保了大按钮的圆角样式一致。


275-275: 小按钮的圆角设置优化

$button-small-border-radius 设置为 $radius-xs,使小按钮的圆角更加符合设计规范。


286-286: 迷你按钮的圆角设置优化

$button-mini-border-radius 设置为 $radius-xs,使迷你按钮的圆角样式与整体风格一致。


1339-1344: 为对话框添加最小宽度和最大高度

新增了 $dialog-min-width$dialog-max-height 变量,增强了对话框在不同屏幕尺寸下的响应式表现。


1351-1351: 调整对话框内容的内边距

更新 $dialog-content-margin12px 0 16px 0,优化了内容与边界的间距,提升了视觉美观度。


1383-1383: 提高对话框标题的字体粗细

$dialog-header-font-weight 设置为 $font-weight-bold,使标题更加突出,提升用户注意力。


1387-1391: 调整对话框关闭按钮的样式

新增 $dialog-vertical-footer-ok-margin-top$dialog-close-width$dialog-close-height 等变量,优化了关闭按钮的位置和尺寸,改善了用户体验。

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

22-22: 更新对话框标题和按钮

将标题更新为“标题”,设置确认按钮文本为“确认”,并隐藏取消按钮,使对话框更加简洁明了。

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

41-44: 新增操作按钮并调整尺寸

添加了一个标签为“操作按钮”的按钮,并设置了大尺寸,丰富了按钮示例,提供了更多使用场景。

src/packages/dialog/dialog.scss (8)

9-9: 为对话框设置最小宽度

新增 min-width: $dialog-min-width;,确保对话框在小屏幕设备上也能保持良好的展示效果。


11-11: 限制对话框的最大高度

设置 max-height: 67%;,防止内容过多时对话框超出屏幕范围,提升用户体验。


92-92: 修改对话框内容的文字颜色

.nut-dialog-content 的文字颜色更新为 $color-title,提高了内容的可读性。


111-125: 优化垂直方向按钮的布局

调整垂直方向按钮的样式,确保按钮在垂直布局下能正确地填满宽度并排列。


135-135: 加强取消按钮的视觉强调

为取消按钮添加了 font-weight: $font-weight;,使其在视觉上更加突出,便于用户识别。


140-141: 加强确认按钮的视觉权重

为确认按钮设置 font-weight: $font-weight-bold;,强调主要操作,提高用户注意力。


143-146: 调整按钮块的布局

新增 .nut-dialog-footer-block 类,确保按钮在块级布局下能够填满父容器的宽度。


64-64: 调整关闭按钮的位置

将关闭按钮的 bottom 值从 -56px 修改为 -96px,需要确保在各种屏幕上显示正常,避免遮挡内容。

✅ Verification successful

Let me gather more information about the dialog styles to verify the positioning.


关闭按钮位置调整已验证安全

根据代码分析,此修改是安全的:

  • 关闭按钮的位置变更是对 &-bottom 类的样式调整,不会影响其他位置的关闭按钮(top-left 和 top-right)
  • 此修改是针对底部关闭按钮的特定样式,通过 CHANGELOG 可以看到这是一个新增的功能 (feat(dialog): support bottom close button #1978)
  • 关闭按钮使用了相对定位和 transform,即使在不同屏幕尺寸下也能保持正确的位置关系
  • 底部关闭按钮的颜色继承自变量 $dialog-close-color,确保了视觉上的一致性
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查关闭按钮在不同屏幕尺寸下的位置。

# 测试:搜索对 `.nut-dialog-close` 类的样式定义,预期结果:仅存在一个 `bottom: -96px` 的定义。
rg '\.nut-dialog-close' -A 5

Length of output: 949


Script:

#!/bin/bash
# 搜索所有与 dialog 相关的 SCSS/CSS 文件中的关闭按钮样式定义
fd -e scss -e css | xargs rg '\.nut-dialog.*close' -B 2 -A 5

# 检查是否有响应式样式定义
fd -e scss -e css | xargs rg '@media.*\.nut-dialog.*close' -B 2 -A 5

Length of output: 133


Script:

#!/bin/bash
# 直接查找 dialog.scss 文件中的关闭按钮样式
cat src/packages/dialog/dialog.scss

# 查找所有包含 dialog 和 close 的样式定义
rg -i 'dialog.*close' -B 2 -A 5

Length of output: 24259

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

114-115: 确认按钮样式更新

确认按钮添加 size="large" 属性符合设计规范。

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

145-146: 按钮样式实现正确

Taro 版本的按钮样式实现与 React 版本保持一致,符合预期。

src/packages/button/button.scss (3)

104-107: 按钮圆角样式优化

新增了不同尺寸按钮的圆角变量定义,提高了样式的可维护性。


147-155: 大尺寸按钮字重设置合理

为大尺寸按钮设置统一的字重,保持了视觉一致性。


175-175: 验证被注释的 border-radius 样式

多处 border-radius 样式被注释掉,需要确认这些样式是否已经在变量中正确定义。

Also applies to: 200-200, 225-225, 242-242

✅ Verification successful

被注释的 border-radius 样式已被正确替换

从搜索结果可以看到,button 组件已经使用了更具体的 CSS 变量来定义圆角:

  • 使用 $button-border-radius(默认 8px)
  • 使用 $button-large-border-radius(12px)
  • 使用 $button-small-border-radius(8px)
  • 使用 $button-mini-border-radius(6px)

被注释掉的 $radius-base$radius-s 已被这些更明确的按钮专用变量所替代,不会造成样式不一致的问题。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 variables.scss 中是否定义了相关的圆角变量
rg -A 1 "\$radius-(base|s)" src/styles/

Length of output: 40


Script:

#!/bin/bash
# 搜索整个代码库中的 radius 相关变量定义
rg -A 1 "\$radius" 

# 搜索 button.scss 中所有的 border-radius 相关代码
rg -A 1 "border-radius" src/packages/button/

Length of output: 4567

@@ -218,7 +218,7 @@ $button-default-background-color: var(
) !default;
$button-default-border-color: var(
--nutui-button-default-border-color,
$color-text
$color-text-disabled
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

默认按钮边框颜色设置需要调整

从代码分析来看,确实存在不合理的颜色设置:

  • 在主样式文件 variables.scss 中使用了 $color-text-disabled(#c2c4cc,禁用文本色)作为默认按钮边框颜色
  • 而在其他主题文件(variables-jrkf.scssvariables-jmapp.scss)中都使用了更合适的 $color-default 变量

建议:

  • variables.scss 中的 $button-default-border-color 也修改为使用 $color-default 变量,以保持与其他主题一致的视觉效果
  • 避免使用禁用状态的颜色作为正常状态按钮的边框色
🔗 Analysis chain

确认默认按钮边框颜色是否合适

$button-default-border-color 设置为 $color-text-disabled 可能会使默认按钮看起来像是禁用状态。建议确认此颜色选择是否符合设计规范。


Let me gather more information about the color variable usage and its definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查代码库中默认按钮的边框颜色设置。

# 测试:搜索使用 `$button-default-border-color` 的样式文件,预期结果:确认颜色是否正确应用。
rg '\$button-default-border-color'

Length of output: 310


Script:

#!/bin/bash
# 检查 $button-default-border-color 的具体定义和相关颜色变量
rg -A 3 '\$button-default-border-color:' src/styles/variables*.scss

# 检查 $color-text-disabled 的定义
rg '\$color-text-disabled:' src/styles/variables*.scss

# 查看按钮组件中的相关样式上下文
rg -A 5 -B 5 '\$button-default-border-color' src/packages/button/button.scss

Length of output: 1473

Comment on lines +93 to +110
{!hideCancelButton &&
(footerDirection === 'vertical' ? (
<div
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</div>
) : (
<Button
type="default"
size="large"
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</Button>
))}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复事件处理器类型不匹配问题

当前实现中,div 的 onClick 事件处理器与 button 的事件处理器类型不匹配,这可能导致类型错误。

建议修改事件处理函数的类型定义:

-    const handleCancel = (e: MouseEvent<HTMLButtonElement>) => {
+    const handleCancel = (e: MouseEvent<HTMLElement>) => {
📝 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
{!hideCancelButton &&
(footerDirection === 'vertical' ? (
<div
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</div>
) : (
<Button
type="default"
size="large"
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</Button>
))}
{!hideCancelButton &&
(footerDirection === 'vertical' ? (
<div
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</div>
) : (
<Button
type="default"
size="large"
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</Button>
))}
🧰 Tools
🪛 GitHub Check: build

[failure] 97-97:
Argument of type 'MouseEvent<HTMLDivElement, MouseEvent>' is not assignable to parameter of type 'MouseEvent<HTMLButtonElement, MouseEvent>'.

Comment on lines +124 to +141
{!hideCancelButton &&
(footerDirection === 'vertical' ? (
<View
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</View>
) : (
<Button
type="default"
size="large"
className={`${classPrefix}-footer-cancel ${btnClass}`}
onClick={(e) => handleCancel(e)}
>
{cancelText || locale.cancel}
</Button>
))}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复 Taro View 组件事件类型问题

在 Taro 环境中,View 组件的事件类型与 React 的 MouseEvent 不兼容。

建议修改事件处理函数类型:

-    const handleCancel = (e: MouseEvent<HTMLButtonElement>) => {
+    const handleCancel = (e: ITouchEvent) => {
       e.stopPropagation()
       if (!beforeCancel?.()) return
       if (!beforeClose?.()) return
       onClose?.()
       onCancel?.()
     }

同时需要在文件顶部添加类型导入:

+import type { ITouchEvent } from '@tarojs/components'

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

🧰 Tools
🪛 GitHub Check: build

[failure] 128-128:
Argument of type 'ITouchEvent' is not assignable to parameter of type 'MouseEvent<HTMLButtonElement, MouseEvent>'.

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