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: ✨ Curtain 幕帘新增 close 插槽和自定义关闭插槽样式类 #746

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

Moonofweisheng
Copy link
Owner

@Moonofweisheng Moonofweisheng commented Nov 29, 2024

Closes: #648

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

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

🔗 相关 Issue

#648

💡 需求背景和解决方案

curtain 添加 close 插槽,和自定义样式类,支持自定义关闭按钮。

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了 wd-curtain 组件的文档,增加了 TypeScript 示例代码,提升了使用说明的清晰度和完整性。
    • 在模板中新增了自定义关闭按钮的演示。
    • 引入了新的插槽和外部样式类,增强了关闭按钮的自定义选项。
  • 文档

    • 改进了 wd-curtain 组件的属性和事件部分的可读性,增加了新的插槽和样式说明。

Copy link

vercel bot commented Nov 29, 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 Nov 29, 2024 5:01am

Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

此次更改主要涉及对 wd-curtain 组件的文档和实现的更新。文档中增加了 TypeScript 代码示例,详细说明了组件的使用方法和属性,特别是关于自定义关闭按钮的样式和功能。组件的模板和脚本部分进行了调整,以支持新的插槽和样式属性,增强了组件的灵活性和可维护性。

Changes

文件路径 更改摘要
docs/component/curtain.md 更新文档,增加 TypeScript 示例,重新格式化属性和事件部分,新增插槽和外部样式类。
src/pages/curtain/Index.vue 新增 "自定义关闭按钮" 演示块,添加 wd-curtain 组件,定义 value9 和相关的处理函数。
src/uni_modules/wot-design-uni/components/wd-curtain/types.ts curtainProps 中新增 customCloseClasscustomCloseStyle 属性。
src/uni_modules/wot-design-uni/components/wd-curtain/wd-curtain.vue 修改模板以支持关闭图标的插槽,更新脚本逻辑以使用计算属性,简化图像样式的处理。

Assessment against linked issues

Objective Addressed Explanation
新增 close-icon-nameclose-icon-sizeclose-icon-color 属性 (648) 该 PR 中未包含这些新属性的实现。
更新文档以补充新属性和功能说明 (648)
提供示例以展示新属性的使用 (648) 示例中未展示新属性的使用。
增强组件的灵活性和可维护性 (648)

Poem

🐰 在幕帘中轻舞飞扬,
自定义按钮真是好,
新样式让人心欢畅,
代码更新如春风,
文档清晰又明亮! 🌼
兔子欢呼,乐无穷!


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 Nov 29, 2024

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit 3037284
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67494a9c85e03d0008527b09
😎 Deploy Preview https://deploy-preview-746--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 (7)
src/uni_modules/wot-design-uni/components/wd-curtain/types.ts (1)

53-53: 建议增加样式字符串格式校验

为了避免无效的样式字符串导致运行时错误,建议添加样式字符串格式的验证。

-  customCloseStyle: makeStringProp('')
+  customCloseStyle: {
+    type: String,
+    default: '',
+    validator: (value: string) => {
+      // 验证是否为有效的 CSS 样式字符串
+      return /^([\w-]+\s*:\s*[^;]+;\s*)*$/.test(value);
+    }
+  }
src/uni_modules/wot-design-uni/components/wd-curtain/wd-curtain.vue (2)

23-30: 插槽实现符合预期,建议补充文档说明

新增的关闭按钮插槽实现合理,保持了良好的向后兼容性。默认插槽内容使用 wd-icon 组件,并支持自定义样式类和样式。

建议在组件文档中补充以下使用示例:

<wd-curtain>
  <template #close>
    <view class="custom-close">关闭</view>
  </template>
</wd-curtain>

89-96: 建议优化计算属性的实现方式

imgStyle 改为计算属性是很好的改进,但实现方式可以更优雅。

建议使用对象方式返回样式:

-const imgStyle = computed(() => {
-  let style = ''
-  if (props.width) {
-    style += `width: ${props.width}px ;`
-    style += `height: ${props.width / imgScale.value}px`
-  }
-  return style
-})
+const imgStyle = computed(() => {
+  if (!props.width) return {}
+  return {
+    width: `${props.width}px`,
+    height: `${props.width / imgScale.value}px`
+  }
+})
src/pages/curtain/Index.vue (2)

