Skip to content

feat: support components #375

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

Merged
merged 1 commit into from
Jun 4, 2025
Merged

feat: support components #375

merged 1 commit into from
Jun 4, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Jun 4, 2025

Steps 组件需要支持 clickable 要用 div 而 Timeline 则是 ol。否则 li + click a11y 会报错。这里添加一个 components 自定义支持。

Summary by CodeRabbit

  • 新功能

    • 现在支持通过自定义组件替换步骤列表的根元素和每个步骤项的包裹元素,提升了组件的灵活性和可扩展性。
  • 测试

    • 增加了针对自定义根元素和步骤项元素的测试用例,确保新功能的正确性。

Copy link

vercel bot commented Jun 4, 2025

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

Name Status Preview Comments Updated (UTC)
steps ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2025 6:43am

Copy link

coderabbitai bot commented Jun 4, 2025

Walkthrough

本次更改为Steps组件引入了自定义根元素和子项元素的能力。通过扩展上下文和属性接口,允许用户通过components属性指定根容器和子项容器的组件类型。相关上下文、子项组件以及测试用例均已相应调整。

Changes

文件/分组 变更摘要
src/Context.ts StepsContextProps接口新增ItemComponent: ComponentType属性,并引入ComponentType类型。
src/Step.tsx Step组件通过上下文获取ItemComponent,替换原有的<li>元素。
src/Steps.tsx 新增ComponentType类型别名,StepsProps支持components属性,内部通过上下文传递自定义组件。根容器由<ol>改为可自定义组件。
tests/index.test.tsx 新增测试用例,验证Steps组件支持自定义根元素和子项元素。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Steps
    participant Step
    participant StepsContext

    User->>Steps: 渲染Steps({ components: { root, item } })
    Steps->>StepsContext: 提供{ ItemComponent: item }
    Steps->>Step: 渲染Step
    Step->>StepsContext: 获取ItemComponent
    Step->>ItemComponent: 渲染Step内容
Loading

Poem

🐰
步骤组件焕新颜,
元素自定义不再难。
上下文中传新意,
测试验证保安全。
代码灵活如兔跳,
前端世界更灿烂!

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/Context.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/Step.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/Steps.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

  • 1 others

📜 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 a5706e5 and 5b984fe.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • src/Context.ts (1 hunks)
  • src/Step.tsx (4 hunks)
  • src/Steps.tsx (6 hunks)
  • tests/index.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/Context.ts (1)
src/Steps.tsx (2)
  • StepsProps (66-104)
  • ComponentType (35-35)
src/Steps.tsx (1)
src/Context.ts (1)
  • StepsContextProps (4-9)
🔇 Additional comments (9)
src/Context.ts (1)

2-2: 良好的类型集成

./Steps 模块正确导入了 ComponentType 类型,并在上下文接口中恰当地添加了 ItemComponent 属性。这种设计允许通过上下文传递自定义组件类型。

Also applies to: 8-8

tests/index.test.tsx (1)

367-383: 完善的测试覆盖

新增的测试用例正确验证了自定义组件功能,通过指定 root: 'ol'item: 'li' 来测试组件替换机制。快照测试确保渲染输出的正确性。

src/Step.tsx (2)

9-9: 正确的上下文集成

正确导入并使用 StepsContext 来获取 ItemComponent,实现了组件的动态替换机制。

Also applies to: 65-65


238-250: 优雅的组件替换实现

将硬编码的 li 元素替换为从上下文获取的 ItemComponent,保持了所有属性和事件处理的完整性。这种实现方式既保证了向后兼容性,又提供了灵活的组件自定义能力。

src/Steps.tsx (5)

35-35: 灵活的类型定义

ComponentType 类型定义允许使用 React 组件或字符串标签名,为组件自定义提供了合适的灵活性。


79-85: 良好的 API 设计

components 属性被标记为内部使用,这表明了谨慎的 API 设计。接口定义清晰,允许自定义根容器和子项容器组件。


119-119: 正确的属性处理和默认值

正确解构 components 属性,并为 RootComponentItemComponent 提供了合理的默认值('div'),确保向后兼容性。

Also applies to: 181-181


189-192: 完整的上下文更新

正确将 ItemComponent 添加到上下文值中,并在依赖数组中包含了所有相关变量,确保上下文在组件变化时正确更新。


229-241: 一致的组件替换实现

使用 RootComponent 替换硬编码的元素,与子组件中的 ItemComponent 替换保持一致。所有属性都正确传递给自定义组件。

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a5706e5) to head (5b984fe).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #375   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines           97        99    +2     
  Branches        37        38    +1     
=========================================
+ Hits            97        99    +2     

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

/** Internal usage of antd. Do not deps on this. */
components?: {
root?: ComponentType;
item?: ComponentType;
Copy link
Member

Choose a reason for hiding this comment

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

单独rc这边不给默认值吗?olli之类的

Copy link
Member Author

Choose a reason for hiding this comment

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

这个 是定义,实现里给了默认值。另外这个库是 rc-steps,所以默认值是 div,antd里的 Timeline 才会改成 ol 和 li

@zombieJ zombieJ merged commit c7b4732 into master Jun 4, 2025
13 checks passed
@zombieJ zombieJ deleted the components branch June 4, 2025 06:46
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