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: supports classnames & styles #484

Merged
merged 4 commits into from
Nov 29, 2024

Conversation

thinkasany
Copy link
Contributor

@thinkasany thinkasany commented Nov 28, 2024

ant-design/ant-design#51814

Summary by CodeRabbit

更新后的版本说明

  • 新功能

    • Popup 组件中添加了可选属性 innerClassName,增强了内层覆盖层的样式灵活性。
    • Tooltip 组件中添加了 stylesclassNames 属性,允许用户自定义工具提示的样式和类名。
  • 测试

    • Tooltip 组件添加了新测试用例,以验证自定义样式和类名的应用。

Copy link

vercel bot commented Nov 28, 2024

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

Name Status Preview Comments Updated (UTC)
tooltip ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2024 2:55am

Copy link

coderabbitai bot commented Nov 28, 2024

Walkthrough

本次更改涉及对 PopupTooltip 组件的增强。Popup 组件新增了可选属性 innerClassName,允许用户为内部覆盖层 div 添加额外的类名,并将 overlayInnerStyle 重命名为 innerStyleTooltip 组件则引入了新的属性 stylesclassNames,使得用户可以自定义工具提示的根元素和内部元素的样式和类名。此外,相关的测试用例也进行了更新,以验证这些新功能的正确性。

Changes

文件 更改摘要
src/Popup.tsx 新增可选属性 innerClassNameContentProps 接口,更新 Popup 函数以支持该属性,并将 overlayInnerStyle 重命名为 innerStyle
src/Tooltip.tsx 新增属性 stylesclassNamesTooltipProps 接口,定义 TooltipStylesTooltipClassNames 接口,更新 Tooltip 组件以应用新属性。
tests/index.test.tsx 新增测试用例验证 Tooltip 组件的自定义样式和类名应用,确保渲染的工具提示包含预期的类名和样式。

Poem

在兔子洞里,样式新添,
PopupTooltip,更灵活变迁。
类名和样式,随心所欲,
兔子欢跳,庆祝这变化的路!
🐰✨

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/Popup.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d8f8ae9 and 4691dbb.

📒 Files selected for processing (2)
  • src/Popup.tsx (1 hunks)
  • src/Tooltip.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Popup.tsx
  • src/Tooltip.tsx

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.

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 (4)
src/Popup.tsx (1)

15-16: 属性解构合理,但建议优化代码格式

props 解构的更新正确包含了新增的 overlayInnerClassName 属性。

建议应用以下格式优化,使代码更易读:

-  const { children, prefixCls, id, overlayInnerStyle, overlayInnerClassName, className, style } =
-    props;
+  const {
+    children,
+    prefixCls,
+    id,
+    overlayInnerStyle,
+    overlayInnerClassName,
+    className,
+    style,
+  } = props;
src/Tooltip.tsx (1)

46-47: 建议添加属性文档注释

为了提高代码的可维护性和使用体验,建议为新添加的 stylesclassNames 属性添加 JSDoc 文档注释,说明其用途和使用方式。

+/** 自定义样式配置对象,可分别设置根元素和内部元素的样式 */
 styles?: TootipStyles;
+/** 自定义类名配置对象,可分别设置根元素和内部元素的类名 */
 classNames?: TooltipClassNames;
tests/index.test.tsx (2)

265-269: 建议增加更多边界测试场景

当前测试用例仅验证了基本功能,建议添加以下场景:

  • 样式和类名为空对象的情况
  • 样式值包含特殊字符的情况
  • 类名包含多个空格的情况

254-284: 建议添加异步交互测试

当前测试用例只验证了初始渲染状态,建议添加以下场景:

  • 动态更新样式和类名
  • 切换可见性时样式和类名的保留情况
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f093bde and be4c18d.

📒 Files selected for processing (3)
  • src/Popup.tsx (1 hunks)
  • src/Tooltip.tsx (5 hunks)
  • tests/index.test.tsx (1 hunks)
🔇 Additional comments (3)
src/Popup.tsx (1)

11-11: 接口扩展符合预期

新增的 overlayInnerClassName 属性类型定义正确,可选参数的设计也合理。这样的扩展不会影响现有代码的兼容性。

src/Tooltip.tsx (1)

100-106: 实现看起来不错,建议验证样式优先级

样式和类名的合并实现正确,使用了适当的展开运算符来合并样式对象。建议验证样式优先级是否符合预期,特别是在覆盖默认样式时。

Also applies to: 113-113, 130-130

✅ Verification successful

样式优先级实现已得到验证

