Skip to content

refactor: popup structure #1145

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
Apr 28, 2025
Merged

refactor: popup structure #1145

merged 1 commit into from
Apr 28, 2025

Conversation

thinkasany
Copy link
Contributor

@thinkasany thinkasany commented Apr 28, 2025

Summary by CodeRabbit

  • 样式
    • 选项列表及其项的样式和类名支持通过 popup 属性进行更细粒度的自定义。
  • 重构
    • 拆分和优化类型声明,提升 popup 相关样式和类名的可扩展性。
  • 测试
    • 更新测试用例以适配 popup 下嵌套的样式和类名结构。

Copy link

vercel bot commented Apr 28, 2025

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

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 28, 2025 8:08am

Copy link
Contributor

coderabbitai bot commented Apr 28, 2025

Walkthrough

本次更改对 Select 组件的样式和类名传递方式进行了结构化调整。具体来说,将原本顶层的 list 和 listItem 样式/类名属性,统一嵌套在 popup 属性下,并在类型定义、上下文属性和测试用例中相应调整。这些变更仅涉及样式和类名的结构化管理,没有影响组件的渲染逻辑、事件处理或状态管理。

Changes

文件/路径 变更摘要
src/OptionList.tsx 将 list 和 listItem 的 className/style 获取方式调整为 contextClassNames?.popup?.list 及 contextClassNames?.popup?.listItem 等嵌套结构。
src/Select.tsx 拆分原有的 SemanticName 类型,将 'listItem' 和 'list' 定义为新的 PopupSemantic 类型,并调整类型导出。
src/SelectContext.ts SelectContextProps 的 classNames 和 styles 属性类型增加 popup 嵌套,支持 popup 相关的样式和类名。
tests/Select.test.tsx 测试用例中的自定义 classNames 和 style 结构调整为 popup 嵌套,并更新断言逻辑。

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Select
  participant OptionList
  participant Context

  User->>Select: 传入 customClassNames/customStyle(含 popup 嵌套)
  Select->>Context: 通过 Provider 提供 classNames/styles
  OptionList->>Context: 读取 contextClassNames?.popup?.list / listItem
  OptionList-->>User: 渲染带嵌套样式的下拉列表
Loading

Possibly related PRs

  • feat: rename dropdown to popup #1103: 该 PR 也涉及将下拉相关属性从 dropdown 重命名为 popup,并引入 popup 语义,和本次变更的样式结构调整直接相关。

Suggested reviewers

  • zombieJ

Poem

🐇
样式嵌套如春雨,
popup 之下藏玄机。
代码整洁添新意,
组件美观更容易。
小兔挥笔庆更新,
前端世界更美丽!

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/OptionList.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)
src/Select.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)
src/SelectContext.ts

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)
  • 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 3639a8a and f352442.

📒 Files selected for processing (4)
  • src/OptionList.tsx (3 hunks)
  • src/Select.tsx (1 hunks)
  • src/SelectContext.ts (2 hunks)
  • tests/Select.test.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/Select.tsx (1)
src/BaseSelect/index.tsx (1)
  • BaseSelectSemanticName (31-31)
src/SelectContext.ts (1)
src/Select.tsx (2)
  • SemanticName (111-111)
  • PopupSemantic (112-112)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / react component workflow
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (9)
src/Select.tsx (1)

111-112: 结构优化:将弹出层语义与基础选择器语义分离

这个改动通过将 listItemlistSemanticName 中分离出来并创建专门的 PopupSemantic 类型,使类型定义更加清晰。这种结构优化使得弹出层相关的样式和类名可以独立管理,符合关注点分离的设计原则。

tests/Select.test.tsx (3)

2427-2430: 测试数据结构调整:将弹出层样式配置嵌套化

测试用例中的自定义类名结构已更新,将 listlistItem 嵌套在 popup 对象中,与组件代码中的类型定义变更保持一致。这种结构使弹出层相关的样式配置更加集中和清晰。


2436-2439: 样式对象结构调整:与类名结构保持一致

自定义样式对象结构也做了相应调整,将 listlistItem 嵌套在 popup 对象中,保持了与类名配置的一致性,这有助于维护代码的一致性和可预测性。


2466-2469: 测试断言更新:验证嵌套结构能否正常工作

测试断言已更新为检查嵌套结构中的类名和样式是否正确应用,确保重构后的代码仍然按预期工作。测试覆盖了弹出层列表和列表项的类名与样式,验证了完整的改动范围。

src/OptionList.tsx (3)

332-333: 更新弹出层列表的类名和样式引用

将列表的类名和样式引用更新为使用嵌套结构 contextClassNames?.popup?.listcontextStyles?.popup?.list,与类型定义的变更保持一致。这种改动使得类名和样式的组织结构更加清晰,便于理解和维护。


366-366: 更新列表项类名引用

将列表项的类名引用更新为 contextClassNames?.popup?.listItem,统一了弹出层相关样式的访问方式,提高了代码的一致性。


406-406: 更新列表项样式引用并保持与自定义样式的合并

将列表项的样式引用更新为 contextStyles?.popup?.listItem,同时保持了与组件自定义样式 style 的合并。这确保了组件级样式覆盖和弹出层样式配置能够同时生效,维持了原有的样式优先级规则。

src/SelectContext.ts (2)

10-10: 导入新的弹出层语义类型

从 './Select' 中导入 PopupSemantic 类型,为后续在接口中使用该类型做准备。这是一个必要的改动,确保类型系统能够正确识别弹出层相关的语义名称。


19-24: 更新上下文接口,支持嵌套的弹出层样式配置

SelectContextProps 接口进行了更新,为 classNamesstyles 添加了可选的嵌套 popup 属性。这种结构化的改进使得弹出层相关的样式配置能够集中管理,同时通过类型系统确保只能使用有效的语义名称。

这种结构变更提高了代码的可维护性和类型安全性,是一个很好的重构方向。

✨ 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.
    • 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.
  • @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 Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.26%. Comparing base (3639a8a) to head (f352442).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1145   +/-   ##
=======================================
  Coverage   98.26%   98.26%           
=======================================
  Files          39       39           
  Lines        1500     1500           
  Branches      453      453           
=======================================
  Hits         1474     1474           
  Misses         26       26           

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

@zombieJ zombieJ merged commit 4e19486 into react-component:master Apr 28, 2025
11 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