Skip to content

feat: ✨ radio添加iconPlacement属性用于控制图标方向#763

Merged
Moonofweisheng merged 2 commits intoMoonofweisheng:masterfrom
RJQingHuan:feat-radio-position
Dec 7, 2024
Merged

feat: ✨ radio添加iconPlacement属性用于控制图标方向#763
Moonofweisheng merged 2 commits intoMoonofweisheng:masterfrom
RJQingHuan:feat-radio-position

Conversation

@RJQingHuan
Copy link
Copy Markdown
Collaborator

@RJQingHuan RJQingHuan commented Dec 7, 2024

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

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

🔗 相关 Issue

close #371

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新特性

    • 更新了 wd-radio 组件文档,新增 icon-placement 属性,支持图标位置的自定义(左、右、自动)。
    • 引入 checked-color 属性,允许自定义选中颜色。
    • 增加 disabled 属性,支持禁用单个或整个 radio-group
    • 改进文档结构,提高可读性。
  • 样式

    • 添加 .icon-placement-left.icon-placement-right 类,以支持图标位置的样式调整。

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 7, 2024

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 Dec 7, 2024 8:37am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 7, 2024

Walkthrough

此次变更主要针对 wd-radio 组件的文档和代码进行了更新。文档中新增了 icon-placement 属性,允许用户设置图标的位置(左、右、自动),并对 cellinline 属性的用法进行了重构。代码方面,types.ts 文件中添加了新的类型和属性以支持图标位置的配置,同时在样式文件中引入了新的样式类以适应图标位置的变化。

Changes

文件路径 变更摘要
docs/component/radio.md 更新文档,新增 icon-placement 属性,重构 cellinline 属性的用法,增强可读性。
src/uni_modules/wot-design-uni/components/wd-radio-group/types.ts 添加新类型 RadioIconPlacement,在 RadioGroupProvide 中新增 iconPlacement 属性。
src/uni_modules/wot-design-uni/components/wd-radio/index.scss 新增 .icon-placement-left.icon-placement-right 样式类,调整图标位置的样式。
src/uni_modules/wot-design-uni/components/wd-radio/types.ts 新增 RadioIconPlacement 类型及 iconPlacement 属性,更新 radioProps
src/uni_modules/wot-design-uni/components/wd-radio/wd-radio.vue 更新模板和脚本,新增 iconPlacement 计算属性,动态应用图标位置样式。

Assessment against linked issues

Objective Addressed Explanation
增加配置字段以设置图标位置 (#[371])
提供左/右位置的 API (#[371])

Possibly related PRs

Suggested reviewers

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

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 7, 2024

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2c14a6c
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/675408df7ab0940008c51a0b
😎 Deploy Preview https://deploy-preview-763--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
Copy Markdown

@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: 1

🧹 Outside diff range and nitpick comments (8)
src/uni_modules/wot-design-uni/components/wd-radio-group/types.ts (1)

2-2: 代码变更合理,建议补充注释说明

代码结构清晰,类型定义准确。建议为 RadioIconPlacement 类型添加详细的 JSDoc 注释,说明每个可选值的具体用途。

 import type { RadioShape, RadioIconPlacement } from '../wd-radio/types'
+
+/**
+ * 图标位置类型
+ * @property {'left'} - 图标位于文本左侧
+ * @property {'right'} - 图标位于文本右侧
+ * @property {'auto'} - 自动判断图标位置
+ */

Also applies to: 14-14, 37-38

src/uni_modules/wot-design-uni/components/wd-radio/types.ts (1)

15-16: 类型定义完善,建议优化类型注释

类型定义和属性配置合理。建议:

  1. RadioIconPlacement 类型添加详细的类型注释
  2. iconPlacement 属性注释中说明 null 值的作用(继承父组件配置)
+/**
+ * 单选框图标位置
+ * @description 控制单选框中图标相对于文本的位置
+ */
 export type RadioIconPlacement = 'left' | 'right' | 'auto'

   /** 图标位置,默认为 left */
+  /** 
+   * 图标位置
+   * @description 控制图标相对于文本的位置
+   * @default null - 继承父组件 RadioGroup 的配置
+   */
   iconPlacement: {
     type: [String, null] as PropType<RadioIconPlacement>,
     default: null
   }

Also applies to: 44-48

src/uni_modules/wot-design-uni/components/wd-radio/wd-radio.vue (2)

7-7: 模板绑定方式需要优化

当前的模板字符串拼接方式可能导致类名出现空格问题。建议使用数组方式处理类名绑定。

-    } icon-placement-${iconPlacement} ${customClass}`"
+    } icon-placement-${iconPlacement}`, customClass]"

90-96: 计算属性实现合理,建议添加单元测试

计算属性 iconPlacement 的实现遵循了组件内其他继承属性的模式,逻辑正确。建议:

  1. 添加对应的单元测试用例,验证属性继承逻辑
  2. 测试不同的父组件配置场景

需要我帮您生成对应的单元测试代码吗?

docs/component/radio.md (2)

152-162: 建议完善文档的一致性

建议对文档做如下改进:

  1. 为新增的 icon-placement 属性添加使用示例
  2. 补充属性的默认值对组件行为的影响说明

166-168: 建议补充事件参数说明

change 事件的参数说明过于简略,建议详细说明 value 的类型和可能的值。

src/uni_modules/wot-design-uni/components/wd-radio/index.scss (2)

175-177: 建议考虑 RTL 布局支持

当前的图标位置切换实现使用了 flex-direction: row-reverse,这可能会影响 RTL(从右到左)布局的正确性。建议考虑使用更灵活的实现方式。

建议参考以下实现方式:

.icon-placement-left {
-  flex-direction: row-reverse;
+  .wd-radio__shape {
+    order: -1;
+    margin-right: 4px;
+    margin-left: 0;
+  }
}

209-215: 建议优化内联模式下的图标位置样式

当前实现在内联模式下使用了 float 布局,这可能会导致一些布局问题。建议统一使用 flex 布局来处理图标位置。

建议参考以下实现:

&.icon-placement-right {
  .wd-radio__shape {
-    margin-right: 0;
-    margin-left: 4px;
-    float: right;
+    order: 1;
+    margin-left: 4px;
+    margin-right: 0;
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3cd5137 and 2c14a6c.

📒 Files selected for processing (5)
  • docs/component/radio.md (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-radio-group/types.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-radio/index.scss (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-radio/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-radio/wd-radio.vue (3 hunks)

Comment on lines +172 to +177
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
| ------------- | --------------------------------------------- | ------------------------- | -------------------- | ------- | -------- |
| value | 单选框选中时的值。会自动匹配radioGroup的value | string / number / boolean | - | - | - |
| shape | 单选框形状 | string | dot / button / check | check | - |
| checked-color | 选中的颜色 | string | - | #4D80F0 | - |
| disabled | 禁用 | boolean | - | false | - |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议补充 Radio 组件的 icon-placement 属性说明

为保持与 RadioGroup 的一致性,建议在 Radio 属性表中也添加 icon-placement 属性的说明,并说明其优先级。

@Moonofweisheng Moonofweisheng merged commit b06a7a7 into Moonofweisheng:master Dec 7, 2024
@RJQingHuan RJQingHuan deleted the feat-radio-position branch December 10, 2024 08:52
@55555778
Copy link
Copy Markdown

牛哇牛哇!

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.

单选 O 框的位置设置,是否可以增加配置字段,设置左右位置。

3 participants