Skip to content
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

feat: ✨ 修复 Switch 组件增加可展示状态文字 (#798) #817

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

Conversation

810505339
Copy link
Collaborator

@810505339 810505339 commented Jan 7, 2025

🤔 这个 PR 的性质是?(至少选择一个)

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • 新功能

    • 为开关组件添加了文字描述功能
    • 支持在开关的激活和非激活状态显示自定义文本
  • 文档更新

    • 更新了开关组件的文档,新增了文字描述使用说明
    • 在属性表中添加了 active-textinactive-text 两个新属性的说明
  • 样式调整

    • 优化了开关组件的布局和显示样式
    • 改进了组件的灵活性和响应性

Copy link

vercel bot commented Jan 7, 2025

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

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 7:38am

Copy link

coderabbitai bot commented Jan 7, 2025

详细介绍

概述

该拉取请求为 wd-switch 组件引入了文本描述功能,允许在开关的激活和非激活状态下显示自定义文本。修改涉及文档、组件样式、类型定义和组件实现,增强了开关组件的用户交互体验。

变更

文件 变更摘要
docs/component/switch.md 新增文本描述部分,更新属性表,移除之前的确认逻辑
src/pages/switch/Index.vue 添加新的开关演示示例,包含文本描述
src/uni_modules/wot-design-uni/components/wd-switch/index.scss 调整布局和样式,支持文本显示
src/uni_modules/wot-design-uni/components/wd-switch/types.ts 新增 activeTextinactiveText 属性
src/uni_modules/wot-design-uni/components/wd-switch/wd-switch.vue 添加 innerText 计算属性,支持文本渲染

建议的审阅者

  • Moonofweisheng

诗歌

🐰 开关跳舞,文字轻语
激活与静止间的魔法
一个开关,两种心情
摸鱼或不摸,随心而行
技术之兔,欢快歌唱!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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

netlify bot commented Jan 7, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 71a82f6
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/677cd985b968e40008b29541
😎 Deploy Preview https://deploy-preview-817--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (6)
src/uni_modules/wot-design-uni/components/wd-switch/wd-switch.vue (1)

3-5: 建议增加无障碍访问支持

文字描述的实现逻辑正确,但建议添加 aria-label 属性以提升无障碍访问支持。

-    <view class="wd-switch__inner" v-if="innerText">
+    <view class="wd-switch__inner" v-if="innerText" :aria-label="innerText">
src/pages/switch/Index.vue (1)

74-76: 建议改进事件处理函数

handleChange6 函数可以更具体地处理值的类型,而不是使用 any

-function handleChange6({ value }: any) {
+function handleChange6({ value }: { value: boolean }) {
   console.log(value)
}
src/uni_modules/wot-design-uni/components/wd-switch/index.scss (2)

47-60: 建议将魔法数字提取为变量

内部文本样式的实现合理,但建议将一些固定值提取为 SCSS 变量以提高可维护性。

  @include e(inner) {
    color: #fff;
-    font-size: calc($-switch-circle-size/2.5);
+    $-switch-text-size-ratio: 2.5;
+    font-size: calc($-switch-circle-size/$-switch-text-size-ratio);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
-    padding: 0 4px 0 calc($-switch-circle-size * 2 + 8px);
+    $-switch-text-padding: 4px;
+    $-switch-text-offset: 8px;
+    padding: 0 $-switch-text-padding 0 calc($-switch-circle-size * 2 + $-switch-text-offset);
    user-select: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all 0.3s;
  }

69-71: 建议复用内边距变量

选中状态下的内边距调整也应该使用相同的变量。

    .wd-switch__inner{
-      padding: 0 calc($-switch-circle-size * 2 + 8px) 0 4px;
+      padding: 0 calc($-switch-circle-size * 2 + $-switch-text-offset) 0 $-switch-text-padding;
    }
docs/component/switch.md (2)

7-8: 移除非正式注释

文件头部包含 "记得注释" 这样的非正式提醒,建议在正式文档中移除此类注释。

- * 记得注释

60-64: 建议完善文字描述示例

当前示例可以更加完整,建议:

  1. 展示带有 v-model 的完整用例
  2. 添加更多常见场景的示例,如配合 disabled 状态的文字展示

建议修改示例如下:

-<wd-switch  active-text="喜欢摸鱼" inactive-text="讨厌摸鱼"  />
+<wd-switch v-model="checked" active-text="喜欢摸鱼" inactive-text="讨厌摸鱼" />
+
+<!-- 禁用状态下的文字展示 -->
+<wd-switch v-model="checked" active-text="开启" inactive-text="关闭" disabled />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 834cd8e and 71a82f6.

📒 Files selected for processing (5)
  • docs/component/switch.md (3 hunks)
  • src/pages/switch/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-switch/index.scss (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-switch/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-switch/wd-switch.vue (2 hunks)
🔇 Additional comments (5)
src/uni_modules/wot-design-uni/components/wd-switch/types.ts (1)

55-62: 类型定义完善且清晰!

新增的 activeTextinactiveText 属性定义合理,并且包含了清晰的 JSDoc 注释说明。

src/uni_modules/wot-design-uni/components/wd-switch/wd-switch.vue (1)

51-53: 计算属性实现简洁有效!

innerText 计算属性的实现逻辑清晰,能够根据开关状态正确显示对应文本。

src/pages/switch/Index.vue (1)

27-29: 示例实现清晰!

文字描述功能的演示示例实现恰当,展示了组件的新特性。

src/uni_modules/wot-design-uni/components/wd-switch/index.scss (1)

5-8: 布局结构优化合理!

使用 inline-flexalign-items: center 的布局方案合理,能够更好地控制内部元素的对齐。

docs/component/switch.md (1)

78-79: 补充属性说明的细节

建议为新增的文字属性补充以下信息:

  1. 文字长度是否有限制
  2. 文字样式是否可自定义
  3. 是否支持国际化配置

请确认以下几点:

  1. 文字是否有长度限制
  2. 是否支持自定义样式类
  3. 是否需要补充国际化相关说明
✅ Verification successful

文字属性实现说明

经过源码验证,可以明确以下几点:

  1. 文字长度没有特殊限制,可根据实际需求设置
  2. 支持自定义样式,可通过 customClasscustomStyle 属性进行样式定制
  3. 文字内容支持直接传入字符串,可配合应用层的国际化方案使用
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查组件源码中是否有文字长度限制或样式相关代码
ast-grep --pattern 'activeText.length' 
ast-grep --pattern 'inactiveText.length'

Length of output: 79


Script:

#!/bin/bash
# 查找 Switch 组件的源文件
fd -e vue -e tsx -e ts -e js switch

# 搜索文本属性的使用方式
ast-grep --pattern 'props: {
  $$$
  activeText: $_,
  $$$
}'

# 搜索样式相关代码
rg -i "class.*active.*text" -A 2

Length of output: 1067


Script:

#!/bin/bash
# 查看开关组件的源代码
cat src/uni_modules/wot-design-uni/components/wd-switch/wd-switch.vue

# 检查国际化相关代码
rg -i "i18n.*active.*text" 

Length of output: 2643

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