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: segmented support classnames and styles #296

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

thinkasany
Copy link
Contributor

@thinkasany thinkasany commented Jan 13, 2025

Summary by CodeRabbit

  • 新功能

    • 为分段组件(Segmented)引入更灵活的样式和类名定制能力
    • 支持为分段项目和标签设置自定义类名和样式
  • 测试

    • 新增测试用例,验证自定义样式和类名的应用

Copy link

coderabbitai bot commented Jan 13, 2025

"""

概述

演练

此更改为 Segmented 组件引入了更灵活的样式和类名定制能力。通过添加新的类型 SemanticName,组件现在支持为 itemlabel 元素单独设置自定义类名和样式。这些更改允许开发者更精细地控制组件的外观,同时保持了现有接口的兼容性。

变更

文件 变更摘要
src/index.tsx - 新增 SemanticName 类型
- 更新 SegmentedProps 接口,添加 classNamesstyles 属性
- 更新 InternalSegmentedOption 组件,添加相同属性
tests/index.test.tsx - 新增测试用例 "should apply custom styles to Segmented"
- 验证自定义类名和样式的应用

诗歌

🐰 分段组件,样式自由
类名随心,风格飞扬
兔子跳跃,代码优雅
定制之美,尽在掌中
创意无限,代码如诗 🎨
"""


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.37%. Comparing base (8afca79) to head (a49bdc2).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #296   +/-   ##
=======================================
  Coverage   99.37%   99.37%           
=======================================
  Files           2        2           
  Lines         161      161           
  Branches       40       40           
=======================================
  Hits          160      160           
  Misses          1        1           

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

src/index.tsx Outdated
@@ -117,6 +124,7 @@ const InternalSegmentedOption: React.FC<{
className={classNames(className, {
[`${prefixCls}-item-disabled`]: disabled,
})}
style={styles?.item}
Copy link
Member

Choose a reason for hiding this comment

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

感觉有点怪,这里写了 styles.item,但是 classNames.item 却在下面的文件里。这个看起来是应该放一起的,否则不够内聚。

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

145-151: 建议优化样式应用逻辑以提升性能

当前的样式应用方式可能导致不必要的重渲染:

  1. classNames 函数在每次渲染时都会被调用
  2. 样式对象在渲染时重新创建

建议:

  1. 使用 useMemo 缓存 className 的计算结果
  2. 考虑将样式对象提升到组件外部或使用 useMemo 缓存
+ const labelClassName = React.useMemo(
+   () => classNames(
+     `${prefixCls}-item-label`,
+     segmentedClassNames?.label,
+   ),
+   [prefixCls, segmentedClassNames?.label]
+ );

Also applies to: 305-317

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df70aa4 and a49bdc2.

📒 Files selected for processing (1)
  • src/index.tsx (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: preview
🔇 Additional comments (2)
src/index.tsx (2)

9-9: 类型定义和接口更新看起来不错!

类型定义清晰,接口扩展合理。新增的 SemanticName 类型和相应的 props 能很好地支持样式自定义需求。

Also applies to: 45-46


80-82: 建议重构样式相关的属性处理方式

目前 styles.itemclassNames.item 的处理逻辑分散在不同位置,这样的设计不够内聚。建议:

  1. 将样式相关的逻辑统一处理
  2. 考虑创建一个专门的 hooks 来处理样式逻辑

@zombieJ zombieJ merged commit 7f2e8f5 into react-component:master Jan 16, 2025
8 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.

2 participants