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(drop-menu): 支持自定义图标以及覆盖默认点击事件 #479

Merged
merged 5 commits into from
Aug 2, 2024

Conversation

ec50n9
Copy link
Contributor

@ec50n9 ec50n9 commented Aug 1, 2024

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

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

🔗 相关 Issue

💡 需求背景和解决方案

在开发中,可能会遇到一个下拉菜单栏里面包含一些非下拉菜单项(如下图),因此如果能提供自定义图标和自定义点击事件的话,能够简化开发。

image

解决方案:在下拉菜单项中添加 icon、icon-size、custom-click 等属性,以便用户传入自定义值来覆盖默认样式和行为。

注意:其中 custom-click 的定义方式还有待斟酌,目前是使用 props 来传入一个函数来进行自定义的,因为如果通过 emit 来传入的话,在下拉菜单容器中不知如何检测菜单项是否有定义自定义事件,使用 props 来传入的话则简单些。

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

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

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

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能

    • 增加自定义下拉菜单图标和大小的功能。
    • 支持为菜单项定义自定义点击事件处理程序。
    • 新增下拉菜单项“地图”和“延迟 0.5s 展开”,增强用户交互体验。
  • 文档

    • 更新文档示例,展示新特性和用法。
    • 详细介绍新增属性及其默认值。

Copy link

netlify bot commented Aug 1, 2024

👷 Deploy request for wot-design-uni accepted.

Name Link
🔨 Latest commit a84da73
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/66ac508e7a30ea00086f097c

Copy link

vercel bot commented Aug 1, 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 Aug 2, 2024 3:22am

Copy link

coderabbitai bot commented Aug 1, 2024

Walkthrough

此次更改为下拉菜单组件添加了多个增强功能,包括自定义菜单图标和大小的新属性,使开发者能够创建更具吸引力的界面。此外,引入的自定义点击事件处理程序为菜单项提供了灵活的交互方式。这些更改使组件更具可定制性和交互性,提升用户体验。

Changes

文件 更改摘要
docs/component/drop-menu.md 添加自定义菜单图标和大小属性,新增自定义点击事件,更新文档示例以展示新功能。
src/pages/dropMenu/Index.vue 在组件中添加新下拉菜单项“地图”,绑定点击事件以处理用户交互,增加延迟展开的功能。
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts 添加新属性iconiconSizebeforeToggle以增强菜单项的功能和可定制性。
src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue 重构点击事件处理,支持自定义点击行为,更新图标显示逻辑以支持动态绑定。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DropMenu
    participant MenuItem

    User->>DropMenu: 点击下拉菜单
    DropMenu->>MenuItem: 显示菜单项
    User->>MenuItem: 点击菜单项
    MenuItem->>DropMenu: 调用自定义点击事件(如果定义)
    MenuItem->>DropMenu: 否则调用默认切换功能
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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

Outside diff range, codebase verification and nitpick comments (2)
docs/component/drop-menu.md (2)

115-117: 确保文档清晰

在描述自定义菜单图标和图标尺寸时,确保说明清晰易懂,并提供具体示例。

+ 可以通过 icon 设置菜单右侧图标,等同于 `<wd-icon />` 的 name 属性。通过 icon-size 设置图标尺寸,等同于 `<wd-icon />` 的 size 属性。

119-119: 确保文档清晰

在描述自定义点击事件时,确保说明清晰易懂,并提供具体示例。

+ 可以通过 custom-click 来自定义菜单点击事件,不传则默认展开菜单。
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 84826f8 and 668b61d.

Files selected for processing (4)
  • docs/component/drop-menu.md (2 hunks)
  • src/pages/dropMenu/Index.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (2 hunks)
Additional comments not posted (11)
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (3)

37-37: 新增 icon 属性

icon 属性定义正确,默认值为 'arrow-down',与现有代码库保持一致。


41-41: 新增 iconSize 属性

iconSize 属性定义正确,默认值为 '14px',与现有代码库保持一致。


45-45: 新增 customClick 属性

customClick 属性定义正确,允许用户自定义点击事件处理函数,与现有代码库保持一致。

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