代码中的样式优先级处理已经得到正确实现:

  • overlayInnerStyle 中,通过展开运算符确保 tooltipStyles?.inner 在后,可以覆盖默认样式
  • 测试文件中包含了样式覆盖的测试用例,验证了自定义样式可以正确覆盖默认样式
  • classNames 工具函数的使用确保了类名的正确组合
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否有相关的测试用例验证样式优先级

# 搜索测试文件中的相关测试用例
rg -l "styles.*root|classNames.*root" tests/

Length of output: 46


Script:

#!/bin/bash
# 搜索 Tooltip 相关的测试文件
fd "tooltip.*\.(test|spec)\.(ts|tsx|js|jsx)" -i

# 搜索测试文件中的样式相关测试
rg -i "style|classname" --type ts --type tsx --type js --type jsx -A 5 "tests/"

# 检查 Tooltip 组件中的样式处理
ast-grep --pattern 'overlayInnerStyle = { $$ }'

# 搜索样式优先级相关的测试用例
rg -i "tooltip.*style.*priority|style.*priority.*tooltip" --type ts --type tsx --type js --type jsx

Length of output: 337


Script:

#!/bin/bash
# 搜索 Tooltip 相关的测试文件,不指定文件类型让 fd 自动处理
fd "tooltip.*test" -i

# 搜索样式相关的代码实现
rg "overlayInnerStyle|tooltipStyles" -A 3

# 搜索样式相关的测试用例
rg "style.*test|test.*style" -A 3

# 检查是否有样式覆盖的相关实现
rg "overlayInnerClassName|tooltipClassNames" -A 3

Length of output: 4549

tests/index.test.tsx (1)

254-264: 测试用例的设置结构清晰明确

测试数据的准备工作组织得当,通过分别定义 customClassNamescustomStyles 对象使得测试意图明确。

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

🧹 Outside diff range and nitpick comments (2)
src/Tooltip.tsx (2)

100-106: 建议增加样式合并的类型安全性

当前的样式合并实现功能正确,但建议添加空值检查以提高代码的健壮性。

-overlayInnerStyle={{ ...overlayInnerStyle, ...tooltipStyles?.inner }}
+overlayInnerStyle={{ 
+  ...(overlayInnerStyle || {}), 
+  ...(tooltipStyles?.inner || {})
+}}

113-113: 保持样式处理的一致性

为了保持代码一致性,建议对 popupStyle 的样式合并也添加相同的空值检查。同时,classNames 工具的使用非常恰当。

-popupStyle={{ ...overlayStyle, ...tooltipStyles?.root }}
+popupStyle={{ 
+  ...(overlayStyle || {}), 
+  ...(tooltipStyles?.root || {})
+}}

Also applies to: 130-130

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between be4c18d and 83ad8a3.

📒 Files selected for processing (1)
  • src/Tooltip.tsx (5 hunks)
🔇 Additional comments (2)
src/Tooltip.tsx (2)

8-8: 接口设计清晰且符合 React 规范!

新增的 TooltipStylesTooltipClassNames 接口设计合理,类型定义准确,并且与 React 组件的样式自定义模式保持一致。

Also applies to: 46-57


86-87: 属性解构合理!

tooltipClassNamestooltipStyles 的命名清晰,解构位置恰当,与其他样式相关属性放在一起便于维护。

src/Popup.tsx Outdated
@@ -8,14 +8,21 @@ export interface ContentProps {
overlayInnerStyle?: React.CSSProperties;
className?: string;
style?: React.CSSProperties;
overlayInnerClassName?: string;
Copy link
Member

Choose a reason for hiding this comment

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

这个要废弃的,不加新的了吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个是为了让 classnames.inner 的class进入到 `${prefixCls}-inner` 这边的class里面,原来已经暴露了一个classname用于content, popup 在其他地方另外有使用。 这个api可以在antd不对外暴露,不写入类型,推荐用户使用classnames.inner
image
image

Copy link
Member

Choose a reason for hiding this comment

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

overlayInnerClassName 和 overlayInnerStyle 改为 innerStyle 和 innerClassName 吧,overlay 在这里是多余的语义。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

overlayInnerStyle 是历史遗留问题,要改的话也只能变成 const { overlayInnerStyle: innerStyle } = props;
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

innerClassName 改好了,innerStyle 只能用别名的方式来了,毕竟popup这个组件导出在外部组件可用,不太能动了,不然可能引发break

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f093bde) to head (4691dbb).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #484   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           26        26           
  Branches        10        10           
=========================================
  Hits            26        26           

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

@afc163 afc163 merged commit 13d7b7a into react-component:master Nov 29, 2024
9 checks passed
@afc163
Copy link
Member

afc163 commented Nov 29, 2024

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.

2 participants