Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Sep 23, 2025

Summary by CodeRabbit

  • 新功能
    • Popup 组件内容区域新增对 className 与 style 的支持,可外部传入样式类与内联样式,便于按需定制主题、间距与布局。
    • 传入的 style 将与组件默认主体样式合并,提升可定制性并减少样式冲突,无需改动组件内部实现。

Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
tooltip Ready Ready Preview Comment Sep 23, 2025 2:31am

Copy link

coderabbitai bot commented Sep 23, 2025

Walkthrough

在 src/Popup.tsx 中为 ContentProps 新增可选的 className 与 style 属性;在组件中解构并将 className 合并到根元素的 className,style 与现有 body 样式进行合并后应用到根 div。

Changes

Cohort / File(s) 摘要
对 Popup 组件开放样式与类名定制
src/Popup.tsx
为 ContentProps 新增 className?: stringstyle?: React.CSSProperties;在 props 解构中加入这两项;根级 div 的 className 增加外部 classNamestyle 由原有 body 样式与外部 style 合并后应用。

Sequence Diagram(s)

sequenceDiagram
    actor Consumer as 使用方
    participant Popup as Popup 组件
    participant DOM as 根 div

    Consumer->>Popup: 传入 { className, style, ... }
    Popup->>Popup: 合并样式(内部bodyStyle ⟶ 外部style)
    Popup->>Popup: 合成 className(内部class ⟶ 外部className)
    Popup->>DOM: 渲染 <div class=... style=...>
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • afc163

Poem

我是一只码田里的兔,蹦跳到 Popup 边沿处。
添个 className,拢个 style 树,
外衣自己穿,内衬我来补。
合并不争吵,样式皆归途,
嘭——一声轻响,弹层更俏酷。 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题直接概括了主要变更:为 Popup 添加对样式注入的支持(新增 className 和 style props 并在根 div 中合并应用)。表述简洁且与变更集高度相关,能让审阅者快速识别 PR 的主要目的。虽然 "style inject" 在语法上略显生硬,但不会影响对修改内容的理解。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch PopupStyle

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces direct styling capabilities to the Popup component. By allowing external className and style props to be passed and applied to the popup's main body element, developers gain greater control over its appearance. This change simplifies custom styling efforts and enhances the component's adaptability within various design systems.

Highlights

  • Enhanced Style Customization: The Popup component now accepts direct className and style props, allowing for more flexible and direct styling of the popup's body element.
  • Prop Type Extension: The ContentProps interface has been extended to include className (string) and style (React.CSSProperties) for the Popup component.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dfc4105) to head (c253b67).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #504   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           37        37           
  Branches        15        15           
=========================================
  Hits            37        37           

☔ 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
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for className and style props to the Popup component, allowing for more direct styling. The implementation is straightforward and correct. I have one suggestion for a performance improvement regarding the creation of the style object, which could be beneficial given that this component is used for tooltips that may re-render frequently.

className={cls(`${prefixCls}-body`, classNames?.body)}
style={styles?.body}
className={cls(`${prefixCls}-body`, classNames?.body, className)}
style={{ ...styles?.body, ...style }}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For performance, it's better to memoize this style object to avoid creating a new one on every render. This is especially important for components like tooltips that can re-render frequently on user interactions like hover. You can use React.useMemo here to prevent unnecessary re-renders of child components and reduce the overhead of React's reconciliation process.

Suggested change
style={{ ...styles?.body, ...style }}
style={React.useMemo(() => ({ ...styles?.body, ...style }), [styles, style])}

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 dfc4105 and c253b67.

📒 Files selected for processing (1)
  • src/Popup.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: thinkasany
PR: react-component/tooltip#484
File: src/Popup.tsx:20-25
Timestamp: 2024-11-28T13:00:19.052Z
Learning: `overlayInnerClassName` 属性在 `Popup.tsx` 中是供内部使用的,已经通过 `classNames.inner` 在现有的测试用例中得到验证,无需单独添加测试。
📚 Learning: 2024-11-28T13:00:19.052Z
Learnt from: thinkasany
PR: react-component/tooltip#484
File: src/Popup.tsx:20-25
Timestamp: 2024-11-28T13:00:19.052Z
Learning: `overlayInnerClassName` 属性在 `Popup.tsx` 中是供内部使用的,已经通过 `classNames.inner` 在现有的测试用例中得到验证,无需单独添加测试。

Applied to files:

  • src/Popup.tsx
🔇 Additional comments (3)
src/Popup.tsx (3)

11-12: 新增属性类型定义看起来正确。

ContentProps 接口添加 classNamestyle 属性,类型定义合适,都是可选的。这样的设计允许外部组件传入自定义的类名和样式。


16-16: 解构赋值正确添加了新属性。

在解构赋值中正确包含了新增的 classNamestyle 属性,与接口定义保持一致。


21-22: 样式和类名合并逻辑实现正确。

  • 第21行:使用 cls 函数正确合并了 prefixCls-bodyclassNames?.body 和新增的 className
  • 第22行:使用对象展开语法正确合并了 styles?.body 和新增的 style,新传入的样式会覆盖相同属性的默认样式

这种实现方式符合React组件的常见模式,优先级处理也很合理。

Comment on lines +11 to +12
className?: string;
style?: React.CSSProperties;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

🧩 Analysis chain

验证新增属性的使用是否与现有测试兼容。

根据学习记录,overlayInnerClassName 等内部属性已有相应测试覆盖。建议验证新增的 classNamestyle 属性是否会影响现有的测试用例。

运行以下脚本来检查相关测试文件和使用情况:

Also applies to: 16-16, 21-22


🏁 Script executed:

#!/bin/bash
# 描述:检查 Popup 组件的测试文件和使用情况

# 查找测试文件
echo "=== 查找 Popup 相关测试文件 ==="
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts | xargs rg -l "Popup|ContentProps"

# 查找 Popup 组件的使用情况
echo -e "\n=== 查找 Popup 组件使用情况 ==="
rg -n -C3 "ContentProps|<Popup" --type=tsx --type=ts

# 检查是否有现有的 className 或 style 相关测试
echo -e "\n=== 检查现有的 className 和 style 测试 ==="
rg -n -C3 "className.*body|style.*body" --type=tsx --type=ts -g '!node_modules'

Length of output: 161


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== tests/popup.test.tsx ==="
sed -n '1,400p' tests/popup.test.tsx || true

echo -e "\n=== src/Popup.tsx (first 200 lines) ==="
sed -n '1,200p' src/Popup.tsx || true

echo -e "\n=== Search overlayInnerClassName across repo ==="
rg -n --hidden -S "overlayInnerClassName" -g '!*node_modules*' || true

echo -e "\n=== Search for className/style mentions in tests ==="
rg -n --hidden -S "className|style" tests -g '!*node_modules*' || true

echo -e "\n=== Search for Popup usages across repo ==="
rg -n --hidden -S "<Popup\b|\bContentProps\b" -g '**/*.{ts,tsx,js,jsx,ts,tsx}' || true

Length of output: 1506


为 Popup 新增的 className/style 添加或更新测试

tests/popup.test.tsx 仅断言导出;src/Popup.tsx 已在接口中接收并将 className/style 合并到渲染的 div(行 11–12),但没有针对 className/style 的测试覆盖。请新增或更新测试以覆盖:1) className 与 classNames.body 的合并行为;2) style 与 styles.body 的合并行为;并确认 src/Tooltip.tsx:132 与 docs/examples/placement.tsx:95 的使用不受影响。

🤖 Prompt for AI Agents
In src/Popup.tsx around lines 11 to 12, the component accepts className and
style but tests don't verify that these are merged with classNames.body and
styles.body; update tests/popup.test.tsx to (1) render Popup with a custom
className and assert the rendered div contains both the custom className and
classNames.body (use container.querySelector or getByTestId on the body div);
(2) render Popup with a custom style (e.g., { color: 'red' }) and assert the
rendered div's style includes both the custom style and styles.body properties
(merged correctly); keep the existing export assertion in the test file and add
assertions that src/Tooltip.tsx line 132 and docs/examples/placement.tsx line 95
usages remain valid by ensuring the test cases use the same props shapes so
those usages are not broken.

@zombieJ zombieJ merged commit d771343 into master Sep 23, 2025
10 checks passed
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