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

fix: repair spin classname is invalid without tip #766

Merged
merged 2 commits into from
Oct 30, 2024
Merged

Conversation

zyfwudi
Copy link
Collaborator

@zyfwudi zyfwudi commented Oct 30, 2024

Types of changes

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Others

Changelog

  • 修复Spin组件当不存在tip时,className失效问题

Summary by CodeRabbit

  • 新功能

    • Spin 组件中添加了 uniqueClassName 属性,以增强类名生成。
    • 多个旋转变体组件(如 DefaultChasingDots 等)现在支持 uniqueClassName 属性。
  • 修复

    • 组件渲染逻辑优化,确保在有提示时不传递 className 属性。

Copy link

coderabbitai bot commented Oct 30, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (4)
  • packages/shineout/src/button/__test__/__snapshots__/button.spec.tsx.snap is excluded by !**/*.snap
  • packages/shineout/src/image/__test__/__snapshots__/image.spec.tsx.snap is excluded by !**/*.snap
  • packages/shineout/src/transfer/__test__/__snapshots__/transfer.spec.tsx.snap is excluded by !**/*.snap
  • packages/shineout/src/upload/__test__/__snapshots__/upload.spec.tsx.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

该拉取请求对 Spin 组件进行了修改,主要新增了 uniqueClassName 属性,以增强组件的类名生成逻辑。此外,renderSpin 函数中的 className 属性的传递逻辑也进行了调整,使其在 tip 变量为真时不传递该属性。多个旋转变体组件中,className 属性被替换为 uniqueClassName,确保每个旋转变体可以应用独特的样式。整体逻辑和结构保持不变。

Changes

文件路径 更改摘要
packages/base/src/spin/base.tsx 新增 uniqueClassName 属性到 Spin 组件的 props 中,增强类名生成逻辑。
packages/base/src/spin/spin.tsx 修改 renderSpin 函数,条件性地传递 className 属性,仅在 tip 为假时才传递。
packages/base/src/spin/spin.type.ts BaseSpinProps 接口中新增可选属性 uniqueClassName,类型为 string
packages/base/src/spin/spins.tsx 多个旋转变体组件中将 className 属性替换为 uniqueClassName,保持样式值一致。

Possibly related PRs

Suggested labels

bug

Poem

🐰 在旋转的世界里,
新增名号真奇妙,
唯一的称号闪耀,
旋转舞动不再少。
兔子欢呼声嘹亮,
风中舞姿轻盈跳! 🌟


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: 1

🧹 Outside diff range and nitpick comments (3)
packages/base/src/spin/spin.type.ts (1)

76-76: 建议为 uniqueClassName 添加 JSDoc 注释

为了保持代码文档的一致性,建议添加与其他属性相同风格的 JSDoc 注释,说明该属性的用途。

建议添加如下注释:

+  /**
+   * @en Unique className for the spin component
+   * @cn Spin 组件的唯一类名
+   */
   uniqueClassName?: string
packages/base/src/spin/spin.tsx (1)

78-78: 修复逻辑正确,建议添加注释说明

className 的条件传递逻辑修复了没有 tip 时样式失效的问题。建议添加注释说明这个行为。

建议添加如下注释:

+      // 当有 tip 时,className 应用在外层容器上
+      // 当没有 tip 时,className 直接应用在 spin 组件上
       return <Comp {...props} color={color} style={style} className={!tip ? className : undefined} />;
packages/base/src/spin/spins.tsx (1)

Line range hint 1-244: 建议优化代码结构以减少重复

当前代码中有大量相似的组件定义模式,建议考虑提取共同逻辑:

  1. 样式处理逻辑可以抽取为公共函数
  2. 可以创建高阶组件来处理通用的 props 处理逻辑

示例重构方案:

