Skip to content

feat(switch): loading状态交给用户控制 #3170

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

Closed
wants to merge 1 commit into from

Conversation

Ryan-CW-Code
Copy link
Contributor

@Ryan-CW-Code Ryan-CW-Code commented Apr 11, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 在开关组件中引入了加载状态(loading),在操作过程中提供实时的加载提示;
    • 新增示例展示了加载状态下的开关操作,同时支持简体中文、繁体中文和英文的多语言提示。
  • 文档

    • 更新了开关组件文档,添加了 loading 属性的详细说明,便于用户了解和使用该功能。

Copy link

coderabbitai bot commented Apr 11, 2025

Walkthrough

该次提交新增了多个组件和 API 功能。首先,在 Switch 组件演示中引入了新的 Demo8 组件,同时增加了“loading”状态的翻译(支持简体中文、繁体中文及英文),并在 UI 中展示。其次,Switch 组件内部逻辑进行了精简,移除旧的 state 处理,完全依赖新增的 loading 属性控制行为。此外,文档中也更新了 Switch 的属性说明,新增 loading 属性以展示加载状态。

Changes

文件(s) 修改摘要
src/packages/switch/demo.taro.tsx, src/packages/switch/demo.tsx 新增加载状态展示:引入 Demo8 组件、添加 loading 翻译文本,并在组件中渲染显示
src/packages/switch/demos/h5/demo8.tsx, src/packages/switch/demos/taro/demo8.tsx 新增 Demo8 组件实现:基于 Cell/Space/ Switch 组件,两个 Switch 均处于加载状态(一个默认选中)
src/packages/switch/doc.en-US.md, src/packages/switch/doc.md, src/packages/switch/doc.taro.md, src/packages/switch/doc.zh-TW.md 更新文档:新增 Switch 组件的 loading 属性说明及对应默认值和翻译
src/packages/switch/switch.taro.tsx, src/packages/switch/switch.tsx, src/types/spec/switch/base.ts 更新 Switch 组件逻辑:新增 loading 属性替代原 changing 状态,调整 onClick 及渲染逻辑以使用 loading 属性

Sequence Diagram(s)

sequenceDiagram
    participant SwitchDemo
    participant View
    participant Demo8
    SwitchDemo->>View: 渲染 loading 翻译文本
    SwitchDemo->>Demo8: 渲染 Demo8 组件
Loading
sequenceDiagram
    participant User
    participant Switch
    User->>Switch: 点击开关
    alt loading 为 true
        Switch-->>User: 显示 Loading 图标,不触发 onChange
    else
        Switch->>Switch: 更新状态
        Switch->>User: 执行 onChange 回调
    end
Loading

Possibly related PRs

Suggested reviewers

  • xiaoyatong
  • oasis-cloud

Poem

在代码林间轻跳跃,
小兔挥笔写更新,
Switch 加载新风采,
Demo8 展现别样趣,
翻译伴随启新路,
代码世界更明亮,
跳跃未来,心欢畅! 🐇💻

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 plan to trigger planning for file edits and PR creation.
  • @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.

@github-actions github-actions bot added 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) labels Apr 11, 2025
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.19%. Comparing base (79a9900) to head (338d5c5).
Report is 8 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #3170      +/-   ##
=============================================
- Coverage      87.20%   87.19%   -0.01%     
=============================================
  Files            279      279              
  Lines          18540    18537       -3     
  Branches        2822     2819       -3     
=============================================
- Hits           16167    16163       -4     
- Misses          2368     2369       +1     
  Partials           5        5              

☔ 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 (2)
src/packages/switch/doc.md (1)

81-81: 属性文档更新清晰

新增的loading属性在文档中有明确的描述:"加载中的开关",类型为boolean,默认值为false。这与代码实现一致,并且提供了足够的信息让用户理解如何使用这个新功能。

不过,文档中没有添加展示loading状态的示例部分,建议考虑添加对应的Demo8示例到文档中。

+
+### 加载状态
+
+:::demo
+
+<CodeBlock src='h5/demo8.tsx'></CodeBlock>
+
+:::
src/packages/switch/doc.zh-TW.md (1)

81-81: 繁體中文文檔更新正確

loading屬性的繁體中文描述"載入中的開關"清晰明確,與簡體中文文檔保持一致性,並符合繁體中文的表達習慣。類型和默認值的設置也正確。

同樣地,繁體中文文檔也建議添加Demo8的示例展示。

+
+### 載入狀態
+
+:::demo
+
+<CodeBlock src='h5/demo8.tsx'></CodeBlock>
+
+:::
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79a9900 and 338d5c5.

📒 Files selected for processing (11)
  • src/packages/switch/demo.taro.tsx (5 hunks)
  • src/packages/switch/demo.tsx (5 hunks)
  • src/packages/switch/demos/h5/demo8.tsx (1 hunks)
  • src/packages/switch/demos/taro/demo8.tsx (1 hunks)
  • src/packages/switch/doc.en-US.md (1 hunks)
  • src/packages/switch/doc.md (1 hunks)
  • src/packages/switch/doc.taro.md (1 hunks)
  • src/packages/switch/doc.zh-TW.md (1 hunks)
  • src/packages/switch/switch.taro.tsx (5 hunks)
  • src/packages/switch/switch.tsx (5 hunks)
  • src/types/spec/switch/base.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/packages/switch/demos/h5/demo8.tsx (2)
