Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Sep 18, 2025

Summary by CodeRabbit

  • 新功能
    • Trigger 新增 uniqueBgClassName、uniqueBgStyle,用于自定义弹层 FloatBg 的类名与内联样式;通过 UniqueProvider 传递,支持更灵活的背景定制且不影响现有行为。
  • 测试
    • 新增用例验证自定义类名与样式在弹层背景上生效,以及未提供时不产生多余类名。
  • 杂务
    • 将 dist/ 加入 .gitignore,避免提交构建产物。

Copy link

coderabbitai bot commented Sep 18, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

本次变更新增并透传两个可选属性 uniqueBgClassNameuniqueBgStyle:从 Trigger 暴露、经 context 与 UniqueProvider 传递,最终应用到 FloatBg 的 className 与 style;补充对应类型声明和测试用例,并在 .gitignore 中新增忽略 dist/

Changes

Cohort / File(s) Change Summary
Git 忽略规则
\.gitignore
新增忽略目录 dist/.dumi/tmp-production 忽略项保持不变(中间变动为临时删除再添加,效果保持)。
FloatBg 组件扩展
src/UniqueProvider/FloatBg.tsx
FloatBgProps 中新增 uniqueBgClassName?: stringuniqueBgStyle?: React.CSSProperties;渲染时将 uniqueBgClassName 合并到 className,并将 uniqueBgStyle 与现有 style 合并到内联 style。
UniqueProvider 透传
src/UniqueProvider/index.tsx
options 中读取并向 FloatBg 透传 uniqueBgClassNameuniqueBgStyle,其它逻辑未变。
上下文类型
src/context.ts
UniqueShowOptions 中新增 uniqueBgClassName?: stringuniqueBgStyle?: React.CSSProperties
对外 API(Trigger)
src/index.tsx
TriggerProps 中新增 uniqueBgClassName?: stringuniqueBgStyle?: React.CSSProperties;在 generateTrigger 中解构并将其放入 getUniqueOptions 的 payload。
测试用例
tests/unique.test.tsx
新增或修改测试:验证在 unique 场景下 FloatBg 正确接收并应用 uniqueBgClassNameuniqueBgStyle,以及当未提供时不产生无效类名。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as 用户
  participant T as Trigger
  participant G as generateTrigger / getUniqueOptions
  participant P as UniqueProvider
  participant F as FloatBg

  Note over T,G: Trigger 构建 uniqueOptions(含 uniqueBgClassName/uniqueBgStyle)
  U->>T: render({ unique, uniqueBgClassName, uniqueBgStyle })
  T->>G: build UniqueShowOptions
  G-->>T: UniqueShowOptions
  T->>P: show(uniqueOptions)
  P->>F: render FloatBg(props + uniqueBgClassName/uniqueBgStyle)
  F-->>U: DOM: `.rc-trigger-popup-float-bg`(含合并后的 className 与 inline style)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • MadCcc

Poem

兔子轻踏代码田,
背景花纹随心变,
class 与 style 双手牵,
浮影落成测例全,
dist 在.gitignore里安眠 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive 标题 “feat: Support uniqueBgXXX for additional passing” 与本次改动新增 uniqueBgClassName 与 uniqueBgStyle 并向下透传的意图相关,但使用了占位符 “XXX” 和模糊的 “additional passing” 表述,语义不够具体或简洁,无法让审阅者一眼看出主要改动点。 建议将标题改为更明确的形式,例如:"feat: add uniqueBgClassName and uniqueBgStyle pass-through to FloatBg" 或 "feat: pass uniqueBgClassName/uniqueBgStyle through Trigger → UniqueProvider → FloatBg",以便清晰反映主要变更并便于历史检索。
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 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 b83963f and 78e69e1.

📒 Files selected for processing (1)
  • tests/unique.test.tsx (3 hunks)

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

@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.

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 enhances the customization capabilities of the UniqueProvider's FloatBg component by introducing new properties that allow developers to apply custom CSS classes and inline styles to its background. This provides greater flexibility for styling unique popup elements without modifying core component logic.

Highlights

  • New Styling Props for FloatBg: Introduced uniqueBgClassName and uniqueBgStyle props to the FloatBg component, allowing for custom CSS classes and inline styles to be applied directly to the background element of unique popups.
  • Propagate Styling Options: The new uniqueBgClassName and uniqueBgStyle props are now propagated through UniqueShowOptions and TriggerProps, making them accessible from the main Trigger component.
  • Comprehensive Test Coverage: Added new test cases to unique.test.tsx to ensure that uniqueBgClassName and uniqueBgStyle are correctly applied and function as expected on the FloatBg component.
  • Build Artifact Exclusion: The .gitignore file has been updated to include dist/, preventing build output directories from being committed to the repository.
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
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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
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 introduces support for uniqueBgClassName and uniqueBgStyle props to allow custom styling of the FloatBg component when using a UniqueProvider. The changes are well-implemented, passing the new props through the component hierarchy from Trigger to FloatBg. The feature is also accompanied by comprehensive tests that validate the new functionality. My feedback focuses on improving the robustness of one of the new test assertions.

Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.72%. Comparing base (0c60e16) to head (78e69e1).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #574   +/-   ##
=======================================
  Coverage   95.72%   95.72%           
