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(dropdown): [dropdown] add right side expansion function for dropdown #2608

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

MomoPoppy
Copy link
Collaborator

@MomoPoppy MomoPoppy commented Dec 4, 2024

…down

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new dropdown components with enhanced properties for better usability.
    • Added support for both static and dynamic dropdown menus, including hierarchical structures.
  • Improvements

    • Updated dropdown properties for clarity and specificity, such as max-height, multi-stage, and refined type definitions.
    • Enhanced styling for dropdown items to improve layout flexibility and standardized margin variables.
  • Documentation

    • Added a new demo showcasing the use of the placement attribute for dropdown positioning.

Copy link

coderabbitai bot commented Dec 4, 2024

Walkthrough

The pull request introduces significant modifications to the dropdown components in the project. Changes include updates to property types and the addition of new properties in the dropdown, dropdown-menu, and dropdown-item components. New Vue component files have been added to implement dropdown menus with static and dynamic content. Documentation enhancements include a new demo showcasing the use of the placement attribute. Styling adjustments in the associated LESS files standardize margin variables and improve layout flexibility for dropdown items.

Changes

File Path Change Summary
examples/sites/demos/apis/dropdown.js Updated property types and added new properties in dropdown, dropdown-menu, and dropdown-item.
examples/sites/demos/pc/app/dropdown/placement-composition-api.vue Added new Vue components: <tiny-dropdown>, <tiny-dropdown-menu>, and <tiny-dropdown-item>.
examples/sites/demos/pc/app/dropdown/placement.vue Added a new Vue component implementing dropdown menus with static and dynamic content.
examples/sites/demos/pc/app/dropdown/webdoc/dropdown.js Added a new demo entry for placement showcasing dropdown functionality.
packages/theme/src/dropdown-item/index.less Modified styling rules, renamed margin variables, and added new styles for dropdown positioning.
packages/theme/src/dropdown-item/vars.less Renamed margin-related variables for consistency in dropdown item styling.

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

In the meadow where dropdowns play,
New features hop in a joyful array.
With icons and options, all set to explore,
Our menus now dance, oh, what a score!
So let’s celebrate with a cheerful cheer,
For dropdowns are better, let’s give a big ear! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between abd9b06 and 64bdaaa.

