Skip to content

fix: 🐛 修复 Divider 分割线组件 CustomClass 未生效的问题#790

Merged
Moonofweisheng merged 1 commit intomasterfrom
fix/divider-custom-class
Dec 17, 2024
Merged

fix: 🐛 修复 Divider 分割线组件 CustomClass 未生效的问题#790
Moonofweisheng merged 1 commit intomasterfrom
fix/divider-custom-class

Conversation

@Moonofweisheng
Copy link
Owner

@Moonofweisheng Moonofweisheng commented Dec 17, 2024

Closes: #789

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

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

🔗 相关 Issue

#789

💡 需求背景和解决方案

为divider添加custom-class

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

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

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

Summary by CodeRabbit

  • 新功能
    • 更新了分隔符组件的样式处理方式,提升了样式管理的清晰度和可维护性。
  • 改进
    • 简化了类逻辑,增强了类型安全性。

@vercel
Copy link

vercel bot commented Dec 17, 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 17, 2024 0:06am

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2024

概述

演练

此次更改主要涉及分隔线(Divider)组件的类型定义和实现。在 types.ts 中,color 属性的类型定义被简化。在 wd-divider.vue 中,组件的样式和类处理逻辑进行了重构,增加了更明确的类型处理和样式管理,并引入了 objToStyle 工具函数来处理样式转换。

变更

文件 变更摘要
src/uni_modules/wot-design-uni/components/wd-divider/types.ts color 属性类型从 makeStringProp('') 变更为 String
src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue 1. 新增 CSSProperties 类型导入
2. 引入 objToStyle 工具函数
3. 重构 rootStyle 计算属性
4. 简化 rootClass 计算属性逻辑

针对链接问题的评估

目标 是否解决 说明
添加 customClass 参数 [#789]

诗歌

兔子轻跳代码行,
分隔线变得更精妆,
样式优雅如丝绸,
类型严谨显神通,
重构之路,兔子欢畅!🐰✨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

@netlify
Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit d971b5a
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/676169497daf4b0008e852ee
😎 Deploy Preview https://deploy-preview-790--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 (2)
src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue (2)

26-31: 样式处理逻辑优化

使用 CSSProperties 类型和 objToStyle 工具函数重构了样式处理逻辑,使代码更加类型安全和可维护。建议考虑以下改进:

 const rootStyle = computed(() => {
   const { color } = props
   const style: CSSProperties = {}
   if (color) {
-    style.color = color
+    style.borderColor = color
   }
   return `${objToStyle(style)};${props.customStyle}`
 })

41-43: 建议优化条件判断的可读性

当前的条件判断逻辑有些重复,建议提取共同条件:

-    [`${prefixCls}--center`]: !props.vertical && !!slots.default,
-    [`${prefixCls}--left`]: !props.vertical && props.contentPosition === 'left',
-    [`${prefixCls}--right`]: !props.vertical && props.contentPosition === 'right',
+    const isHorizontal = !props.vertical;
+    [`${prefixCls}--center`]: isHorizontal && !!slots.default,
+    [`${prefixCls}--left`]: isHorizontal && props.contentPosition === 'left',
+    [`${prefixCls}--right`]: isHorizontal && props.contentPosition === 'right',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3bee13 and d971b5a.

📒 Files selected for processing (2)
  • src/uni_modules/wot-design-uni/components/wd-divider/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue (1 hunks)
🔇 Additional comments (4)
src/uni_modules/wot-design-uni/components/wd-divider/types.ts (1)

12-12: 类型定义的改进看起来不错!

color 属性的类型从 makeStringProp('') 简化为 String 是一个合理的改动,使类型定义更加直观。

src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue (3)

18-20: 导入声明更加完整和规范

添加了 CSSProperties 类型和 objToStyle 工具函数的导入,增强了类型安全性和样式处理能力。


36-46: 类名处理逻辑优化,修复了 CustomClass 问题

重构后的代码:

  1. 使用对象统一管理类名,提高了代码可读性
  2. 正确处理了 customClass 的应用,解决了原有问题
  3. 条件判断更加清晰

这个改动很好地解决了 PR 的主要目标:修复 CustomClass 未生效的问题。


44-44: 验证 CustomClass 修复

请验证 CustomClass 在以下场景中是否正常工作:

✅ Verification successful

CustomClass 属性验证已完成

根据代码检查结果,CustomClass 的实现是正确的:

  • 在组件的计算属性 rootClass 中正确处理了 customClass 属性:[props.customClass]: !!props.customClass
  • 组件文档中已列出 custom-class 作为外部样式类
  • 组件模板中通过 :class="rootClass" 正确应用了样式类

自定义样式类功能已正确实现,可以放心使用。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索 wd-divider 组件的使用示例
rg -l "wd-divider.*customClass"

# 检查测试用例
rg -l "customClass.*wd-divider" -g "*test*"

Length of output: 228


Script:

#!/bin/bash
# 搜索组件文档和示例
fd -e md -e vue | xargs rg -l "customClass.*wd-divider|wd-divider.*customClass"

# 检查组件定义中的 customClass 实现
ast-grep --pattern 'props: {
  $$$
  customClass: {
    $$$
  }
  $$$
}'  src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue

# 检查组件模板中的 customClass 使用
ast-grep --pattern '<template>
  $$$
  class="$$$"
  $$$
</template>' src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue

Length of output: 364


Script:

#!/bin/bash
# 检查组件文件内容
cat src/uni_modules/wot-design-uni/components/wd-divider/wd-divider.vue

# 搜索示例文档
fd "divider" -e md | xargs cat

# 搜索组件测试文件
fd "divider.*test" | xargs cat

Length of output: 3520

@Moonofweisheng Moonofweisheng merged commit 44df081 into master Dec 17, 2024
@Moonofweisheng Moonofweisheng deleted the fix/divider-custom-class branch December 17, 2024 12:11
@coderabbitai coderabbitai bot mentioned this pull request May 5, 2025
19 tasks
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.

[Bug 上报] wd-divider缺失customClass参数

1 participant