const withSpinStyles = (Component: React.ComponentType<SpinProps>, styleName: keyof SpinClasses) => {
  return (props: SpinProps) => {
    const { jssStyle, ...rest } = props;
    const spinStyles = jssStyle?.spin?.() || ({} as SpinClasses);
    
    return <Component {...rest} uniqueClassName={spinStyles[styleName]} />;
  };
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 478d4c8 and fa8a069.

⛔ Files ignored due to path filters (1)
  • packages/shineout/src/spin/__test__/__snapshots__/spin.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • packages/base/src/spin/base.tsx (2 hunks)
  • packages/base/src/spin/spin.tsx (1 hunks)
  • packages/base/src/spin/spin.type.ts (1 hunks)
  • packages/base/src/spin/spins.tsx (13 hunks)
🔇 Additional comments (5)
packages/base/src/spin/base.tsx (2)

10-10: 属性解构中添加 uniqueClassName 属性

在组件的属性解构中添加 uniqueClassName 是一个合理的改进,这样可以确保在没有 tip 属性时类名也能正常工作。


31-31: 验证类名生成逻辑的改进

类名生成逻辑的修改看起来合理,但建议验证在不同场景下的表现。

✅ Verification successful

Let me gather more information about the Spin component usage and its tests.


根据已获得的信息,我可以生成最终响应了。

类名生成逻辑验证通过

通过查看 Spin 组件的源码和测试用例,可以确认:

  • 类名生成逻辑使用了标准的 classNames 工具函数
  • 测试用例完整覆盖了类名相关的场景
  • 组件具有完善的样式和类名测试
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 Spin 组件在其他文件中的使用情况
# 预期:确认类名相关的修改不会影响现有功能

# 测试:搜索 Spin 组件的使用场景
rg -l "Spin" --type tsx

# 测试:检查是否有相关的测试文件
fd -e test.tsx -e spec.tsx

Length of output: 3237


Script:

#!/bin/bash
# 查找 Spin 组件的测试文件内容
cat packages/shineout/src/spin/__test__/spin.spec.tsx

# 查找 Spin 组件的使用情况,使用正确的文件类型
rg -l "Spin" --type ts --type tsx --type jsx

# 检查类名相关的测试用例
rg "className" packages/shineout/src/spin/__test__/spin.spec.tsx

Length of output: 9496


Script:

#!/bin/bash
# 检查 base.tsx 中的类名生成逻辑
cat packages/base/src/spin/base.tsx

# 检查其他组件中是否有类似的类名生成逻辑
rg "classNames\(.*styles\?\..*\)" --type ts --type tsx

# 检查是否有其他使用 uniqueClassName 的地方
rg "uniqueClassName" --type ts --type tsx

Length of output: 1258

packages/base/src/spin/spin.type.ts (1)

76-76: 新属性 uniqueClassName 的实现看起来不错!

属性类型定义正确,且与现有的 className 属性模式保持一致。这个改动很好地解决了没有 tip 时 className 失效的问题。

packages/base/src/spin/spin.tsx (1)

78-78: 建议验证样式在不同场景下的表现

请确认以下两种场景的样式是否正常:

  1. 有 tip 时,样式是否正确应用在外层容器
  2. 没有 tip 时,样式是否正确应用在 spin 组件本身
✅ Verification successful

Let me gather more information about the Spin component implementation and its usage.


Let me check the actual Spin component implementation to understand how the className is handled.


Let me try a different approach to check the Spin component implementation.


样式处理逻辑正确,无需修改

根据源码分析,当前的样式处理逻辑是合理的:

  1. 有 tip 时:

    • className 会应用在外层容器 contentClass
    • Spin 组件本身不带 className,避免样式重复应用
  2. 没有 tip 时:

    • className 直接应用在 Spin 组件上
    • 不会创建额外的容器层级

这种处理方式可以确保样式在不同场景下都能正确应用,不会出现样式冲突或重复的问题。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索 Spin 组件的使用场景,验证不同 tip 配置下的样式应用
rg -l "Spin.*className.*tip" 

Length of output: 144


Script:

#!/bin/bash
# Check the Spin component implementation
ast-grep --pattern 'export $_ function Spin' -A 20

# Check actual usage in docs
rg "Spin.*className.*tip" -A 3

Length of output: 53193


Script:

#!/bin/bash
# Check the Spin component implementation and its wrapper
rg -A 10 "function Spin" packages/base/src/spin/

Length of output: 50


Script:

#!/bin/bash
# Check the content of the Spin component file
cat packages/base/src/spin/spin.tsx

# Check for any tests related to className behavior
rg -l "className.*tip" packages/base/src/spin/

Length of output: 2740

packages/base/src/spin/spins.tsx (1)

47-47: 统一使用 uniqueClassName 替代 className

所有的 Spin 变体组件都从使用 className 切换到了 uniqueClassName。这个改动是为了解决当 tip 属性未提供时类名失效的问题。这种统一的修改方式有助于确保样式的一致性和可预测性。

不过建议考虑以下几点:

  1. 确保 uniqueClassName 在 TypeScript 类型定义中已正确声明
  2. 考虑添加相关测试用例,验证无 tip 时的样式是否正确应用

Also applies to: 63-63, 74-74, 83-83, 97-97, 115-115, 127-127, 137-137, 147-147, 164-164, 178-178, 204-204, 223-223

@@ -112,7 +112,7 @@ const ScaleCircle = (props: SpinProps) => {
<BaseSpin
{...props}
count={12}
className={spinStyles.fadingCircle}
uniqueClassName={spinStyles.fadingCircle}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

ScaleCircle 组件使用了错误的样式类名

ScaleCircle 组件错误地使用了 fadingCircle 的样式类名,这可能会导致样式混乱。

建议修改为:

-      uniqueClassName={spinStyles.fadingCircle}
+      uniqueClassName={spinStyles.scaleCircle}
📝 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
uniqueClassName={spinStyles.fadingCircle}
uniqueClassName={spinStyles.scaleCircle}

@saint3347 saint3347 merged commit 691f4e2 into main Oct 30, 2024
1 check 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.

2 participants