10-10: 更新 @click 事件绑定

@click 事件绑定现在调用 handleItemClick 函数,改动合理。


93-99: 新增 handleItemClick 函数

handleItemClick 函数定义正确,能够处理自定义和默认点击事件。

src/pages/dropMenu/Index.vue (2)

37-37: 新增自定义下拉菜单项

自定义下拉菜单项定义正确,属性配置合理,集成到现有组件中。


125-127: 新增 handleMapClick 函数

handleMapClick 函数定义正确,增强了组件的交互性。

docs/component/drop-menu.md (4)

121-125: 示例代码清晰

示例代码展示了如何使用新属性,确保示例代码准确无误。

<wd-drop-menu>
  <wd-drop-menu-item title="地图" icon="location" icon-size="24px" :custom-click="handleClick" />
</wd-drop-menu>

127-131: 示例代码清晰

示例代码展示了如何定义自定义点击事件,确保示例代码准确无误。

function handleClick() {
  console.log('点击了地图')
}

171-173: 确保属性描述准确

确保新属性在表格中的描述准确,并与其他属性一致。

| icon      | 菜单图标                                                           | string            | -       | arrow-down | -     |
| icon-size | 菜单图标尺寸                                                        | string            | -       | 14px | _       |
| custom-click | 菜单点击事件                                                     | function          | -       | -      | -      |

173-173: 确保属性描述准确

确保新属性在表格中的描述准确,并与其他属性一致。

| custom-click | 菜单点击事件                                                     | function          | -       | -      | -      |

Copy link
Owner

@Moonofweisheng Moonofweisheng left a comment

Choose a reason for hiding this comment

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

是否可以将custom-click替换为before-toggle既可实现自定义点击事件,又可以实现异步打开或关闭

@ec50n9
Copy link
Contributor Author

ec50n9 commented Aug 2, 2024

是否可以将custom-click替换为before-toggle既可实现自定义点击事件,又可以实现异步打开或关闭

好主意,我尝试修改一下

@ec50n9
Copy link
Contributor Author

ec50n9 commented Aug 2, 2024

是否可以将custom-click替换为before-toggle既可实现自定义点击事件,又可以实现异步打开或关闭

我已经按照您的意见将custom-click替换为before-toggle,并且更新了相关代码。这些修改已经提交到PR分支上了(我还没尝试过在提交pr后继续commit代码,所以不太确定你是否能看到我今天新的commit,如果看不到的话麻烦提醒我一下,我检查检查🧐)。

请您再次检查一下更新后的代码,看看是否符合您的预期。如果还有任何需要调整或改进的地方,请告诉我,我会尽快进行修改。
再次感谢您的反馈和指导🙏。

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 668b61d and 5ff143b.

Files selected for processing (4)
  • docs/component/drop-menu.md (2 hunks)
  • src/pages/dropMenu/Index.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (2 hunks)
Files skipped from review as they are similar to previous changes (4)
  • docs/component/drop-menu.md
  • src/pages/dropMenu/Index.vue
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts
  • src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue

@Moonofweisheng
Copy link
Owner

是否可以将custom-click替换为before-toggle既可实现自定义点击事件,又可以实现异步打开或关闭

我已经按照您的意见将custom-click替换为before-toggle,并且更新了相关代码。这些修改已经提交到PR分支上了(我还没尝试过在提交pr后继续commit代码,所以不太确定你是否能看到我今天新的commit,如果看不到的话麻烦提醒我一下,我检查检查🧐)。

请您再次检查一下更新后的代码,看看是否符合您的预期。如果还有任何需要调整或改进的地方,请告诉我,我会尽快进行修改。 再次感谢您的反馈和指导🙏。

感谢你的PR!有一点可以做个调整,可以参考before-uploadbefore-toggle做个类型标注。

@ec50n9
Copy link
Contributor Author

ec50n9 commented Aug 2, 2024

感谢提醒!已修正😁

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ff143b and a84da73.

Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts

@Moonofweisheng Moonofweisheng merged commit 108e1b3 into Moonofweisheng:master Aug 2, 2024
1 check passed
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.

2 participants