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: ✨ datetime-picker新增right-icon插槽 #633

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

810505339
Copy link
Collaborator

@810505339 810505339 commented Sep 26, 2024

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

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • wd-datetime-picker 组件中添加了自定义右侧图标的功能,用户可以通过新的 right-icon 插槽进行定制。
    • 提供了基于状态的条件渲染示例,图标会根据选择器的状态变化。
  • 文档

    • 更新了文档以包含新的 right-icon 插槽及其使用示例。
  • 样式

    • 修改了 wd-pagination 组件的样式,更新了活动和禁用状态的颜色属性。

Copy link

vercel bot commented Sep 26, 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 Sep 27, 2024 1:25am

Copy link

coderabbitai bot commented Sep 26, 2024

Walkthrough

此次更改为 wd-datetime-picker 组件引入了一个新的功能,允许用户通过 right-icon 插槽自定义右侧图标。更新的文档展示了如何在 HTML 中实现该插槽,并提供了基于 isEmpty 变量状态变化的条件图标示例。此外,TypeScript 代码定义了 rightIconClick 函数,用于处理自定义图标的点击事件,打开日期时间选择器或清除值。

Changes

文件路径 更改摘要
docs/component/datetime-picker.md 添加了 right-icon 插槽的文档,更新了属性表以包含该插槽及其使用的最低版本。
src/pages/datetimePicker/Index.vue 添加了自定义图标的演示块,包含 value18 状态管理、isEmpty 计算属性及 rightIconClick 函数。
src/uni_modules/wot-design-uni/components/wd-datetime-picker/wd-datetime-picker.vue 添加了 right-icon 插槽,允许插入自定义右侧图标,保持现有图标的渲染条件不变。
src/uni_modules/wot-design-uni/components/wd-pagination/index.scss 修改了 wd-pagination 组件的 SCSS 文件中的激活和禁用状态的颜色属性。

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

🐇 在日期选择器中,图标新添,
自定义的乐趣,真是无边。
点击开关,清空或选择,
兔子欢跳,乐在其中间。
让我们一起,享受这变迁! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between df64340 and 9517e44.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-pagination/index.scss (2 hunks)
🔇 Additional comments (2)
src/uni_modules/wot-design-uni/components/wd-pagination/index.scss (2)

36-36: 更改为使用不透明度而非固定颜色值

这个更改从使用固定的颜色值转变为使用不透明度,这样做可以提高样式的灵活性,便于在不同主题间维护。

请确认这个改动在视觉上的效果是否符合预期。考虑添加一个测试用例或截图来验证活动状态导航元素的外观。


39-40: 更改为使用不透明度并移除注释掉的代码

这个更改类似于之前的修改,使用不透明度替代了固定的颜色值,这有助于提高样式的灵活性。

建议:

  1. 删除注释掉的旧代码 // color: rgba(0,0,0,0.15),以避免造成混淆。
  2. 考虑降低不透明度值。当前的 0.985 非常接近于完全不透明,可能与设计意图不符。建议重新评估这个值,确保它能够正确表现出禁用状态的视觉效果。

请验证这个高不透明度值(0.985)是否能够正确地表现出禁用状态的视觉效果。考虑添加一个测试用例或截图来确认禁用状态导航元素的外观。


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.

Copy link

netlify bot commented Sep 26, 2024

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9517e44
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/66f60928020b7c000826a7fe
😎 Deploy Preview https://deploy-preview-633--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: 2

🧹 Outside diff range and nitpick comments (3)
src/pages/datetimePicker/Index.vue (1)

36-44: 自定义图标功能实现正确,建议小幅改进。

新增的自定义图标功能实现得很好,符合PR的目标。条件渲染和事件处理的方式都很合适。

为了提高可访问性,建议在图标上添加 aria-label 属性:

- <wd-icon custom-class="wd-picker__arrow" :name="isEmpty ? 'arrow-right' : 'close'" />
+ <wd-icon custom-class="wd-picker__arrow" :name="isEmpty ? 'arrow-right' : 'close'" :aria-label="isEmpty ? '打开日期选择器' : '清除选择'" />

这样可以为使用屏幕阅读器的用户提供更好的体验。

docs/component/datetime-picker.md (1)

263-289: 代码示例整体不错,但有几处可以改进:

  1. HTML 示例中,view 标签应该改为 view,以符合小程序的标准。
  2. TypeScript 示例中,isEmpty 变量没有定义,需要添加其定义和用途说明。
  3. 考虑添加注释来解释 rightIconClick 函数的逻辑,特别是为什么在 isEmpty 时打开选择器,而在非空时清除值。

建议进行如下修改:

  1. 将 HTML 中的 view 改为 view
  2. 在 TypeScript 代码中添加 isEmpty 的定义,例如:
    const isEmpty = computed(() => !value.value || value.value.length === 0)
  3. rightIconClick 函数添加注释:
    /* right-icon点击事件 */
    function rightIconClick() {
      // 如果当前值为空,则打开日期时间选择器
      if (isEmpty.value) {
        dateTimePickerRef.value!.open()
        return
      }
      // 如果当前值不为空,则清空选择
      value.value = []
    }

这些改进将使示例代码更加完整和易于理解。

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

41-43: 新增的 right-icon 插槽实现良好,但可以稍作改进

这个新增的插槽为 datetime-picker 组件提供了更好的自定义性,允许用户根据需要替换默认的右侧图标。实现方式保持了向后兼容性,同时确保了在禁用或只读状态下不显示图标。

为了提高代码的可读性和可维护性,建议将条件判断提取为一个计算属性。例如:

+const showRightIcon = computed(() => !disabled && !readonly)

 <template>
   ...
-  <slot name="right-icon" :disabled="disabled" :readonly="readonly">
-    <wd-icon v-if="!disabled && !readonly" custom-class="wd-picker__arrow" name="arrow-right" />
+  <slot name="right-icon" :show="showRightIcon">
+    <wd-icon v-if="showRightIcon" custom-class="wd-picker__arrow" name="arrow-right" />
   </slot>
   ...
 </template>

这样可以使模板更加清晰,并且将逻辑集中到一处,便于future维护。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2666027 and 99ad5e3.

📒 Files selected for processing (3)
  • docs/component/datetime-picker.md (2 hunks)
  • src/pages/datetimePicker/Index.vue (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-datetime-picker/wd-datetime-picker.vue (1 hunks)
🔇 Additional comments not posted (3)
src/pages/datetimePicker/Index.vue (1)

75-75: 自定义图标功能的数据和计算属性实现正确。

新增的 value18 响应式引用、dateTimePickerRef 引用和 isEmpty 计算属性都实现得很好,为自定义图标功能提供了必要的数据支持。

Also applies to: 80-80, 177-179

docs/component/datetime-picker.md (2)

258-261: 新增的自定义图标功能说明清晰明了。

这个新增的部分很好地解释了如何使用新的 right-icon 插槽来自定义右侧图标。文档的这个添加对用户理解和使用新功能很有帮助。


Line range hint 258-365: 总体评价:文档更新质量良好,新功能说明清晰

此次更新很好地介绍了 DatetimePicker 组件的新功能 —— 自定义右侧图标。文档结构清晰,包含了使用示例和必要的 API 更新。我们提出的小改进主要集中在代码示例的完整性和 Slot 表格的细节上。实施这些建议将进一步提高文档的质量和用户友好性。

总的来说,这是一个很好的功能添加和文档更新。在解决了提到的小问题后,这个更新将为用户提供清晰和全面的指导,以充分利用新的 right-icon 插槽功能。

Comment on lines +181 to +188
function rightIconClick() {
if (isEmpty.value) {
dateTimePickerRef.value!.open()
return
}
value18.value = []
toast.success('清空成功')
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

建议改进 rightIconClick 函数中的空值处理。

rightIconClick 函数的实现逻辑正确,但在访问 dateTimePickerRef.value 时使用了非空断言操作符 (!),这可能在某些情况下导致运行时错误。

建议使用可选链操作符 (?.) 来安全地访问和调用 open 方法:

function rightIconClick() {
  if (isEmpty.value) {
-   dateTimePickerRef.value!.open()
+   dateTimePickerRef.value?.open()
    return
  }
  value18.value = []
  toast.success('清空成功')
}

这样可以避免在 dateTimePickerRef.valuenullundefined 时抛出错误。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function rightIconClick() {
if (isEmpty.value) {
dateTimePickerRef.value!.open()
return
}
value18.value = []
toast.success('清空成功')
}
function rightIconClick() {
if (isEmpty.value) {
dateTimePickerRef.value?.open()
return
}
value18.value = []
toast.success('清空成功')
}

@@ -328,6 +362,7 @@ const displayFormatTabLabel = (items) => {
|------|-----|---------|
| default | 使用默认插槽 | - |
| label | 左侧标题插槽 | - |
| right-icon | 右侧图标插槽 | $LOWEST_VERSION$ |
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Slot 表格更新正确,但版本号需要确定:

  1. 版本号占位符 $LOWEST_VERSION$ 需要替换为实际的版本号。
  2. 考虑为 right-icon 插槽添加更多详细信息,例如可用的作用域参数。

建议进行如下修改:

  1. $LOWEST_VERSION$ 替换为此功能首次引入的实际版本号。
  2. 扩展 right-icon 插槽的说明,例如:
    | right-icon | 右侧图标插槽。作用域参数:{ disabled, readonly } | x.x.x |
    其中 x.x.x 为实际版本号。

这些修改将使文档更加准确和有用。

@Moonofweisheng Moonofweisheng self-requested a review September 26, 2024 04:50
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