=======================================
  Files          17       17           
  Lines         936      936           
  Branches      265      265           
=======================================
  Hits          896      896           
  Misses         40       40           

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

@zombieJ
Copy link
Member Author

zombieJ commented Sep 18, 2025

@gemini-code-assist CR again

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

本次 PR 新增了 uniqueBgClassNameuniqueBgStyle 属性,用于在 unique 模式下自定义 Trigger 的背景,增强了组件的灵活性。代码实现清晰,通过 Trigger -> UniqueProvider -> FloatBg 的属性传递,逻辑正确。同时,PR 也包含了相应的单元测试来验证新功能,并更新了 .gitignore 文件,整体质量很高。我只有一个关于测试代码重构的建议,以提高其可维护性。

Comment on lines 156 to 249
it('should apply uniqueBgClassName to FloatBg component', async () => {
const { container } = render(
<UniqueProvider>
<Trigger
action={['click']}
popup={<strong className="x-content">tooltip</strong>}
unique
uniqueBgClassName="custom-bg-class"
>
<div className="target">click me</div>
</Trigger>
</UniqueProvider>,
);

// Initially no popup should be visible
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();

// Click trigger to show popup
fireEvent.click(container.querySelector('.target'));
await awaitFakeTimer();

// Check that popup exists
const popup = document.querySelector('.rc-trigger-popup');
expect(popup).toBeTruthy();

// Check that FloatBg has the custom background className
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
expect(floatBg).toBeTruthy();
expect(floatBg.className).toContain('custom-bg-class');
});

it('should apply uniqueBgStyle to FloatBg component', async () => {
const { container } = render(
<UniqueProvider>
<Trigger
action={['click']}
popup={<strong className="x-content">tooltip</strong>}
unique
uniqueBgStyle={{ backgroundColor: 'red', border: '1px solid blue' }}
>
<div className="target">click me</div>
</Trigger>
</UniqueProvider>,
);

// Initially no popup should be visible
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();

// Click trigger to show popup
fireEvent.click(container.querySelector('.target'));
await awaitFakeTimer();

// Check that popup exists
const popup = document.querySelector('.rc-trigger-popup');
expect(popup).toBeTruthy();

// Check that FloatBg has the custom background style
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
expect(floatBg).toBeTruthy();
expect(floatBg).toHaveStyle({
backgroundColor: 'red',
border: '1px solid blue',
});
});

it('should not apply any additional className to FloatBg when uniqueBgClassName is not provided', async () => {
const { container } = render(
<UniqueProvider>
<Trigger
action={['click']}
popup={<strong className="x-content">tooltip</strong>}
unique
>
<div className="target">click me</div>
</Trigger>
</UniqueProvider>,
);

// Initially no popup should be visible
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();

// Click trigger to show popup
fireEvent.click(container.querySelector('.target'));
await awaitFakeTimer();

// Check that popup exists
const popup = document.querySelector('.rc-trigger-popup');
expect(popup).toBeTruthy();

// Check that FloatBg exists but does not have custom background className
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
expect(floatBg).toBeTruthy();
expect(floatBg.className).not.toContain('undefined');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

这三个新的测试用例 (should apply uniqueBgClassName..., should apply uniqueBgStyle..., should not apply any additional className...) 中存在较多重复的设置代码,例如渲染组件、触发弹窗和检查弹窗是否可见的逻辑。

为了提高测试代码的可读性和可维护性,建议将这部分通用的设置逻辑提取到一个辅助函数中。这样可以让每个测试用例更专注于其核心的断言逻辑,使代码更简洁。

例如,可以创建一个这样的辅助函数:

async function setupAndOpenPopup(triggerProps: Partial<TriggerProps> = {}) {
  const { container } = render(
    <UniqueProvider>
      <Trigger
        action={['click']}
        popup={<strong className="x-content">tooltip</strong>}
        unique
        {...triggerProps}
      >
        <div className="target">click me</div>
      </Trigger>
    </UniqueProvider>,
  );

  // Initially no popup should be visible
  expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();

  // Click trigger to show popup
  fireEvent.click(container.querySelector('.target'));
  await awaitFakeTimer();

  // Check that popup exists
  const popup = document.querySelector('.rc-trigger-popup');
  expect(popup).toBeTruthy();

  return { container, popup };
}

然后测试用例可以简化为:

it('should apply uniqueBgClassName to FloatBg component', async () => {
  await setupAndOpenPopup({ uniqueBgClassName: 'custom-bg-class' });

  const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
  expect(floatBg).toBeTruthy();
  expect(floatBg.className).toContain('custom-bg-class');
});

@zombieJ zombieJ merged commit 5a50916 into master Sep 18, 2025
9 checks passed
@zombieJ zombieJ deleted the bg branch September 18, 2025 09:35
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 (4)
src/UniqueProvider/FloatBg.tsx (1)

86-91: 用户样式可能覆盖动画内联样式(transform/opacity/transition)

uniqueBgStyle 放在最后会覆盖 motionStyle 与定位样式,若用户传入 transform/opacity/transition,可能破坏入场/离场动画或定位。建议至少在文档中提示“避免设置这些关键属性”,或在此处做白名单/黑名单保护。

可选思路(其一:仅文档告警):

  • 在 TriggerProps 的 JSDoc 处补充:避免在 uniqueBgStyle 中设置 transform/opacity/transition。

可选思路(其二:运行时保护,避免覆盖关键属性):

-            style={{
-              ...offsetStyle,
-              ...sizeStyle,
-              ...motionStyle,
-              ...uniqueBgStyle,
-            }}
+            style={{
+              ...offsetStyle,
+              ...sizeStyle,
+              ...motionStyle,
+              // 仅当未提供这些关键属性时再合并(示例)
+              ...(uniqueBgStyle?.transform !== undefined ||
+              uniqueBgStyle?.opacity !== undefined ||
+              uniqueBgStyle?.transition !== undefined
+                ? {}
+                : uniqueBgStyle),
+            }}
src/UniqueProvider/index.tsx (1)

158-158: prefixCls 建议加兜底,避免外部误用导致 undefined

UniqueProvider 主要由 Trigger 驱动,但接口是导出的。为稳妥起见可在此增加默认值,避免外部直接调用 show 时未提供 prefixCls 导致类名异常。

-  const prefixCls = options?.prefixCls;
+  const prefixCls = options?.prefixCls ?? 'rc-trigger-popup';
src/index.tsx (1)

101-104: 新增 props 与透传链路完整

  • TriggerProps 新增 uniqueBgClassName/uniqueBgStyle,命名与语义清晰;
  • generateTrigger 中解构并在 getUniqueOptions 中传递,配合 UniqueProvider/FloatBg 完成闭环。

建议在这两处 JSDoc 补充提示:uniqueBgStyle 中请避免设置 transform/opacity/transition 以免影响动画。

如需,我可以顺手提交一版 JSDoc 与 README 片段更新。

Also applies to: 176-178, 332-334

tests/unique.test.tsx (1)

187-219: 用 computedStyle 断言在 JSDOM 下可能不稳定,建议改为读取行内样式

JSDOM 对样式计算存在差异,backgroundColor 可能变为 rgb(...);改为断言元素的行内样式更稳。

应用此 diff 改进断言稳定性:

-    const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
-    expect(floatBg).toBeTruthy();
-    const computedStyle = window.getComputedStyle(floatBg);
-    expect(computedStyle.backgroundColor).toBe('red');
-    expect(computedStyle.border).toContain('1px solid blue');
+    const floatBg = document.querySelector('.rc-trigger-popup-float-bg') as HTMLElement;
+    expect(floatBg).toBeTruthy();
+    const style = floatBg.style;
+    expect(style.backgroundColor).toBe('red');
+    expect(style.border).toBe('1px solid blue');
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c60e16 and b83963f.

📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • src/UniqueProvider/FloatBg.tsx (4 hunks)
  • src/UniqueProvider/index.tsx (1 hunks)
  • src/context.ts (1 hunks)
  • src/index.tsx (3 hunks)
  • tests/unique.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/unique.test.tsx (1)
tests/util.tsx (1)
  • awaitFakeTimer (97-104)
🔇 Additional comments (6)
src/context.ts (1)

23-24: 为 UniqueShowOptions 新增 uniqueBgClassName/uniqueBgStyle 定义合理

类型与后续透传一致,命名与 popupClassName/popupStyle 对齐,易理解。

src/UniqueProvider/FloatBg.tsx (1)

20-21: className 透传实现到位

将 uniqueBgClassName 直接并入 classNames,undefined/空字符串会被忽略,不会出现 'undefined' 类名污染(测试已覆盖)。

Also applies to: 37-39, 79-81

src/UniqueProvider/index.tsx (1)

219-221: 透传到 FloatBg 的实现正确

uniqueBgClassName / uniqueBgStyle 均从 options 透传,符合上下文设计。

tests/unique.test.tsx (2)

156-185: 验证 className 透传的用例到位

覆盖了自定义类名命中 FloatBg 的主路径,能够有效防回归。


220-248: 避免 'undefined' 类名的用例很实用

能直接捕捉 classNames 合并失误,保留该用例有价值。

.gitignore (1)

42-43: 结论:dist/ 不会随 npm 发布 — 需确认发版策略

package.json 的 "files" 字段为 ["es","lib","assets//*.css","assets//*.less"],且仓库无 .npmignore;npm publish 会以 files 为白名单(若无 .npmignore 则会参考 .gitignore),因此 dist/(已在 .gitignore 中)不会包含在发布包中。

建议(任选其一):

  • 若需发布 dist:在 package.json 的 files 中加入 "dist";
  • 或让 CI 把构建产物输出到已包含的目录(es 或 lib);
  • 不推荐:直接提交 dist 到仓库并移除 .gitignore 中的 dist/。

位置提示:.gitignore(Lines 42-43),package.json(仓库根目录)。

This was referenced Sep 19, 2025
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