Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Sep 19, 2025

给 unique body 添加 css var,用于上游计算。

Copy link

coderabbitai bot commented Sep 19, 2025

Warning

Rate limit exceeded

@zombieJ has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 70d31f3 and aebf0f5.

📒 Files selected for processing (3)
  • src/UniqueProvider/UniqueBody.tsx (4 hunks)
  • src/UniqueProvider/index.tsx (1 hunks)
  • tests/unique.test.tsx (2 hunks)

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.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch missing-arrow-var

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!

此拉取请求旨在通过在 UniqueBody 组件中引入 CSS 变量来增强其灵活性,特别是针对箭头定位。这些变量 (--arrow-x--arrow-y) 允许上游组件(如 UniqueProvider)动态计算并设置箭头的精确位置,从而实现更精细的 UI 布局控制和样式定制。

Highlights

  • 引入箭头位置 CSS 变量: 在 UniqueBody 组件中引入了 --arrow-x--arrow-y CSS 变量,用于动态控制箭头的水平和垂直位置。
  • 传递箭头位置数据: UniqueProvider 组件现在会将计算出的箭头坐标 (arrowX, arrowY) 作为 arrowPos 属性传递给 UniqueBody
  • 更新类型定义: 增加了 ArrowPos 类型定义,并将其添加到 UniqueBodyProps 接口中。
  • 新增测试用例: 增加了测试,以确保在 Trigger 组件中启用箭头居中时,UniqueBody 元素上的 CSS 变量被正确设置。
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
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 主要为 UniqueBody 组件添加了 --arrow-x--arrow-y 两个 CSS 自定义属性,以便将箭头位置信息暴露给 CSS 进行计算,这是一个很好的改进。代码实现基本正确,并且更新了测试用例以覆盖新功能。

我提出了一些建议以提高代码的健壮性和可维护性:

  1. UniqueBody.tsx 中,建议使用 ?? 操作符代替 || 来处理默认值,并考虑使用模块扩展来代替类型断言,以增强类型安全。
  2. unique.test.tsx 中,建议增强测试断言,以更精确地验证 CSS 变量值的格式。

整体来看,这是一个不错的更新,采纳建议后代码质量会更高。

Comment on lines +89 to +90
'--arrow-x': `${arrowPos?.x || 0}px`,
'--arrow-y': `${arrowPos?.y || 0}px`,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

建议使用空值合并操作符(??)代替逻辑或操作符(||),以更明确地处理 nullundefined 的情况。当 arrowPos.xarrowPos.y 的值为 0 时,||?? 的行为一致,但 ?? 能更清晰地表达“仅在值为 nullundefined 时提供默认值”的意图,这是更健壮的做法。

Suggested change
'--arrow-x': `${arrowPos?.x || 0}px`,
'--arrow-y': `${arrowPos?.y || 0}px`,
'--arrow-x': `${arrowPos?.x ?? 0}px`,
'--arrow-y': `${arrowPos?.y ?? 0}px`,

...motionStyle,
...uniqueBgStyle,
}}
} as React.CSSProperties}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

使用 as React.CSSProperties 类型断言来支持 CSS 自定义属性虽然可行,但它会削弱类型安全。一个更佳的实践是使用模块扩展(module augmentation)来为 React.CSSProperties 接口添加自定义属性的类型定义。这样可以在整个项目中安全地使用这些属性,而无需每次都进行类型断言。

你可以在项目中创建一个 .d.ts 类型声明文件(例如 react.d.ts),并添加以下内容:

import 'react';

declare module 'react' {
  interface CSSProperties {
    '--arrow-x'?: string;
    '--arrow-y'?: string;
  }
}

应用此更改后,就可以移除此处的 as React.CSSProperties 类型断言了。

Comment on lines +254 to +255
expect(computedStyle.getPropertyValue('--arrow-x')).not.toBe('');
expect(computedStyle.getPropertyValue('--arrow-y')).not.toBe('');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

当前的测试断言 not.toBe('') 只能验证 CSS 变量已被设置,但不够健壮。例如,如果值是 0px(默认值),测试也会通过。为了使测试更精确,建议使用正则表达式来验证值的格式是否为有效的像素值。这可以确保不仅设置了变量,而且其值符合预期格式。

Suggested change
expect(computedStyle.getPropertyValue('--arrow-x')).not.toBe('');
expect(computedStyle.getPropertyValue('--arrow-y')).not.toBe('');
expect(computedStyle.getPropertyValue('--arrow-x')).toMatch(/-?\d+(\.\d+)?px/);
expect(computedStyle.getPropertyValue('--arrow-y')).toMatch(/-?\d+(\.\d+)?px/);

Copy link

codecov bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.05%. Comparing base (70d31f3) to head (aebf0f5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #577   +/-   ##
=======================================
  Coverage   96.04%   96.05%           
=======================================
  Files          17       17           
  Lines         936      938    +2     
  Branches      274      267    -7     
=======================================
+ Hits          899      901    +2     
  Misses         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.

@zombieJ zombieJ merged commit 46600c0 into master Sep 19, 2025
10 checks passed
@zombieJ zombieJ deleted the missing-arrow-var branch September 19, 2025 09:19
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