Skip to content

feat: 增加extra #483

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Roxannej
Copy link

@Roxannej Roxannej commented May 26, 2025

添加了extra,ant-design/ant-design#53542

Summary by CodeRabbit

  • 新功能

    • Dialog 组件新增支持 extra 属性,可在对话框标题栏旁自定义额外内容(如按钮、链接等)。
  • 样式

    • 优化对话框标题栏布局,提升 extra 内容的展示效果。
    • 修正关闭按钮透明度样式,提升界面一致性。

Copy link

coderabbitai bot commented May 26, 2025

"""

Walkthrough

本次更改为 Dialog 组件体系引入了一个新的 extra 属性,允许在对话框标题栏旁边自定义渲染额外内容。为此,类型定义、内容渲染逻辑、样式文件及示例文档均进行了相应调整,确保 extra 内容的传递、渲染和样式一致性。

Changes

文件/路径分组 变更摘要
src/IDialogPropTypes.tsx 为 Dialog 类型定义新增可选的 extra: ReactNode 属性。
src/Dialog/Content/Panel.tsx Panel 组件支持 extra 属性,调整 header 渲染逻辑以展示 extra 内容。
src/Dialog/Content/index.tsx Content 组件新增对 extra 的过滤与传递,仅在有效时传递给 Panel。
assets/index/Dialog.less 新增 -extra 样式类,优化 header 布局,修正 close 按钮透明度等。
docs/examples/ant-design.tsx 示例中为 Dialog 组件添加 extra 属性,演示其用法。
tests/index.spec.tsx 新增针对 extra 属性的多种渲染测试用例,覆盖空值和有效内容场景。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dialog
    participant Panel
    participant UI

    User->>Dialog: 传递 extra 属性
    Dialog->>Panel: 传递 extra 属性
    Panel->>UI: 渲染 header(包含 title 和 extra)
    UI-->>User: 显示带有额外内容的 Dialog
Loading

Suggested reviewers

  • thinkasany
  • zombieJ

Poem

兔子写代码,Dialog 新花样,
extra 一加,标题旁边亮。
样式轻轻调,体验更舒畅,
组件更灵活,用户齐点赞。
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/Dialog/Content/index.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/IDialogPropTypes.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

tests/index.spec.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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 (2)
docs/examples/ant-design.tsx (1)

99-99: 示例中的事件处理器命名可能引起混淆

extra 属性中使用的 onClick 处理器与第 40 行定义的 onClick 是同一个函数,这会导致点击 "click me" 链接时触发对话框的打开逻辑,可能不是预期的行为。

建议为演示目的创建一个独立的事件处理器以避免混淆。

+  const onExtraClick = () => {
+    console.log('Extra content clicked');
+  };
+
   const onClick = (e: React.MouseEvent) => {
     setMousePosition({ x: e.pageX, y: e.pageY });
     setVisible1(true);
   };

-      extra={<a onClick={onClick}>click me</a>}
+      extra={<a onClick={onExtraClick}>click me</a>}
src/Dialog/Content/index.tsx (1)

40-44: 简化 hasExtra 验证逻辑

当前的验证逻辑过于复杂,可以简化为更易读的实现。

建议简化为:

-  const hasExtra =
-  extra !== null &&
-  extra !== undefined &&
-  typeof extra !== 'boolean' &&
-  !(typeof extra === 'string' && extra.trim() === '');
+  const hasExtra = extra != null && extra !== false && extra !== '';

这样的实现更简洁,并且能达到相同的效果:过滤掉 nullundefinedfalse 和空字符串。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d998708 and f260866.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/index.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • assets/index/Dialog.less (5 hunks)
  • docs/examples/ant-design.tsx (1 hunks)
  • src/Dialog/Content/Panel.tsx (3 hunks)
  • src/Dialog/Content/index.tsx (2 hunks)
  • src/Dialog/index.tsx (2 hunks)
  • src/IDialogPropTypes.tsx (1 hunks)
🔇 Additional comments (10)
src/Dialog/Content/Panel.tsx (2)

101-108: extraNode 的实现逻辑合理

extraNode 的条件渲染和样式应用逻辑正确,能够正确处理 extra 内容的展示。


110-131:

❓ Verification inconclusive

头部渲染逻辑需要验证设计意图

当没有 title 但有 extra 内容时,代码仍然会渲染一个完整的 header div。请确认这是否符合设计预期,因为这可能会影响样式布局。

建议考虑是否应该在没有 title 且没有 extra 的情况下完全不渲染 header。


🏁 Script executed:

#!/bin/bash
# 搜索相关的样式定义以了解 header 的样式设计意图
rg -A 5 -B 5 "header.*extra|extra.*header" --type css --type less

Length of output: 67


🏁 Script executed:

#!/bin/bash
# 查看 Panel.tsx 顶部逻辑,prefixCls 定义及整体组件结构
sed -n '1,120p' src/Dialog/Content/Panel.tsx

# 对比 footerNode 渲染逻辑,确认是否存在类似的条件判断
rg -n 'footerNode' -C3 src/Dialog/Content/Panel.tsx

Length of output: 3686


验证 Header 渲染逻辑是否符合设计预期

目前无论 titleextra 是否存在,代码都会渲染一个空的 header 容器,这可能会在样式或布局上产生多余的空白或边框。请在以下位置确认设计/样式规范中对 .${prefixCls}-header 的使用要求:

• 文件:src/Dialog/Content/Panel.tsx
行号:大约 110–131

建议考虑将渲染逻辑改为仅在 titleextra 任一存在时才渲染 header,例如:

- const headerNode = title ? (
+ const headerNode = title || extra ? (
    <div className={classNames(`${prefixCls}-header`, modalClassNames?.header)} style={{ ...modalStyles?.header }}>
      {title && (
        <div
          className={classNames(`${prefixCls}-title`, modalClassNames?.title)}
          id={ariaId}
          style={{ ...modalStyles?.title }}
        >
          {title}
        </div>
      )}
      {extraNode}
    </div>
- ) : (
-   <div
-     className={classNames(`${prefixCls}-header`, modalClassNames?.header)}
-     style={{ ...modalStyles?.header }}
-   >
-     {extraNode}
-   </div>
- );
+ ) : null;

请根据样式定义及设计文档,确认是否需要这一调整。

src/IDialogPropTypes.tsx (1)

59-59: 类型定义添加正确

extra?: ReactNode; 的类型定义符合 React 组件属性的标准模式,ReactNode 类型能够支持各种内容类型。

src/Dialog/index.tsx (1)

46-46: extra 属性添加正确

在解构中添加 extra 属性的做法符合组件属性处理的标准模式。

src/Dialog/Content/index.tsx (2)

33-33: 正确添加了 extra 属性解构

从 props 中正确解构出 extra 属性,为后续的条件判断和传递做好准备。


87-87: 正确实现条件传递逻辑

使用 hasExtra 条件来决定是否传递 extra 属性给 Panel 组件,这确保了只有有意义的内容才会被渲染。

assets/index/Dialog.less (4)

25-27: 新增 extra 样式类

为新的 extra 功能添加了合适的样式,padding-right: 36px 确保了与关闭按钮之间有足够的间距。


50-50: 修正了 opacity 值

.2 修正为标准的 0.2,提高了代码的一致性和可读性。


74-76: 增强了 header 布局

添加了 flexbox 属性(display: flexalign-items: centerjustify-content: space-between),这为新的 extra 内容提供了更好的布局支持,确保标题和额外内容能够正确对齐。


95-96: 优化了 CSS 选择器分组

将相似的动画选择器进行了合理分组,减少了代码重复,提高了样式表的可维护性。这是一个很好的代码重构。

Also applies to: 109-110

Copy link

vercel bot commented May 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dialog ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2025 3:22am

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f260866 and 966d318.

📒 Files selected for processing (1)
  • src/Dialog/Content/index.tsx (2 hunks)
🔇 Additional comments (1)
src/Dialog/Content/index.tsx (1)

33-33: 正确添加了 extra 属性的解构赋值。

extra 属性已正确添加到 props 的解构赋值中,这是支持额外内容功能的必要步骤。

Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 97.00%. Comparing base (d998708) to head (5de5100).

Files with missing lines Patch % Lines
src/Dialog/Content/index.tsx 60.00% 2 Missing ⚠️
src/Dialog/Content/Panel.tsx 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #483      +/-   ##
==========================================
- Coverage   98.43%   97.00%   -1.44%     
==========================================
  Files           8        8              
  Lines         192      200       +8     
  Branches       66       74       +8     
==========================================
+ Hits          189      194       +5     
- Misses          3        6       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 a303a44 and f9c344e.

📒 Files selected for processing (3)
  • src/Dialog/Content/index.tsx (2 hunks)
  • src/IDialogPropTypes.tsx (2 hunks)
  • tests/index.spec.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Dialog/Content/index.tsx
  • src/IDialogPropTypes.tsx
🔇 Additional comments (4)
tests/index.spec.tsx (4)

2-2: 导入语句更新合理

新增 screen 导入用于支持新的测试用例,这是一个良好的做法。


737-741: 测试用例实现正确

测试当 extra 为 React 节点时的渲染逻辑,使用了合适的测试 ID 和断言方法。


753-758: 测试用例实现良好

正确测试了非空字符串的渲染逻辑,同时验证了文本内容和 DOM 元素的存在。


760-766: 测试覆盖全面

正确测试了 null 和 undefined 两种边界情况,确保在这些情况下不会渲染 extra 元素。

Comment on lines +748 to +751
it('does not render extra when extra is string with only spaces', () => {
render(<Dialog visible extra=" " />);
expect(screen.queryByText(' ')).toBeNull();
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

测试逻辑需要改进

测试空格字符串的场景很有用,但当前的断言方法不够准确。应该检查 DOM 中是否存在 .rc-dialog-extra 元素。

-    expect(screen.queryByText('   ')).toBeNull();
+    expect(document.querySelector('.rc-dialog-extra')).toBeNull();
📝 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
it('does not render extra when extra is string with only spaces', () => {
render(<Dialog visible extra=" " />);
expect(screen.queryByText(' ')).toBeNull();
});
it('does not render extra when extra is string with only spaces', () => {
render(<Dialog visible extra=" " />);
- expect(screen.queryByText(' ')).toBeNull();
+ expect(document.querySelector('.rc-dialog-extra')).toBeNull();
});
🤖 Prompt for AI Agents
In tests/index.spec.tsx around lines 748 to 751, the test currently checks for
absence of the string with spaces but does not accurately verify if the extra
content is rendered. Update the test to check that the DOM does not contain any
element with the class `.rc-dialog-extra` when extra is a string of only spaces,
ensuring the extra content is truly not rendered.

Comment on lines +743 to +746
it('does not render extra when extra is empty string', () => {
render(<Dialog visible extra="" />);
expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull();
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复测试选择器错误

测试逻辑正确,但选择器使用有误。screen.queryByTestId 应该传入测试 ID,而不是 CSS 选择器。

-    expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull();
+    expect(document.querySelector('.rc-dialog-extra')).toBeNull();
🤖 Prompt for AI Agents
In tests/index.spec.tsx around lines 743 to 746, the test uses
screen.queryByTestId with a CSS selector string '.rc-dialog-extra' instead of
the actual test ID. Fix this by passing the correct test ID string without any
CSS selector syntax to screen.queryByTestId to properly query the element by its
test ID.

Comment on lines +768 to +771
it('renders extra when extra is a non-empty string', () => {
render(<Dialog visible extra="Extra Text" />);
expect(screen.getByText('Extra Text')).toBeInTheDocument();
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

删除重复的测试用例

这个测试用例与第753-758行的测试用例功能重复,都是测试非空字符串的渲染。建议删除以避免冗余。

-  it('renders extra when extra is a non-empty string', () => {
-    render(<Dialog visible extra="Extra Text" />);
-    expect(screen.getByText('Extra Text')).toBeInTheDocument();
-  });
📝 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
it('renders extra when extra is a non-empty string', () => {
render(<Dialog visible extra="Extra Text" />);
expect(screen.getByText('Extra Text')).toBeInTheDocument();
});
🤖 Prompt for AI Agents
In tests/index.spec.tsx around lines 768 to 771, there is a test case that
duplicates the functionality of the test case between lines 753 to 758, both
checking rendering of a non-empty string in the extra prop. Remove the test case
at lines 768 to 771 to eliminate redundancy and keep the test suite concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant