Skip to content

refactor: Semantic structure #927

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 10 commits into from
Apr 18, 2025
Merged

refactor: Semantic structure #927

merged 10 commits into from
Apr 18, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Apr 18, 2025

  • 把 antd 侧的逻辑全部下沉到 rc-picker 中以优化体积同时简化处理逻辑。
  • 将弹窗语义化结构收到 popup 中
  • 添加 rootClassName 支持
  • 微调 Context 逻辑,添加一个 TODO 标记问题

Summary by CodeRabbit

  • 新功能

    • 支持通过 rootClassName 属性自定义根节点和下拉弹窗的类名。
    • 支持更细粒度的样式和类名定制,可为弹窗各部分(如 header、body、content、item、footer)分别设置 classNames 和 styles。
  • 重构

    • 统一和优化了样式与类名的传递方式,引入了新的语义化样式处理机制,提升了样式管理的灵活性和一致性。
  • 测试

    • 增强了对 classNames、styles 及 rootClassName 应用效果的测试覆盖,确保各部分样式和类名正确生效。

Copy link

vercel bot commented Apr 18, 2025

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

Name Status Preview Comments Updated (UTC)
picker ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2025 8:46am

Copy link

coderabbitai bot commented Apr 18, 2025

Walkthrough

本次变更重构了日期选择器组件的样式和类名处理方式,采用了更具语义化的结构。引入了 useSemantic 钩子和新的类型定义,统一管理 classNamesstyles,并通过上下文传递到各子组件。SharedPickerProps 接口及相关类型被重构,支持更细粒度的样式和类名分组(如 root、header、body、content、item、footer 等)。相关组件和测试同步调整,确保类名和样式的传递、合并及应用更加规范和一致,同时增加了 rootClassName 支持,便于根节点自定义样式。

Changes

文件/路径分组 变更摘要
docs/examples/basic.tsx 示例中为 Picker 组件新增 rootClassNameclassNameclassNames 属性,演示更丰富的样式自定义。
src/interface.tsx, src/hooks/useSemantic.ts 移除旧的 SemanticStructure,引入更细分的 SemanticNamePanelSemanticName,定义新的 classNames/styles 类型和 useSemantic 钩子,确保 popup 等子结构有默认值。
src/PickerInput/RangePicker.tsx, src/PickerInput/SinglePicker.tsx 使用 useSemantic 合并样式和类名,替换原有 props,统一传递和应用,支持 rootClassName
src/PickerInput/context.tsx context 类型调整,classNamesstyles 属性类型变更为必填且更细分的结构。
src/PickerInput/Selector/Icon.tsx, src/PickerInput/Selector/Input.tsx, src/PickerInput/Selector/RangeSelector.tsx, src/PickerInput/Selector/SingleSelector/index.tsx, src/PickerInput/Popup/Footer.tsx 统一 classnames 引用为 cls,简化 context 解构,调整样式和类名的应用方式。
src/PickerPanel/context.ts, src/PickerPanel/index.tsx 引入 SharedPanelContext,集中管理 panel 的 classNames 和 styles,通过 context 提供给子组件,移除 props 传递。
src/PickerPanel/PanelBody.tsx, src/PickerPanel/PanelHeader.tsx, src/PickerPanel/TimePanel/TimePanelBody/TimeColumn.tsx, src/PickerPanel/TimePanel/TimePanelBody/index.tsx 组件样式和类名的传递方式由 context/props 统一为新结构,调整命名和引用,支持更细粒度的样式控制。
tests/picker.spec.tsx 测试用例同步调整,覆盖更细分的 classNames/styles,增加对 rootClassName 的测试,确保各层样式应用准确。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Picker
    participant useSemantic
    participant Context
    participant SubComponent

    User->>Picker: 传递 classNames/styles/rootClassName
    Picker->>useSemantic: 合并/填充 classNames/styles
    useSemantic-->>Picker: 返回 mergedClassNames/mergedStyles
    Picker->>Context: 通过 context 提供 mergedClassNames/mergedStyles
    SubComponent->>Context: 获取 mergedClassNames/mergedStyles
    SubComponent->>SubComponent: 应用样式和类名
Loading

Possibly related PRs

Suggested reviewers

  • afc163

Poem

🐇
代码如春草,样式分层生,
语义化合并,根节点也新生。
classNames/styles 齐步走,
组件上下文共传承。
测试护航,界面更灵动,
兔子点头说:美观又轻松!

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.

docs/examples/basic.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 Function.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    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)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    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)
src/PickerInput/Popup/Footer.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 Function.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    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)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    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)
src/PickerInput/Selector/Icon.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 Function.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    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)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    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)
  • 15 others

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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 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 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.80%. Comparing base (e4a254d) to head (e201a06).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #927   +/-   ##
=======================================
  Coverage   98.79%   98.80%           
=======================================
  Files          64       65    +1     
  Lines        2656     2669   +13     
  Branches      740      742    +2     
=======================================
+ Hits         2624     2637   +13     
  Misses         29       29           
  Partials        3        3           

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

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/PickerPanel/context.ts (1)

61-62: 增加 TODO 注释标记潜在改进点

添加了 TODO 注释,指出当前从 props 获取样式的方式不够理想,应当迁移到 SharedPanelContext。建议按照 TODO 完成这项改进,使样式管理更加一致。

建议在后续迭代中实现此 TODO,将所有样式属性完全迁移到 SharedPanelContext 中,以确保一致的样式管理模式。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e4a254d and e201a06.

📒 Files selected for processing (18)
  • docs/examples/basic.tsx (1 hunks)
  • src/PickerInput/Popup/Footer.tsx (4 hunks)
  • src/PickerInput/RangePicker.tsx (8 hunks)
  • src/PickerInput/Selector/Icon.tsx (2 hunks)
  • src/PickerInput/Selector/Input.tsx (4 hunks)
  • src/PickerInput/Selector/RangeSelector.tsx (4 hunks)
  • src/PickerInput/Selector/SingleSelector/index.tsx (4 hunks)
  • src/PickerInput/SinglePicker.tsx (8 hunks)
  • src/PickerInput/context.tsx (2 hunks)
  • src/PickerPanel/PanelBody.tsx (6 hunks)
  • src/PickerPanel/PanelHeader.tsx (6 hunks)
  • src/PickerPanel/TimePanel/TimePanelBody/TimeColumn.tsx (3 hunks)
  • src/PickerPanel/TimePanel/TimePanelBody/index.tsx (4 hunks)
  • src/PickerPanel/context.ts (5 hunks)
  • src/PickerPanel/index.tsx (4 hunks)
  • src/hooks/useSemantic.ts (1 hunks)
  • src/interface.tsx (2 hunks)
  • tests/picker.spec.tsx (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (8)
src/PickerInput/Selector/RangeSelector.tsx (2)
docs/examples/time.tsx (1)
  • div (17-58)
docs/examples/debug.tsx (1)
  • div (45-110)
src/PickerPanel/TimePanel/TimePanelBody/TimeColumn.tsx (1)
src/PickerPanel/context.ts (1)
  • usePanelContext (50-52)
src/PickerInput/context.tsx (1)
src/hooks/useSemantic.ts (2)
  • FilledClassNames (8-10)
  • FilledStyles (12-14)
src/PickerPanel/index.tsx (1)
src/PickerPanel/context.ts (2)
  • PickerHackContext (132-132)
  • SharedPanelContext (10-10)
src/PickerPanel/TimePanel/TimePanelBody/index.tsx (2)
src/PickerPanel/context.ts (1)
  • PickerHackContext (132-132)
docs/examples/time.tsx (1)
  • div (17-58)
src/hooks/useSemantic.ts (1)
src/interface.tsx (1)
  • SharedPickerProps (318-449)
src/PickerInput/RangePicker.tsx (1)
src/hooks/useSemantic.ts (1)
  • useSemantic (19-36)
src/PickerPanel/context.ts (1)
src/hooks/useSemantic.ts (2)
  • FilledPanelClassNames (4-4)
  • FilledPanelStyles (6-6)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (81)
src/hooks/useSemantic.ts (1)

1-36: 优雅的实现了语义化结构的样式处理

这个新的 useSemantic 钩子函数很好地实现了对 classNamesstyles 属性的规范化,确保 popup 属性始终存在。使用 useMemo 来优化性能也是很好的做法。

推荐添加几个使用示例到注释中,以便其他开发者更容易理解如何使用这个钩子。

src/PickerInput/Selector/SingleSelector/index.tsx (4)

1-1: 导入别名统一为 cls

classnames 包的导入别名从 classNames 改为 cls 有助于统一代码风格,避免与组件属性命名冲突。


113-113: 简化上下文解构

直接使用 classNames 而不是重命名为 selectorClassNames,简化了代码并保持了一致性。


204-214: 使用 cls 替代 classNames 函数

统一使用 cls 函数组合类名,保持了代码风格的一致性。


229-229: 更新类名组合逻辑

直接使用 classNames.prefix 替代之前的变量名,与整体重构保持一致。

docs/examples/basic.tsx (1)

54-63: 示例中添加了新的样式属性

很好地展示了新的样式自定义能力,包括:

  1. rootClassName 用于根节点
  2. className 作为普通类名
  3. 结构化的 classNames 对象

这个示例对于用户理解如何使用新的语义化样式结构非常有帮助。

src/PickerInput/Selector/RangeSelector.tsx (4)

1-1: 统一导入别名为 cls

classnames 包的导入别名从 classNames 改为 cls,与项目其他部分保持一致。


124-124: 简化上下文解构

直接使用 classNames 而不是使用别名,简化了代码并提高了可读性。


214-224: 使用 cls 替代 classNames 函数

统一使用 cls 函数来组合类名,保持了代码风格的一致性。


242-242: 更新前缀类名组合逻辑

使用 cls 函数和直接访问 classNames.prefix,与整体重构方向一致。

src/PickerInput/Selector/Icon.tsx (3)

3-3: 引入命名更改以提高一致性

classnames 的导入别名从 classNames 更改为 cls,使其与项目中其他 picker 组件保持一致。这样有助于维护代码风格的统一性。


12-12: 上下文解构更新

PickerContext 直接解构 classNamesstyles,而不是使用别名,简化了代码并与语义化样式重构保持一致。


16-17: 更新样式和类名的应用方式

使用 cls 和直接访问 classNames.suffixstyles.suffix,这表明这些属性现在被保证存在(通过 useSemantic 钩子填充)。这种模式与整个重构中的语义化样式处理方式保持一致。

src/PickerPanel/TimePanel/TimePanelBody/TimeColumn.tsx (3)

1-1: 更新导入以支持语义化结构

classnames 导入别名从 classNames 更改为 cls,并使用 usePanelContext 钩子统一上下文的获取方式,移除了之前的 PickerHackContext 使用。这种改进使代码更简洁且结构更清晰。

Also applies to: 4-4


35-35: 统一上下文消费方式

通过 usePanelContext 解构获取 classNamesstyles,代替之前分开使用 PickerHackContext 的方式。这种变化简化了组件的上下文依赖,使代码更易于理解和维护。


106-107: 更新样式和类名的应用方式

将样式属性从 styles?.popupItem 更改为 styles.item,将类名构造从使用 classNamespickerClassNames?.popupItem 结合改为使用 clsclassNames.item 结合。这种更新统一了样式和类名处理的命名约定,并确保了类型安全。

src/PickerInput/context.tsx (2)

3-4: 更新类型导入以支持语义化结构

移除了 SemanticStructure 的导入,添加了 FilledClassNamesFilledStyles 类型的导入。这些类型提供了更精确的类型定义,支持组件的语义化样式结构。


13-14: 更新上下文属性类型

classNamesstyles 属性从可选的、以 SemanticStructure 为键的部分记录更改为必需的、类型为 FilledClassNamesFilledStyles 的属性。这种变化确保了这些属性始终存在,并使用更具体的类型,增强了类型安全性。

这与通过 useSemantic 钩子集中管理和标准化样式的更广泛重构相符。

src/PickerInput/Popup/Footer.tsx (4)

1-1: 引入命名更改以提高一致性

classnames 的导入别名从 classNames 更改为 cls,使其与项目中其他 picker 组件保持一致。这样有助于维护代码风格的统一性。


45-51: 扩展上下文解构

扩展 PickerContext 的解构,除现有的 prefixClslocalebutton 外,还包括 classNamesstyles 属性。这使组件能够访问通过上下文提供的样式信息,与语义化样式结构保持一致。


79-79: 更新类名构造函数

将类名构造从 classNames 更改为 cls,保持与项目中其他组件的一致性。


110-113: 添加语义化样式支持

在根 footer <div> 上合并默认的 footer 类名 ${prefixCls}-footerclassNames.popup.footer,并应用来自 styles.popup.footer 的内联样式。这种更新使组件能够支持动态样式和类名组合,与引入的语义化样式方法一致。

src/PickerInput/Selector/Input.tsx (4)

1-1: 将 classnames 库的导入命名从 classNames 改为 cls

为了保持整个代码库的一致性,将 classnames 库的导入别名统一修改为 cls。这种命名约定更简洁,同时避免与从上下文中提取的 classNames 属性混淆。


76-80: 优化上下文属性的解构提取

PickerContext 中解构出的 classNames 属性替代了原来的 inputClassNames,使组件属性命名更加语义化和一致。这符合整体的语义化结构重构目标。


385-394: 使用 cls 函数合并类名

将原来使用 classNames 函数替换为 cls 函数来合并类名,保持了一致的命名约定,使代码更加清晰。


407-408: 将样式责任从包装器转移到输入元素

通过明确地将 className={classNames.input}style={styles.input} 添加到内部 input 组件,将样式应用责任从外部包装器 div 转移到实际的输入元素上。这种方式更符合语义化结构,使样式应用更加精确和有意义。

src/PickerPanel/PanelHeader.tsx (4)

1-1: 将 classnames 库的导入命名从 classNames 改为 cls

为了保持整个代码库的命名一致性,将 classnames 库的导入别名统一修改为 cls。这种修改使得代码库中的命名约定更加统一。


35-38: 从面板上下文中解构出样式和类名属性

usePanelContext 钩子中解构出 classNamesstyles 属性,这些属性将用于组件的样式应用。这种方式使样式管理更加集中和一致,符合语义化结构重构的目标。


123-123: 使用语义化的类名和样式属性

为头部元素应用 classNames.headerstyles.header,使样式应用更加语义化和结构化。这种方式使组件的样式逻辑更易于理解和维护。


130-130: 统一按钮的类名应用方式

使用 cls 函数来合并按钮的类名,包括条件类名的应用,使代码更加一致和清晰。这种修改遵循了代码库中类名处理的统一模式。

Also applies to: 143-143, 157-157, 170-170

src/PickerPanel/PanelBody.tsx (6)

1-1: 将 classnames 库的导入命名从 classNames 改为 cls

为保持代码库的命名一致性,将 classnames 库的导入别名统一修改为 cls。这种修改使得整个代码库中的命名约定更加统一。


46-50: 从面板上下文中解构出样式和类名属性

usePanelContext 钩子中解构出 classNamesstyles 属性,这些属性将用于组件的样式应用。这种方式使样式管理更加集中和一致。


68-68: 简化 PickerHackContext 的使用

PickerHackContext 中只提取 onCellDblClick 属性,移除了原来提取的 classNamesstyles。这种简化使上下文的使用更加清晰,且避免了重复提取相同的属性。


128-142: 使用语义化的单元格类名

在单元格的 className 属性中添加 classNames.item,使用 cls 函数合并类名,这种方式使样式应用更加语义化和结构化。


143-143: 为单元格添加样式属性

通过 style={styles.item} 为单元格添加样式,使样式应用更加直接和明确。这与类名的应用方式一致,增强了样式管理的一致性。


187-188: 使用语义化的类名和样式属性

为主体和内容元素应用 classNames.bodyclassNames.content 以及相应的样式属性,使样式应用更加语义化和结构化。这种修改使组件的样式逻辑更易于理解和维护。

src/PickerPanel/TimePanel/TimePanelBody/index.tsx (4)

7-7: 将 classnames 库的导入命名从 classNames 改为 cls

为了保持整个代码库的命名一致性,将 classnames 库的导入别名统一修改为 cls。此处调整了导入顺序,并使用了统一的命名约定。


30-34: 从面板上下文中解构出样式和类名属性

usePanelContext 钩子中解构出 classNamesstyles 属性,这些属性将用于组件的样式应用。这种方式使样式管理更加集中和一致,符合语义化结构重构的目标。


44-44: 简化 PickerHackContext 的使用

PickerHackContext 中只提取 onCellDblClick 属性,移除了原来提取的其他属性。这种简化使上下文的使用更加清晰,避免了样式和交互逻辑的混合。


274-274: 使用语义化的类名和样式属性

为内容元素应用 classNames.contentstyles.content,使用 cls 函数合并类名,这种方式使样式应用更加语义化和结构化。这与代码库中其他组件的样式应用方式保持一致。

src/PickerPanel/index.tsx (5)

14-14: 从 interface 导入 PanelSemanticName 类型

这里从 ../interface 导入 PanelSemanticName 类型,这是语义化重构的一部分,用于更明确地定义面板各部分的样式和类名。


23-23: 更新导入包含 SharedPanelContext

./context 导入 PickerHackContextSharedPanelContext,后者是新添加的用于处理面板样式和类名的 Context。


381-387: 创建并合并面板样式 Context

添加了 sharedPanelContext 用于集中管理面板样式和类名,优先级为:pickerClassNames.popup > panelClassNames > 空对象。这种方式使样式处理更加一致和可维护。


395-395: 简化依赖数组

移除了 classNamesstyles 相关依赖,现在仅依赖 parentHackContexthideHeader,减少了不必要的重新计算。


428-464: 使用 SharedPanelContext.Provider 包装组件

重构了组件返回的 JSX,使用 SharedPanelContext.Provider 包装 PickerHackContext.Provider,提供统一的样式和类名管理方式。这种更具语义化的结构使代码更易于维护。

src/interface.tsx (3)

314-316: 新增语义化类型定义

将原有的 SemanticStructure 拆分为更具语义化的两个类型:

  • SemanticName: 用于主选择器的样式和类名
  • PanelSemanticName: 用于弹出面板的样式和类名

这种拆分使得类型定义更加精确,组件样式结构更加清晰。


332-332: 添加 rootClassName 属性

新增 rootClassName 属性允许直接为根元素添加类名,提供了更方便的根元素样式自定义方式。


334-339: 重构样式和类名属性类型

更新了 stylesclassNames 属性类型,采用新的语义化类型定义:

  • 使用 SemanticName 作为主要选择器样式和类名的键
  • 添加嵌套的 popup 属性使用 PanelSemanticName 作为弹出面板样式和类名的键

这种结构使样式定义更加结构化,支持更细粒度的样式控制。

src/PickerInput/SinglePicker.tsx (7)

2-2: 标准化 classnames 导入命名

classnames 包的导入名称统一为 cls,保持代码风格一致性。


35-35: 添加 useSemantic 钩子导入

导入 useSemantic 钩子用于规范化处理 classNamesstyles 属性。


127-130: 重命名和添加样式相关属性

  • 添加 rootClassName 属性用于根元素类名
  • styles 重命名为 propStyles
  • classNames 重命名为 propClassNames

这种命名使属性的来源和用途更加明确,区分原始属性和合并后的属性。


208-210: 使用 useSemantic 钩子处理样式

使用 useSemantic 钩子规范化处理 classNamesstyles,确保它们具有一致的结构和默认值。


634-635: 更新弹出层样式和类名应用

使用合并后的样式对象 mergedStyles.popup.root 和类名 cls(rootClassName, mergedClassNames.popup.root) 应用到弹出层,保持样式结构一致性。


646-650: 更新选择器样式和类名应用

使用 cls 合并多个类名源(原始类名、根类名和语义类名),同时合并样式对象。这种方式保证了样式应用的一致性和优先级。


588-599: 更新 Context 值和依赖数组

将合并后的 mergedClassNamesmergedStyles 提供给 Context,并更新依赖数组包含这些合并值,确保 Context 值的正确更新。

src/PickerInput/RangePicker.tsx (8)

2-2: 标准化 classnames 导入命名

classnames 包的导入名称统一为 cls,保持代码风格一致性。


39-39: 添加 useSemantic 钩子导入

导入 useSemantic 钩子用于规范化处理 classNamesstyles 属性。


164-166: 重命名和添加样式相关属性

  • 添加 rootClassName 属性用于根元素类名
  • styles 重命名为 propStyles
  • classNames 重命名为 propClassNames

这种命名使属性的来源和用途更加明确,区分原始属性和合并后的属性。


230-232: 使用 useSemantic 钩子处理样式

使用 useSemantic 钩子规范化处理 classNamesstyles,确保它们具有一致的结构和默认值。


571-573: 更新 panelProps 排除属性列表

在构建传递给面板组件的属性时,排除 classNamesstyles 属性,防止这些属性被直接传递给面板组件。这与在单独的 context 中处理样式的重构目标一致。


774-776: 更新弹出层样式和类名应用

使用合并后的样式对象 mergedStyles.popup.root 和类名 cls(rootClassName, mergedClassNames.popup.root) 应用到弹出层,保持样式结构一致性。


788-792: 更新选择器样式和类名应用

使用 cls 合并多个类名源(原始类名、根类名和语义类名),同时合并样式对象。这种方式保证了样式应用的一致性和优先级。


704-715: 更新 Context 值和依赖数组

将合并后的 mergedClassNamesmergedStyles 提供给 Context,并更新依赖数组包含这些合并值,确保 Context 值的正确更新。

src/PickerPanel/context.ts (5)

2-3: 引入了语义化类型定义,增强类型安全性

useSemantic 钩子中导入了 FilledPanelClassNamesFilledPanelStyles 类型,这些类型将确保组件样式结构的一致性和类型安全。


5-10: 新增 SharedPanelContext 用于集中管理样式

创建了新的上下文 SharedPanelContext 来集中管理面板的 classNamesstyles,这是重构的核心部分,使样式管理更加语义化和集中化。


43-44: 在 PanelContextProps 中增加样式属性

PanelContextProps 接口中添加了 classNamesstyles 属性,确保这些样式能够传递到使用此上下文的组件中。


85-86: 使用 SharedPanelContext 获取样式

从新的 SharedPanelContext 中提取 classNamesstyles,实现了样式的统一管理和访问。这是重构中的关键步骤,使组件能够一致地获取样式信息。


97-98: 将样式属性添加到共享信息对象

info 对象中添加了 classNamesstyles 属性,确保这些样式能够被正确地传递给所有使用此信息的子组件。

tests/picker.spec.tsx (13)

1354-1361: 重构类名结构使用语义化命名

popupClassNames 对象重构为更具语义化的结构,包含 rootheaderbodycontentitemfooter 属性,与组件的结构层次一致,提高了代码可读性和维护性。


1362-1369: 重构样式结构与类名结构保持一致

样式对象 popupStyles 的结构与类名结构保持一致,同样使用语义化的命名,包含相同的属性名,使代码更加一致和易于理解。


1370-1380: 更新测试用例使用新的嵌套结构

测试用例更新为使用新的嵌套结构,将 classNamesstyles 放在 popup 属性下,与组件实际使用方式保持一致,确保测试的有效性。


1382-1400: 更新测试断言以验证新的样式结构

更新了测试断言,验证每个 DOM 元素是否正确应用了相应的类名和样式,确保样式重构后的行为与预期一致。


1405-1407: 更新面板测试的属性名称

将面板测试中的属性名从 popupBodypopupContentpopupItem 更新为更简洁的 bodycontentitem,与新的语义化结构保持一致。

Also applies to: 1410-1412


1425-1430: 更新面板测试断言

更新了面板测试断言,以验证新的类名和样式属性是否正确应用,确保重构后的行为与预期一致。


1435-1436: 添加根元素样式测试

为测试添加了 root 类名和样式,确保根元素的样式也能够正确应用,完善了测试覆盖范围。

Also applies to: 1446-1447


1440-1444: 更新弹出层测试的样式结构

更新了弹出层测试的样式结构,使用新的嵌套格式,确保测试与实际组件使用方式一致。

Also applies to: 1451-1455


1459-1463: 更新时间面板测试的样式应用方式

更新了时间面板测试中样式的应用方式,使用新的嵌套结构,确保测试与实际组件使用方式一致。


1475-1479: 添加根元素选择与断言

为测试添加了根元素的选择与断言,验证根元素是否正确应用了类名和样式,完善了测试覆盖范围。

Also applies to: 1480-1481


1491-1492: 更新面板测试的样式应用

更新了面板测试中样式的应用方式,使用新的结构传递 classNamesstyles,确保测试与实际组件使用方式一致。


1500-1503: 更新面板测试的断言

更新了面板测试的断言,以验证新的类名和样式是否正确应用,确保重构后的行为与预期一致。


1506-1512: 新增 rootClassName 功能测试

添加了对 rootClassName 属性的测试,验证该属性能够正确应用到选择器根元素和下拉菜单上,这是一个有价值的新功能,使用户可以更方便地自定义根元素样式。

@zombieJ zombieJ merged commit 3f97192 into master Apr 18, 2025
12 checks passed
@zombieJ zombieJ deleted the semantic branch April 18, 2025 08:51
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