📒 Files selected for processing (2)
  • examples/sites/demos/apis/dropdown.js (2 hunks)
  • packages/theme/src/dropdown-item/index.less (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/theme/src/dropdown-item/index.less
🔇 Additional comments (2)
examples/sites/demos/apis/dropdown.js (2)

374-377: LGTM! Good documentation practices.

The experimental tag and demo link are properly added for the new placement feature.


557-557: ⚠️ Potential issue

⚠️ Breaking Change: Removal of top placement options requires careful consideration

The modification of IPlacementType to remove 'top', 'top-start', and 'top-end' options is a breaking change that could impact existing implementations. This change should be handled with more care.

Recommendations:

  1. Consider maintaining backward compatibility by keeping the top placement options
  2. If removal is necessary:
    • Implement a deprecation cycle first
    • Add migration documentation
    • Bump major version number
    • Document this as a breaking change in the PR description

Alternative implementation that maintains compatibility:

-type IPlacementType =  'bottom-start' | 'bottom-end'
+type IPlacementType = 'top' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end'

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. (Experiment)
  • @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.

@github-actions github-actions bot added the enhancement New feature or request label Dec 4, 2024
@MomoPoppy
Copy link
Collaborator Author

image
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


image
image

@MomoPoppy MomoPoppy changed the title feat(dropdown): [dropdown] add right side expansion function for drop… feat(dropdown): [dropdown] add right side expansion function for dropdown Dec 4, 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: 4

🧹 Outside diff range and nitpick comments (1)
examples/sites/demos/pc/app/dropdown/placement-composition-api.vue (1)

23-50: Add JSDoc comments to document component purpose

The script section lacks documentation explaining the purpose of this demo and how it relates to the new right-side expansion feature.

Add descriptive comments:

+/**
+ * @description Demonstrates dropdown placement and expansion options
+ * Shows:
+ * - Different placement options (bottom-start, bottom-end)
+ * - Right-side expansion behavior
+ * - Static and dynamic dropdown content
+ */
<script setup>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a9a197a and 62b2793.

📒 Files selected for processing (6)
  • examples/sites/demos/apis/dropdown.js (1 hunks)
  • examples/sites/demos/pc/app/dropdown/placement-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/dropdown/placement.vue (1 hunks)
  • examples/sites/demos/pc/app/dropdown/webdoc/dropdown.js (1 hunks)
  • packages/theme/src/dropdown-item/index.less (3 hunks)
  • packages/theme/src/dropdown-item/vars.less (1 hunks)
🔇 Additional comments (4)
examples/sites/demos/pc/app/dropdown/placement.vue (1)

1-60: ⚠️ Potential issue

Maintain consistency with Composition API version

This Options API version should be updated to match the changes recommended for the Composition API version, including:

  1. Demonstration of right-side expansion
  2. Documentation comments
  3. Additional placement examples
packages/theme/src/dropdown-item/index.less (2)

72-72: LGTM: Consistent variable renaming for bi-directional support

The margin variable renaming from -margin-right to -margin-x better reflects their bi-directional usage, supporting both left and right expansion modes.

Also applies to: 91-91


158-202: LGTM: Well-structured right-side expansion styles

The implementation for right-side expansion is well thought out:

  • Uses flex-direction: row-reverse for layout
  • Properly handles icon transformations
  • Correctly positions child dropdowns using left: 100%
examples/sites/demos/pc/app/dropdown/webdoc/dropdown.js (1)

30-43: LGTM: Clear and complete documentation for placement feature

The new demo entry is well-documented:

  • Clear descriptions in both Chinese and English
  • Properly explains the bottom-start placement value
  • References the correct example file

Comment on lines +1 to +21
<template>
<tiny-dropdown>
<template #dropdown>
<tiny-dropdown-menu placement="bottom-start">
<tiny-dropdown-item label="老友粉"></tiny-dropdown-item>
<tiny-dropdown-item>黄金糕</tiny-dropdown-item>
<tiny-dropdown-item>狮子头</tiny-dropdown-item>
<tiny-dropdown-item>螺蛳粉</tiny-dropdown-item>
<tiny-dropdown-item disabled>双皮奶</tiny-dropdown-item>
<tiny-dropdown-item>蚵仔煎</tiny-dropdown-item>
</tiny-dropdown-menu>
</template>
</tiny-dropdown>
<br />
<br />
<tiny-dropdown>
<template #dropdown>
<tiny-dropdown-menu :options="options" placement="bottom-start"> </tiny-dropdown-menu>
</template>
</tiny-dropdown>
</template>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Demo should demonstrate right-side expansion functionality

The template only shows bottom-start placement without demonstrating the new right-side expansion feature that this PR introduces. Consider adding examples that showcase both left and right expansion behaviors.

Suggested additions:

 <tiny-dropdown>
   <template #dropdown>
-    <tiny-dropdown-menu placement="bottom-start">
+    <tiny-dropdown-menu placement="bottom-end">
       <tiny-dropdown-item label="老友粉"></tiny-dropdown-item>
       <!-- ... -->
     </tiny-dropdown-menu>
   </template>
 </tiny-dropdown>
+<!-- Add documentation comment explaining the different placement options -->
+<tiny-dropdown>
+  <template #dropdown>
+    <tiny-dropdown-menu placement="bottom-start" expand="right">
+      <!-- Add example with right expansion -->
+    </tiny-dropdown-menu>
+  </template>
+</tiny-dropdown>

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +38 to +41
// 展开图标的水平外边距
--tv-DropdownItem-expand-margin-x: var(--tv-space-md, 8px);
// 自定义图标的水平外边距
--tv-DropdownItem-pre-icon-margin-x: var(--tv-space-sm, 4px);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add variables to support right-side expansion

While renaming margin variables to be more generic is good, additional variables are needed to fully support right-side expansion functionality.

Consider adding:

 // 展开图标的水平外边距
 --tv-DropdownItem-expand-margin-x: var(--tv-space-md, 8px);
 // 自定义图标的水平外边距
 --tv-DropdownItem-pre-icon-margin-x: var(--tv-space-sm, 4px);
+// 右侧展开时的位置调整
+--tv-DropdownItem-expand-right-offset: var(--tv-space-xl, 16px);
+// 右侧展开时的图标旋转
+--tv-DropdownItem-expand-right-rotation: 270deg;
📝 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
// 展开图标的水平外边距
--tv-DropdownItem-expand-margin-x: var(--tv-space-md, 8px);
// 自定义图标的水平外边距
--tv-DropdownItem-pre-icon-margin-x: var(--tv-space-sm, 4px);
// 展开图标的水平外边距
--tv-DropdownItem-expand-margin-x: var(--tv-space-md, 8px);
// 自定义图标的水平外边距
--tv-DropdownItem-pre-icon-margin-x: var(--tv-space-sm, 4px);
// 右侧展开时的位置调整
--tv-DropdownItem-expand-right-offset: var(--tv-space-xl, 16px);
// 右侧展开时的图标旋转
--tv-DropdownItem-expand-right-rotation: 270deg;

Comment on lines +44 to 49
var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-expand-margin-x)
);
// 菜单项文本的左侧外边距
--tv-DropdownItem-label-margin-left: calc(
var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-pre-icon-margin-right)
var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-pre-icon-margin-x)
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update margin calculations for right-side expansion

