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: add placement for Drawer #4958

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Nov 27, 2024

Description

Drawer新增placement属性,用于控制抽屉的弹出方向。close: #4952

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new placement property for the Vben Drawer component, allowing users to specify its position as 'left', 'right', 'top', or 'bottom'.
    • Enhanced example interface with multiple buttons to open the drawer in different placements, improving user interaction.
  • Documentation

    • Updated documentation to clarify the new placement property and its usage, including parameter handling and state management guidance.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners November 27, 2024 02:12
Copy link

changeset-bot bot commented Nov 27, 2024

⚠️ No Changeset found

Latest commit: 63e6176

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

The pull request introduces a new placement property to the Vben Drawer component, allowing users to specify its position as 'left', 'right', 'top', or 'bottom', with a default of 'right'. Documentation has been updated to reflect this change, clarifying parameter handling priorities. The DrawerApi class and related interfaces have been modified to include this new property, enhancing the configurability of the drawer component. Additionally, the component's layout and behavior have been adjusted in the drawer.vue file to accommodate the new placement property.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-drawer.md Updated documentation to include placement property and clarify parameter handling priorities.
packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts Added placement property to defaultState in DrawerApi class.
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts Introduced DrawerPlacement type and added placement property to DrawerProps interface.
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue Modified layout handling for placement property, enhancing responsive design.
playground/src/views/examples/drawer/index.vue Updated openBaseDrawer function to accept placement parameter and added buttons for each placement.

Assessment against linked issues

Objective Addressed Explanation
Add placement field to the Drawer component for customizable direction (4952)

Possibly related PRs

Suggested reviewers

  • vince292007

Poem

In a drawer snug and tight,
New placements bring delight!
Left or right, or up and down,
Open wide, don’t wear a frown!
With options bright, let’s take a chance,
A drawer dance—come join the prance! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts

Oops! Something went wrong! :(

ESLint: 9.15.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


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
Contributor

@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 (8)
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (1)

78-82: Consider enhancing the property documentation.

While the documentation includes the default value, it would be helpful to add more details about:

  • The purpose of this property
  • The effect of each placement value
  • Any layout implications
  /**
-   * 抽屉位置
+   * Controls the placement direction of the drawer
+   * - 'left': Drawer slides in from the left edge
+   * - 'right': Drawer slides in from the right edge
+   * - 'top': Drawer slides in from the top edge
+   * - 'bottom': Drawer slides in from the bottom edge
    * @default right
    */
packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (1)

44-44: Consider adding JSDoc for the placement property.

To improve code documentation and IDE support, consider adding a JSDoc comment explaining the available placement options and their effects.

+      /** Position of the drawer. Can be 'left', 'right', 'top', or 'bottom'. */
       placement: 'right',
playground/src/views/examples/drawer/index.vue (2)

16-16: Remove commented code

The commented placement configuration appears to be debugging code. It should be removed to maintain code cleanliness.

-  // placement: 'left',

86-95: Consider accessibility and DRY improvements

The buttons implementation is functionally correct but could be enhanced:

  1. Add aria-labels for better accessibility
  2. Consider using a more DRY approach for button styling
-      <Button type="primary" @click="openBaseDrawer('right')">右侧打开</Button>
-      <Button class="ml-2" type="primary" @click="openBaseDrawer('bottom')">
+      <Button 
+        type="primary" 
+        aria-label="Open drawer from right" 
+        @click="openBaseDrawer('right')"
+      >
+        右侧打开
+      </Button>
+      <Button 
+        class="ml-2" 
+        type="primary" 
+        aria-label="Open drawer from bottom"
+        @click="openBaseDrawer('bottom')"
+      >

Consider creating a reusable component for these buttons to reduce repetition:

<script setup lang="ts">
const props = defineProps<{
  placement: DrawerPlacement;
  label: string;
}>();
</script>

<template>
  <Button 
    class="ml-2" 
    type="primary"
    :aria-label="`Open drawer from ${placement}`"
    @click="openBaseDrawer(placement)"
  >
    {{ label }}
  </Button>
</template>
docs/src/components/common-ui/vben-drawer.md (3)

91-91: Documentation for placement property needs enhancement.

While the basic information is provided, consider enhancing the documentation to:

  1. Add a description in Chinese to maintain consistency with the bilingual format
  2. Include example usage for each placement value
  3. Clarify the visual behavior for each placement option

Consider updating the line to:

-| placement | 抽屉弹出位置 | `'left'\|'right'\|'top'\|'bottom'` | `right` |
+| placement | 抽屉弹出位置 (控制抽屉弹出方向) | `'left'\|'right'\|'top'\|'bottom'` | `right` |

Also, consider adding a usage example section before the API documentation:

## 自定义弹出方向

通过 `placement` 属性可以控制抽屉的弹出方向,支持 `left``right``top``bottom` 四个方向。

<DemoPreview dir="demos/vben-drawer/placement" />

Line range hint 1-24: Consider adding important sections to the documentation.

To ensure comprehensive documentation, consider adding the following sections:

  1. Testing considerations for different placement values
  2. Browser compatibility notes
  3. Examples of common use cases for each placement direction

Add these sections before the API documentation:

## 浏览器兼容性

该组件的 `placement` 属性在所有现代浏览器中都能正常工作。

## 测试建议

在使用不同的 `placement` 值时,请确保:
- 检查抽屉内容在不同方向上的正确渲染
- 验证动画效果的正确性
- 测试响应式布局下的表现

## 常见用例

- `left`: 适用于导航菜单
- `right`: 适用于详情面板
- `top`: 适用于通知或预览
- `bottom`: 适用于移动端的操作面板

Line range hint 3-3: Add version and feature information.

Consider adding version information and feature history to help users understand when this capability was introduced.

Add after the title:

> 新功能: `placement` 属性从 v2.x.x 版本开始支持,允许自定义抽屉的弹出方向。该功能基于 issue #4952 的需求开发。
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (1)

123-124: Consider adding placement-specific transitions

The width and height handling for different placements is well implemented. However, consider adding specific transitions for each placement to enhance the user experience.

 :class="
   cn('flex w-[520px] flex-col', drawerClass, {
     '!w-full': isMobile || placement === 'bottom' || placement === 'top',
-    'max-h-[100vh]': placement === 'bottom' || placement === 'top',
+    'max-h-[100vh] transition-[max-height]': placement === 'bottom' || placement === 'top',
+    'transition-[width]': placement === 'left' || placement === 'right',
   })
 "
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f85badf and 63e6176.

📒 Files selected for processing (5)
  • docs/src/components/common-ui/vben-drawer.md (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (2 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (2 hunks)
  • playground/src/views/examples/drawer/index.vue (4 hunks)
🔇 Additional comments (6)
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (1)

7-7: LGTM! Well-defined type for drawer placement.

The DrawerPlacement type is well-defined with comprehensive values covering all possible directions.

packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (1)

44-44: LGTM! Verify type definition for placement.

The addition of the placement property with default value 'right' looks good and aligns with the PR objectives.

Let's verify the type definition exists:

✅ Verification successful

Type definition for placement is correctly defined

The DrawerPlacement type is properly defined in drawer.ts with all expected values ('bottom', 'left', 'right', 'top'), which aligns perfectly with the default value 'right' used in drawer-api.ts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the DrawerPlacement type definition
# Expected: Find the type definition that should include 'left', 'right', 'top', 'bottom'

ast-grep --pattern 'type DrawerPlacement = $_'

Length of output: 169

playground/src/views/examples/drawer/index.vue (2)

2-2: LGTM: Type import is correctly added

The DrawerPlacement type import is properly added and used consistently throughout the code.


35-37: LGTM: Function implementation is correct

The openBaseDrawer function is well-implemented with:

  • Proper type safety using DrawerPlacement
  • Sensible default value
  • Correct state management sequence
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (2)

65-65: LGTM: Placement property correctly integrated

The placement property is properly added to the destructured values from usePriorityValues, aligning with the PR objectives.


129-129: Validate placement values

Add runtime validation for the placement prop to ensure only valid values are used.

@vince292007 vince292007 merged commit 7350267 into vbenjs:main Nov 27, 2024
14 checks passed
@mynetfan mynetfan deleted the feat/drawer-placement branch November 27, 2024 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: Drawer抽屉组件是否能增加placement字段,方便自定义抽屉的方向
2 participants