60-60: 建议重构重复的处理函数

当前的实现方式虽然可行,但存在大量重复的处理函数模式。建议将这些处理函数统一封装,以提高代码的可维护性。

-const value1 = ref<boolean>(false)
-const value2 = ref<boolean>(false)
-// ... more value refs
+const curtainStates = ref<Record<number, boolean>>({})
+
+function handleClick(index: number) {
+  curtainStates.value[index] = true
+}
+
+function handleClose(index: number) {
+  curtainStates.value[index] = false
+}

Also applies to: 113-118


129-135: 建议优化关闭按钮的可点击区域

为了提升移动端的用户体验,建议:

  1. 增加按钮的可点击区域
  2. 添加触摸反馈效果
 .custom-close {
   position: absolute;
   top: 10px;
   right: 10px;
   color: #ffffff;
   font-size: 32rpx;
+  padding: 20rpx;
+  cursor: pointer;
+  &:active {
+    opacity: 0.8;
+  }
 }
docs/component/curtain.md (2)

Line range hint 20-30: 建议优化重复的代码示例

代码示例在多个部分中完全重复。建议考虑以下改进方案:

  1. 在文档开始处提供一个完整的代码示例
  2. 在后续部分中仅展示与该特定功能相关的代码差异部分

Also applies to: 43-53, 66-76, 89-99


Line range hint 1-144: 建议添加关闭按钮插槽的使用示例

文档中缺少如何使用自定义关闭按钮插槽的示例代码。建议添加一个新的示例部分,展示:

  1. 如何使用 close 插槽
  2. 如何应用 custom-close-classcustom-close-style

示例代码参考:

<wd-button @click="handleClick">展示自定义关闭按钮的幕帘</wd-button>
<wd-curtain 
  :value="value" 
  :src="img" 
  @close="handleClose"
  custom-close-class="my-close-class"
  custom-close-style="color: red;"
>
  <template #close>
    <view class="custom-close">关闭</view>
  </template>
</wd-curtain>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 09f7f9c and 3037284.

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

41-53: 新属性实现完善且符合需求

新增的 customCloseClasscustomCloseStyle 属性实现规范,类型定义清晰,文档注释完整。这些属性很好地满足了自定义关闭按钮样式的需求。

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

50-50: 导入声明更新合理

从 Vue 中导入 computed 用于优化响应式属性的实现是一个很好的改进。


76-81: watch 逻辑简化提升了代码可读性

watch 逻辑的改进很好地处理了图片加载状态和显示逻辑的关系。

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

22-24: 代码结构清晰,实现符合需求!

新增的自定义关闭按钮示例完全符合需求,代码组织良好,slot 的使用也符合 Vue 的最佳实践。

Also applies to: 42-46

docs/component/curtain.md (2)

105-114: 属性表格内容完整且清晰

属性表格结构合理,包含了所有必要的字段说明。


118-131: 事件表格内容准确完整

事件表格包含了完整的事件列表,描述清晰准确。

Comment on lines +132 to +136
## Slots

| name | 说明 | 最低版本 |
| ----- | ------------ | ---------------- |
| close | 关闭按钮插槽 | $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

需要更新版本号占位符

插槽表格中的 $LOWEST_VERSION$ 需要替换为实际的版本号。

Comment on lines +140 to +144
| 类名 | 说明 | 最低版本 |
| ------------------ | -------------- | ---------------- |
| custom-class | 根节点样式 | - |
| custom-close-class | 关闭按钮样式类 | $LOWEST_VERSION$ |
| custom-close-style | 关闭按钮样式 | $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

样式类定义完整,但需要更新版本号

外部样式类的添加符合需求,支持自定义关闭按钮样式。但是:

  1. custom-close-class 的版本号占位符需要替换
  2. custom-close-style 的版本号占位符需要替换

@Moonofweisheng Moonofweisheng merged commit 7bc3592 into master Nov 29, 2024
7 checks passed
@Moonofweisheng Moonofweisheng deleted the feature/curtain-close branch November 29, 2024 05:09
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