The current margin calculations need to be updated to handle both left and right expansion scenarios.

Consider updating the calculations:

 --tv-DropdownItem-content-margin-left: calc(
-  var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-expand-margin-x)
+  var(--tv-expand-direction) * (var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-expand-margin-x))
 );
 --tv-DropdownItem-label-margin-left: calc(
-  var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-pre-icon-margin-x)
+  var(--tv-expand-direction) * (var(--tv-DropdownItem-icon-size) + var(--tv-DropdownItem-pre-icon-margin-x))
 );

Committable suggestion skipped: line range outside the PR's diff.

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

🧹 Outside diff range and nitpick comments (1)
packages/theme/src/dropdown-item/index.less (1)

159-203: Consider adding RTL support for right-side expansion.

The right-side expansion implementation looks good, but consider adding RTL (Right-to-Left) support for better internationalization.

Add RTL support by using logical properties:

 .@{dropdown-menu-prefix-cls}[x-placement='bottom-start'],
 .@{dropdown-menu-prefix-cls}[x-placement='top-start'] {
   .@{dropdown-item-prefix-cls}__wrap {
-    flex-direction: row-reverse;
+    flex-direction: row-reverse; /* For LTR */
+    [dir="rtl"] & {
+      flex-direction: row; /* For RTL */
+    }
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 62b2793 and abd9b06.

📒 Files selected for processing (2)
  • examples/sites/demos/apis/dropdown.js (2 hunks)
  • packages/theme/src/dropdown-item/index.less (4 hunks)
🔇 Additional comments (3)
packages/theme/src/dropdown-item/index.less (2)

17-17: LGTM: Variable declaration follows naming convention.

The new variable @dropdown-menu-prefix-cls follows the established pattern of using the css-prefix variable.


73-73: LGTM: Consistent margin variable naming.

The margin variables have been renamed from -right suffix to -x suffix, which better represents their bidirectional usage in the new right-side expansion feature.

Also applies to: 92-92

examples/sites/demos/apis/dropdown.js (1)

374-377: LGTM: Proper experimental feature marking.

The placement property is correctly marked as experimental with version 3.21.0.

@@ -551,7 +554,7 @@ type IButtonType = 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'i
name: 'IPlacementType',
type: 'type',
code: `
type IPlacementType = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end'
type IPlacementType = 'bottom-start' | 'bottom-end'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Breaking Change Confirmed: IPlacementType restriction impacts existing code

The verification shows extensive usage of 'top' related placement values across the codebase, particularly in:

  • Multiple tooltip components using 'top', 'top-start', and 'top-end' placements
  • Popover components relying on top placements
  • Various UI components (Select, Grid, Tree) using top positioning

The removal of these options from IPlacementType will break existing implementations. Specific impacts:

  • 80+ instances of top-related placements found in component templates
  • Test files containing top placement assertions
  • Demo and documentation examples showcasing top placement functionality

Recommendations:

  1. Maintain these placement options in the type definition
  2. If removal is necessary, implement a deprecation cycle first
  3. Document migration path in release notes
🔗 Analysis chain

Breaking Change: IPlacementType restriction.

The removal of 'top', 'top-start', and 'top-end' options from IPlacementType is a breaking change that could affect existing implementations.

Let's verify the impact:

Consider:

  1. Adding a migration guide
  2. Deprecating the removed options first
  3. Maintaining backward compatibility until the next major version

Let me gather more information to verify the impact comprehensively.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of removed placement values
rg -l "placement.*['\"]top(?:-start|-end)?['\"]" --type vue

# Also check documentation
rg "placement.*top" examples/sites/demos/apis/dropdown.js

Length of output: 242


Script:

#!/bin/bash
# Search for usage of placement prop with top values in all files
rg -A 2 "placement['\"]?\s*[:=]\s*['\"]top" 

# Search for IPlacementType usage
rg "IPlacementType"

# Search for any documentation or examples mentioning placement
fd "README|CHANGELOG|docs" --type f --exec rg -l "placement"

Length of output: 41346

zzcr
zzcr previously approved these changes Dec 11, 2024
@zzcr zzcr merged commit 95028d5 into opentiny:dev Dec 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants