Skip to content

feat: make full antd style #22

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat: make full antd style #22

wants to merge 1 commit into from

Conversation

MadCcc
Copy link
Member

@MadCcc MadCcc commented Jul 10, 2025

Summary by CodeRabbit

  • 新功能

    • 现在支持自定义渲染 Tag、Badge、Space、Modal、message 和 notification 组件,提升了组件的灵活性和展示效果。
  • 修复

    • 优化了组件过滤逻辑,notification 和 message 组件将始终被包含,不再因命名规则被误排除。
  • 测试

    • 增强了样式提取测试,确保 .ant-notification.ant-message 样式被正确包含。

Copy link

coderabbitai bot commented Jul 10, 2025

📝 Walkthrough

Walkthrough

此次更改主要调整了组件黑名单 defaultBlackList,移除了一些组件,并为 Tag、Badge、Space、Modal、message 和 notification 添加了自定义渲染函数。同时,优化了 defaultNode 的过滤逻辑,使 notification 和 message 组件可以被正确包含。相关测试也同步完善。

Changes

文件/路径 变更摘要
src/index.tsx 修改黑名单,添加 Tag、Badge、Space、Modal、message、notification 的自定义渲染函数,调整组件过滤逻辑以支持 notification 和 message。
tests/index.test.tsx 增强黑名单相关测试,新增对 .ant-notification.ant-message 样式的断言。

Sequence Diagram(s)

sequenceDiagram
    participant 调用方
    participant defaultNode
    participant ComponentCustomizeRender

    调用方->>defaultNode: 请求渲染组件
    defaultNode-->>ComponentCustomizeRender: 检查是否有自定义渲染
    alt 有自定义渲染
        ComponentCustomizeRender-->>defaultNode: 返回自定义JSX
    else 没有自定义渲染
        defaultNode-->>调用方: 返回默认JSX
    end
    defaultNode-->>调用方: 返回最终组件节点
Loading

Possibly related PRs

  • feat: support whitelist and blacklist #21: 该 PR 也涉及 src/index.tsx 的黑名单和组件过滤机制,与本次更改在实现细节和范围上有所不同,但核心均为组件过滤逻辑的调整。

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.

tests/index.test.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:1369:15)
    at require.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    at Module._compile (node:internal/modules/cjs/loader:1692:14)
    at Object..js (node:internal/modules/cjs/loader:1824:10)
    at Module.load (node:internal/modules/cjs/loader:1427:32)
    at Module._load (node:internal/modules/cjs/loader:1250:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1449:12)
src/index.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:1369:15)
    at require.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    at Module._compile (node:internal/modules/cjs/loader:1692:14)
    at Object..js (node:internal/modules/cjs/loader:1824:10)
    at Module.load (node:internal/modules/cjs/loader:1427:32)
    at Module._load (node:internal/modules/cjs/loader:1250:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1449:12)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/full-style

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 auto-generate unit tests to generate unit tests for 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

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

79-79: 过滤逻辑更新合理,但条件表达式可读性有待提升

更新过滤逻辑以显式包含 'notification' 和 'message' 组件是合理的,因为这些组件名不符合首字母大写的命名约定。

建议提升代码可读性:

- ![...defaultBlackList, ...excludes].includes(name) && (name[0] === name[0].toUpperCase() || ['notification', 'message'].includes(name)),
+ ![...defaultBlackList, ...excludes].includes(name) && 
+ (name[0] === name[0].toUpperCase() || ['notification', 'message'].includes(name)),

或者更清晰的写法:

- ![...defaultBlackList, ...excludes].includes(name) && (name[0] === name[0].toUpperCase() || ['notification', 'message'].includes(name)),
+ {
+   const isNotBlacklisted = ![...defaultBlackList, ...excludes].includes(name);
+   const isCapitalized = name[0] === name[0].toUpperCase();
+   const isSpecialComponent = ['notification', 'message'].includes(name);
+   return isNotBlacklisted && (isCapitalized || isSpecialComponent);
+ }
tests/index.test.tsx (1)

72-73: 测试覆盖改进良好,验证了新的组件包含逻辑

新增的测试断言很好地验证了 notification 和 message 组件现在会被包含在样式提取中,这与源代码的更改保持一致。

这些测试确保了:

  1. notification 和 message 组件的样式被正确提取
  2. 黑名单过滤逻辑按预期工作
  3. 与现有的 Button 和 Card 组件测试保持一致

建议考虑添加更多测试用例来覆盖新的自定义渲染函数:

+ it('should extract styles for components with custom render functions', () => {
+   const cssText = extractStyle();
+   expect(cssText).toContain('.ant-tag');
+   expect(cssText).toContain('.ant-badge');
+   expect(cssText).toContain('.ant-space');
+   expect(cssText).toContain('.ant-modal');
+ });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5066da7 and 1bbc891.

📒 Files selected for processing (2)
  • src/index.tsx (2 hunks)
  • tests/index.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: setup
🔇 Additional comments (2)
src/index.tsx (2)

30-63: 请补充类型定义并验证私有 API 的稳定性

新增的渲染器逻辑基本合理,但为了增强类型安全和稳定性,建议:

  • 避免使用 any,为 Badge、Space、Modal、message、notification 等渲染函数补充精确的组件类型。
  • 私有 API _InternalPanelDoNotUseOrYouWillBeFired 未在公开文档中说明,请确认其在当前 antd 版本中的稳定性或是否存在公开替代方案。
  • 如确实需要使用该私有面板,建议在调用处添加容错逻辑(如 try/catch 或条件判断),以防未来升级时 API 变动导致运行时错误。

示例类型调整(请根据项目中实际引入的 antd 版本校准):

-  Badge: (Badge: any) => (
+  Badge: (Badge: React.ComponentType<any> & { Ribbon: React.ComponentType<any> }) => (
-  Space: (Space: any) => (
+  Space: (Space: React.ComponentType<any> & { Compact: React.ComponentType<any> }) => (
-  Modal: (Modal: any) => (
+  Modal: (Modal: React.ComponentType<any> & { _InternalPanelDoNotUseOrYouWillBeFired: React.ComponentType<any> }) => (
-  message: (message: any) => {
+  message: (message: { _InternalPanelDoNotUseOrYouWillBeFired: React.ComponentType<any> }) => {
-  notification: (notification: any) => {
+  notification: (notification: { _InternalPanelDoNotUseOrYouWillBeFired: React.ComponentType<any> }) => {

请针对以上几点进行确认与调整,确保类型正确且对私有 API 的依赖可控。


7-10: 确认黑名单调整实际影响

• 受影响文件:src/index.tsx(7–10 行),defaultBlackList 中移除了
['Drawer', 'Modal', 'Popconfirm', 'Popover', 'Tooltip', 'Tour']
• 搜索结果:
– Drawer、Popconfirm、Popover、Tooltip、Tour 在 .tsx/.ts 文件中均未被引用,移除它们不会改变样式提取结果。
– 仅 Modal 在 src/index.tsx 中有引用,移除后会将 Modal 样式纳入提取,可能导致样式包体积增大。

请确认:

  1. 是否确实需要将 Modal 样式包含在提取中?如是,是否已评估样式文件大小的变化?
  2. 如需保留本次变更,是否同步更新文档或变更日志说明对黑名单的调整?

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