src/packages/switch/switch.taro.tsx (1)
  • Switch (19-105)
src/packages/switch/switch.tsx (1)
  • Switch (17-103)
src/packages/switch/demos/taro/demo8.tsx (2)
src/packages/switch/switch.taro.tsx (1)
  • Switch (19-105)
src/packages/switch/switch.tsx (1)
  • Switch (17-103)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (19)
src/types/spec/switch/base.ts (1)

11-11: 新增加的loading属性与组件功能匹配

这个变更为BaseSwitch接口添加了一个布尔类型的loading属性,这与PR的目标"让用户控制loading状态"相符。这个属性将允许用户直接控制Switch组件的加载状态。

src/packages/switch/demos/h5/demo8.tsx (1)

1-14: Demo8组件展示了loading状态的用法

这个新增的Demo8组件很好地展示了loading属性的用法,通过两个不同状态的Switch(一个默认状态的loading和一个checked状态的loading)来帮助用户理解这个新功能。

代码结构清晰,使用Space组件合理布局多个Switch实例,符合组件库的设计风格。

src/packages/switch/doc.taro.md (1)

81-81: 属性文档更新完整

属性 loading 的添加与实现代码保持一致,文档描述清晰简洁。

src/packages/switch/demos/taro/demo8.tsx (1)

1-14: 代码示例结构合理

新增的 Demo8 组件结构清晰,展示了 Switch 组件的 loading 状态在默认开启和关闭两种情况下的效果,与其他示例代码保持一致的风格。

src/packages/switch/doc.en-US.md (1)

81-81: 英文文档属性描述准确

英文文档中 loading 属性的添加与中文文档保持一致,属性描述准确清晰。

src/packages/switch/demo.taro.tsx (3)

13-13: 正确导入新增 Demo 组件

正确导入了 Demo8 组件,保持与其他 Demo 组件导入的一致性。


25-25: 多语言翻译完整

为 loading 状态添加了中文、繁体中文和英文的翻译,描述准确,有助于用户理解该功能。

Also applies to: 35-35, 45-45


66-67: UI 展示正确

正确添加了标题和 Demo8 组件的展示,保持了与其他 Demo 相同的结构和风格。

src/packages/switch/demo.tsx (3)

10-10: 新增了 Demo8 组件的导入

导入了展示 Switch 组件 loading 状态的 Demo8 组件,扩展了组件演示范例。


22-22: 为 loading 状态添加了多语言翻译

在中文简体、中文繁体和英文三种语言中都添加了对应的 loading 状态描述文本,保证了国际化支持的完整性。

Also applies to: 32-32, 42-42


62-63: 增加了 loading 状态的演示部分

添加了标题和 Demo8 组件的渲染,使用户可以直观地看到 loading 状态的效果,完善了组件文档。

src/packages/switch/switch.tsx (4)

15-15: 添加 loading 属性到默认配置

为 Switch 组件添加了 loading 属性并设置默认值为 false,让用户可以控制组件的加载状态。


25-25: 从 props 中解构 loading 属性

从组件 props 中解构出 loading 属性,使其可以在组件内部使用。


56-57: 更新点击事件的条件判断

将点击事件的条件判断更新为同时检查 disabled 和 loading 状态,确保在加载状态下组件不可交互,提升了用户体验。


78-87: 优化 loading 图标的条件渲染

优化了 loading 图标的条件渲染逻辑,使用 loading 属性代替原有的内部状态管理,简化了组件逻辑。

src/packages/switch/switch.taro.tsx (4)

17-17: 在 Taro 版本中添加 loading 属性

在 Taro 版本的 Switch 组件中添加了 loading 属性并设置默认值为 false,与 Web 版本保持一致,确保了跨平台的行为一致性。


27-27: 从 props 中解构 loading 属性

从 Taro 组件 props 中解构出 loading 属性,保持与 Web 版本的实现一致。


58-58: 更新 Taro 版本中点击事件的条件判断

将 Taro 版本中点击事件的条件判断更新为同时检查 disabled 和 loading 状态,保持与 Web 版本一致的交互体验。


80-89: 优化 Taro 版本中 loading 图标的条件渲染

优化了 Taro 版本中 loading 图标的条件渲染逻辑,使用 loading 属性代替原有的内部状态管理,与 Web 版本保持一致的实现方式。

@oasis-cloud
Copy link
Collaborator

如果要支持这种增加 loading 属性,仍需要保留 switch 切换状态时的加载中状态。

@Ryan-CW-Code
Copy link
Contributor Author

在原来的基础上做成受控的吧?
是您们内部switch都是使用loading的吗,看别的组件库都是让外部控制

@Ryan-CW-Code
Copy link
Contributor Author

新版更新,已经有另外的解决方案了

@Ryan-CW-Code Ryan-CW-Code deleted the switch_loading branch July 4, 2025 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants