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: modal&drawer support appendToMain and zIndex #5092

Merged
merged 8 commits into from
Dec 10, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 10, 2024

Description

ModalDrawer新增appendToMain属性,可以配置将弹窗挂载到body还是layout的内容区域。

Modal:
image

Drawer:
image

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

  • New Features

    • Updated documentation for Vben Drawer and Vben Modal components with new properties: appendToMain and zIndex.
    • Introduced new InContentDrawer and InContentModal components, enhancing modal and drawer functionalities.
    • Added functionality to dynamically control drawer and modal rendering locations and stacking order.
    • Enhanced DialogContent, SheetContent, and DialogScrollContent components with new properties for improved positioning and z-index control.
    • Added new Modal and Drawer elements to the basic.vue component for user engagement.
  • Bug Fixes

    • Corrected style application for overflowY in the page.vue component.
  • Documentation

    • Enhanced clarity and detail in documentation for various components, including usage notes for new properties.
  • Chores

    • Updated package dependencies to include @vben-core/shared.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners December 10, 2024 04:35
Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: ea33b41

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 Dec 10, 2024

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/shadcn-ui/src/ui/dialog/DialogOverlay.vue

Oops! Something went wrong! :(

ESLint: 9.16.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)

Walkthrough

The pull request introduces updates to the documentation and properties of several UI components, including the Vben Drawer, Vben Modal, and dialog components in the shadcn-ui library. Key additions include the appendToMain and zIndex properties, enhancing the configurability and behavior of these components. The documentation clarifies usage and requirements for these properties, while new components are introduced in the playground examples to demonstrate the updated functionality. Overall, these changes aim to improve the clarity and usability of the components.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-drawer.md Updated documentation to include appendToMain and zIndex properties, clarifying their usage and behavior.
docs/src/components/common-ui/vben-modal.md Updated documentation to include appendToMain and zIndex properties, with explanations about their functionality.
packages/@core/base/shared/src/constants/globals.ts Added new constant ELEMENT_ID_MAIN_CONTENT with value __vben_main_content.
packages/@core/ui-kit/layout-ui/package.json Added dependency "@vben-core/shared": "workspace:*" to the package.
packages/@core/ui-kit/layout-ui/src/vben-layout.vue Imported idMainContent constant and updated LayoutContent component's id attribute.
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts Added properties appendToMain, modal, showCancelButton, showConfirmButton, and zIndex to DrawerProps.
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue Introduced prop appendToMain and updated default value for zIndex.
packages/@core/ui-kit/popup-ui/src/modal/modal.ts Added properties appendToMain and zIndex to ModalProps.
packages/@core/ui-kit/popup-ui/src/modal/modal.vue Added prop appendToMain and updated computed property for dynamic appending behavior.
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue Added properties appendTo and zIndex to DialogContentProps, enhancing dialog positioning.
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogOverlay.vue Removed z-[1000] class from overlay template.
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogScrollContent.vue Added zIndex property and updated positioning styles for dialog components.
packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetContent.vue Added properties appendTo and zIndex to SheetContentProps, enhancing component flexibility.
packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetOverlay.vue Changed positioning from fixed to absolute.
packages/effects/common-ui/src/components/page/page.vue Updated contentStyle computed property for type safety and style application.
playground/src/views/examples/drawer/in-content-demo.vue Introduced new component demonstrating drawer functionality.
playground/src/views/examples/drawer/index.vue Added InContentDrawer component and related functionality for opening the drawer.
playground/src/views/examples/modal/in-content-demo.vue Introduced new component demonstrating modal functionality.
playground/src/views/examples/modal/index.vue Added InContentModal component and functionality for opening the modal.
playground/src/views/examples/vxe-table/basic.vue Integrated modal and drawer capabilities into the basic example component.

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • vince292007
  • anncwb

🐰 In the meadow where the drawers play,
New properties hop in, brightening the day.
With appendToMain, they dance and they sway,
Z-index rising, in a colorful display!
Documentation clearer, for all to see,
Hooray for the changes, let’s celebrate with glee! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9380289 and ea33b41.

📒 Files selected for processing (3)
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogOverlay.vue (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetOverlay.vue (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/sheet.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetOverlay.vue
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/sheet.ts
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogOverlay.vue

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.

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

🧹 Outside diff range and nitpick comments (22)
packages/effects/common-ui/src/components/page/page.vue (1)

Line range hint 15-23: Document auto-content-height requirement for modal/drawer integration

Since this component's autoContentHeight property is crucial for proper modal/drawer functionality when using appendToMain, consider adding this requirement to the property's documentation.

  /**
   * 根据content可见高度自适应
+   * @remarks Required when using Modal or Drawer components with appendToMain property
   */
  autoContentHeight?: boolean;
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (2)

50-60: Consider simplifying and renaming the helper function

The isAppendToBody function could be improved for clarity and maintainability:

-function isAppendToBody() {
-  return (
-    props.appendTo === 'body' ||
-    props.appendTo === document.body ||
-    !props.appendTo
-  );
+function shouldUseFixedPosition() {
+  return !props.appendTo || ['body', document.body].includes(props.appendTo);
}

const position = computed(() => 
-  isAppendToBody() ? 'fixed' : 'absolute'
+  shouldUseFixedPosition() ? 'fixed' : 'absolute'
);

The suggested changes:

  1. Rename the function to better reflect its purpose
  2. Simplify the conditions using array inclusion
  3. Make the code more maintainable

Line range hint 1-117: Consider documenting mounting behavior and testing scenarios

Since this component now supports flexible mounting locations, consider:

  1. Documenting the implications of different mounting strategies (body vs. main content)
  2. Adding examples in the component's documentation
  3. Creating test cases for different mounting scenarios
  4. Ensuring proper cleanup of mounted elements

This flexibility in mounting locations could affect:

  • Event bubbling behavior
  • Style inheritance
  • Screen reader accessibility
  • Portal cleanup on component destruction

Would you like help creating documentation templates or test scenarios for these cases?

playground/src/views/examples/drawer/in-content-demo.vue (3)

10-13: Clean up commented code in onConfirm handler

The commented drawerApi.close() line should either be removed or implemented based on the intended behavior.

  onConfirm() {
    message.info('onConfirm');
-   // drawerApi.close();
  },

17-20: Consider internationalizing the text content

The component contains hardcoded Chinese text. Consider using i18n translations for better maintainability and internationalization support.

- <Drawer append-to-main title="基础抽屉示例" title-tooltip="标题提示内容">
+ <Drawer append-to-main :title="t('drawer.basicExample')" :title-tooltip="t('drawer.titleTooltip')">
    <template #extra> extra </template>
-   本抽屉指定在内容区域打开
+   {{ t('drawer.contentAreaNote') }}

17-17: Document append-to-main requirement

Consider adding a comment explaining that append-to-main requires the parent Page component to have auto-content-height set.

playground/src/views/examples/modal/in-content-demo.vue (3)

18-20: Consider using width prop instead of class

Using a class for width specification might override component's internal styling. Consider using the Modal's built-in width prop instead.

  <Modal
    append-to-main
-   class="w-[600px]"
+   :width="600"
    title="基础弹窗示例"

10-13: Clean up commented code in onConfirm handler

The commented modalApi.close() line should either be removed or implemented based on the intended behavior.

  onConfirm() {
    message.info('onConfirm');
-   // modalApi.close();
  },

20-24: Consider internationalizing the text content

The component contains hardcoded Chinese text. Consider using i18n translations for better maintainability and internationalization support.

-   title="基础弹窗示例"
-   title-tooltip="标题提示内容"
+   :title="t('modal.basicExample')"
+   :title-tooltip="t('modal.titleTooltip')"
  >
-   此弹窗指定在内容区域打开
+   {{ t('modal.contentAreaNote') }}
packages/@core/base/shared/src/constants/globals.ts (1)

10-12: LGTM! Consider enhancing the documentation

The constant follows the established patterns and naming conventions. Consider adding a more detailed JSDoc comment explaining its relationship with the appendToMain feature.

-/** 内容区域的组件ID */
+/**
+ * ID for the main content area component.
+ * Used by Modal and Drawer components when appendToMain is enabled.
+ * @zh_CN 内容区域的组件ID
+ */
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogScrollContent.vue (1)

35-36: Consider extracting overlay styles to a shared class

The overlay has complex styling that could benefit from being extracted to a shared utility class, especially since similar styling might be needed for other dialog variants.

Consider creating a shared class in your CSS utilities:

-class="data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 border-border absolute inset-0 grid place-items-center overflow-y-auto border bg-black/80"
+class="dialog-overlay"
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (1)

106-109: Consider enhancing zIndex documentation

The documentation for the zIndex property could be improved by including the default value in the JSDoc comment, similar to other properties.

  /**
   * 抽屉层级
+  * @default 1000
   */
  zIndex?: number;
packages/@core/ui-kit/popup-ui/src/modal/modal.ts (1)

120-123: Consider enhancing zIndex documentation

For consistency with other properties and the Drawer component, consider adding the default value to the JSDoc comment.

  /**
   * 弹窗层级
+  * @default 1000
   */
  zIndex?: number;
playground/src/views/examples/vxe-table/basic.vue (2)

70-78: Consider adding error handling to open functions

The open functions could benefit from try-catch blocks to handle potential errors gracefully.

 function openModal() {
+  try {
     modalApi.open();
+  } catch (error) {
+    console.error('Failed to open modal:', error);
+  }
 }

 function openDrawer() {
+  try {
     drawerApi.open();
+  } catch (error) {
+    console.error('Failed to open drawer:', error);
+  }
 }

93-98: Consider demonstrating new properties

The example could showcase the new appendToMain and zIndex properties to better demonstrate their usage.

-    <Modal title="弹窗测试">
+    <Modal
+      title="弹窗测试"
+      :append-to-main="true"
+      :z-index="2000"
+    >
       <p>这是一个弹窗</p>
     </Modal>
-    <Drawer title="抽屉测试">
+    <Drawer
+      title="抽屉测试"
+      :append-to-main="true"
+      :z-index="1900"
+    >
       <p>这是一个抽屉</p>
     </Drawer>
docs/src/components/common-ui/vben-drawer.md (1)

77-77: Consider enhancing the zIndex property description

While the property definitions are accurate, the zIndex description could be more detailed to explain:

  • Its relationship with other UI elements
  • Common scenarios for customization

Also applies to: 99-99

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

47-56: Consider extracting z-index magic number into a constant

The z-index value of 199 is hardcoded. Consider extracting this into a named constant to improve maintainability and document the relationship with the layout's z-index of 200.

+const CONTENT_DRAWER_Z_INDEX = 199; // Below layout's z-index (200)
+
 function openInContentDrawer(placement: DrawerPlacement = 'right') {
   inContentDrawerApi.setState({ placement });
   if (placement === 'top') {
-    // 页面顶部区域的层级只有200,所以设置一个低于200的值,抽屉从顶部滑出来的时候才比较合适
-    inContentDrawerApi.setState({ zIndex: 199 });
+    inContentDrawerApi.setState({ zIndex: CONTENT_DRAWER_Z_INDEX });
   } else {
     inContentDrawerApi.setState({ zIndex: undefined });
   }
   inContentDrawerApi.open();
 }
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (1)

35-37: Consider moving z-index default to shared constants

The default z-index value could be moved to a shared constants file to maintain consistency across components.

+// In @vben-core/shared/constants
+export const DEFAULT_DRAWER_Z_INDEX = 1000;
+
+// In current file
 const props = withDefaults(defineProps<Props>(), {
   appendToMain: false,
   drawerApi: undefined,
-  zIndex: 1000,
+  zIndex: DEFAULT_DRAWER_Z_INDEX,
 });
packages/@core/ui-kit/popup-ui/src/modal/modal.vue (2)

168-170: Consider extracting common functionality to a shared composable

The appendToMain and zIndex functionality is duplicated between modal and drawer components. Consider extracting this into a shared composable for better maintainability.

+// New file: @vben-core/composables/use-append-to-main.ts
+import { computed, type ComputedRef } from 'vue';
+import { ELEMENT_ID_MAIN_CONTENT } from '@vben-core/shared/constants';
+
+export function useAppendToMain(appendToMain: ComputedRef<boolean>) {
+  return computed(() => appendToMain.value ? `#${ELEMENT_ID_MAIN_CONTENT}` : undefined);
+}

+// In modal.vue and drawer.vue
-const getAppendTo = computed(() => {
-  return appendToMain.value ? `#${ELEMENT_ID_MAIN_CONTENT}` : undefined;
-});
+const getAppendTo = useAppendToMain(appendToMain);

Also applies to: 180-180, 198-198


36-37: Maintain consistency with drawer z-index defaults

Ensure the default z-index value is consistent with the drawer component by using the same shared constant.

+import { DEFAULT_DRAWER_Z_INDEX } from '@vben-core/shared/constants';
+
 const props = withDefaults(defineProps<Props>(), {
   appendToMain: false,
   modalApi: undefined,
+  zIndex: DEFAULT_DRAWER_Z_INDEX,
 });
packages/@core/ui-kit/layout-ui/src/vben-layout.vue (2)

461-462: Consider moving the ID constant declaration closer to related layout variables.

The idMainContent constant would be better placed with other layout-related variables near the start of the script, improving code organization and maintainability.

 const contentRef = ref();
+const idMainContent = ELEMENT_ID_MAIN_CONTENT;
 
 const {
   arrivedState,

559-559: Consider documenting the modal/drawer mounting behavior.

Since this change enables a new mounting point for modals and drawers, consider:

  1. Adding comments explaining the mounting behavior
  2. Updating component documentation to describe when to use appendToMain
  3. Adding examples demonstrating different mounting scenarios

This will help other developers understand and correctly use this feature.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 018ddc7 and 8b44f69.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (21)
  • docs/src/components/common-ui/vben-drawer.md (2 hunks)
  • docs/src/components/common-ui/vben-modal.md (2 hunks)
  • packages/@core/base/shared/src/constants/globals.ts (1 hunks)
  • packages/@core/ui-kit/layout-ui/package.json (1 hunks)
  • packages/@core/ui-kit/layout-ui/src/vben-layout.vue (3 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (4 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (8 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.ts (3 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue (7 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (3 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogOverlay.vue (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogScrollContent.vue (3 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetContent.vue (2 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetOverlay.vue (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/sheet.ts (2 hunks)
  • packages/effects/common-ui/src/components/page/page.vue (2 hunks)
  • playground/src/views/examples/drawer/in-content-demo.vue (1 hunks)
  • playground/src/views/examples/drawer/index.vue (4 hunks)
  • playground/src/views/examples/modal/in-content-demo.vue (1 hunks)
  • playground/src/views/examples/modal/index.vue (4 hunks)
  • playground/src/views/examples/vxe-table/basic.vue (3 hunks)
🔇 Additional comments (24)
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogOverlay.vue (1)

10-10: Verify the impact of z-index removal on existing implementations.

The removal of the hardcoded z-index might affect existing modal implementations that rely on the default stacking behavior.

Let's check for any existing usages that might be affected:

packages/effects/common-ui/src/components/page/page.vue (2)

2-9: LGTM! Enhanced type safety with StyleValue import

The addition of the StyleValue type import from Vue improves type safety for style-related computations.


39-48: Verify scroll behavior with modal/drawer integration

The changes improve type safety with StyleValue annotation and enable proper overflow behavior. However, since this component interacts with modal/drawer components through the appendToMain feature, we should verify the scroll behavior in different scenarios.

packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (2)

81-91: Template changes look good, verify z-index value

The implementation correctly applies the positioning and z-index to both overlay and content components, maintaining proper stacking context. The animations provide smooth transitions.

Consider verifying if the default z-index of 1000 is appropriate for your application's stacking context:

Also applies to: 96-96

✅ Verification successful

Default z-index value of 1000 is appropriate

The z-index value of 1000 for the Dialog component is consistent with other overlay components in the codebase:

  • DialogScrollContent uses z-index: 1000
  • SheetContent uses z-index: 1000
  • Drawer component uses z-index: 1000

While the layout components use lower z-index values (200 and below) which is correct as dialogs should appear above layout elements:

  • Layout header: ~200
  • Layout sidebar: 0-1
  • Layout footer: varies based on props
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other z-index values in the codebase for comparison
rg "z-index|zIndex" --type vue --type css --type scss -A 2

Length of output: 88


Script:

#!/bin/bash
# Search for z-index values using ripgrep with just file extensions
rg "z-index|zIndex" -g "*.vue" -g "*.css" -g "*.scss" -A 2

Length of output: 10773


23-32: Verify prop naming consistency with PR objectives

The PR objectives mention appendToMain but the implemented prop is named appendTo. This might cause confusion for other developers. Consider either:

  1. Updating the PR description to match the implementation, or
  2. Renaming the prop to match the intended feature name.
✅ Verification successful

Prop naming is correct, no changes needed

The implementation using appendTo is correct and consistent with the component architecture. The search results show that:

  1. appendTo is used consistently in shadcn-ui components (DialogContent.vue and SheetContent.vue) as a flexible prop accepting HTMLElement or string
  2. appendToMain is a different, boolean-type prop used in popup-ui components (modal.ts, drawer.ts) specifically for main content area mounting
  3. The documentation confirms these are two distinct features with different purposes

The PR objectives likely referred to supporting both features, and the implementation correctly uses appendTo for this general-purpose dialog component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any usage of appendToMain in the codebase
rg "appendToMain" --type vue --type ts

Length of output: 66


Script:

#!/bin/bash
# Search for any usage of appendToMain or appendTo in the codebase
rg -t typescript -t javascript -t vue "appendToMain|appendTo"

Length of output: 98


Script:

#!/bin/bash
# Search for any usage of appendToMain or appendTo using ripgrep without file type filters
rg "appendToMain|appendTo"

Length of output: 2610

packages/@core/ui-kit/layout-ui/package.json (1)

43-43: LGTM: Dependency addition aligns with feature requirements

The addition of @vben-core/shared as a workspace dependency is appropriate for accessing shared constants needed for the new mounting features.

packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetContent.vue (4)

18-23: LGTM: Well-structured prop interface extensions

The new props appendTo and zIndex are properly typed and align with the PR objectives for flexible mounting and z-index control.


30-33: LGTM: Sensible default values

Default values are appropriate:

  • appendTo: 'body' maintains backward compatibility
  • zIndex: 1000 follows common UI library conventions

49-59: LGTM: Robust mounting logic implementation

The isAppendToBody function and position computed property effectively handle the mounting behavior:

  • Comprehensive checks for body mounting scenarios
  • Correct position switching between 'fixed' and 'absolute'

65-71: Verify z-index propagation to nested components

The z-index and position styles are correctly applied to both overlay and content. However, we should verify that z-index values properly cascade to nested dialogs if they exist.

✅ Verification successful

Z-index propagation is properly handled - no nested dialogs found

Based on the codebase analysis, there are no instances of nested DialogContent or SheetContent components. The z-index and position styles are correctly applied at the root level of each dialog/sheet component, and there's no risk of z-index stacking context issues from nesting. The current implementation in SheetContent.vue is safe and follows best practices.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for nested dialog usage patterns
ast-grep --pattern 'DialogContent {
  $$$
  DialogContent {
    $$$
  }
  $$$
}'

Length of output: 82


Script:

#!/bin/bash
# Search for nested dialog usage in template files
rg -U "(?s)<DialogContent.*?<DialogContent.*?</DialogContent>.*?</DialogContent>" --type vue

# Search for any nested sheet/dialog components
rg -U "(?s)<(Sheet|Dialog)(Content|Root).*?<(Sheet|Dialog)(Content|Root).*?</(Sheet|Dialog)(Content|Root).*?</(Sheet|Dialog)(Content|Root)" --type vue

# Check if there are any components that might use multiple dialogs
rg "<(Sheet|Dialog)(Content|Root)" --type vue -l | xargs -I {} rg -U "(?s)<(Sheet|Dialog)(Content|Root).*<(Sheet|Dialog)(Content|Root)" {} || true

Length of output: 476


Script:

#!/bin/bash
# Search for nested dialog usage in template files without file type restriction
rg -U "(?s)<DialogContent.*?<DialogContent.*?</DialogContent>.*?</DialogContent>"

# Search for any nested sheet/dialog components
rg -U "(?s)<(Sheet|Dialog)(Content|Root).*?<(Sheet|Dialog)(Content|Root).*?</(Sheet|Dialog)(Content|Root).*?</(Sheet|Dialog)(Content|Root)"

# List files with multiple dialog/sheet components
fd -e vue -e js -e jsx -e tsx | xargs rg "<(Sheet|Dialog)(Content|Root)" -l | while read -r file; do
  echo "=== $file ==="
  rg -U "(?s)<(Sheet|Dialog)(Content|Root).*<(Sheet|Dialog)(Content|Root)" "$file" || true
done

Length of output: 4157

packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogScrollContent.vue (2)

17-20: LGTM: Consistent z-index implementation

The zIndex prop implementation matches SheetContent.vue, maintaining consistency across components.


45-45: LGTM: Proper z-index binding

The z-index style binding is correctly implemented on the DialogContent component.

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

10-14: LGTM! Well-structured interface additions

The new properties are well-documented and properly typed. The additions of appendToMain, modal, and button visibility controls enhance the component's flexibility.

Also applies to: 72-72, 87-95

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

6-10: LGTM! Consistent implementation with Drawer component

The appendToMain property is well-documented and maintains consistency with the Drawer component implementation.

playground/src/views/examples/modal/index.vue (3)

12-12: LGTM: Modal setup looks good!

The implementation correctly sets up the InContentModal using useVbenModal with proper component connection.

Also applies to: 20-23


49-51: LGTM: Modal handler implementation is correct!

The openInContentModal function properly uses the modal API to trigger the modal.


89-89: LGTM: Template implementation is well structured!

The changes correctly:

  • Add auto-content-height to Page component (required for appendToMain)
  • Include the modal component
  • Add a clear demo section with proper description

Also applies to: 108-111

docs/src/components/common-ui/vben-drawer.md (1)

101-105: LGTM: Clear and comprehensive appendToMain documentation!

The documentation effectively explains:

  • The purpose and behavior of appendToMain
  • Requirements for proper implementation
  • Impact on layout and content
docs/src/components/common-ui/vben-modal.md (1)

112-116: LGTM: Clear and comprehensive appendToMain documentation!

The documentation effectively explains:

  • The purpose and behavior of appendToMain
  • Requirements for proper implementation
  • Impact on layout and content
playground/src/views/examples/drawer/index.vue (1)

20-24: LGTM: Drawer initialization follows existing patterns

The initialization of InContentDrawer follows the same pattern as other drawer instances, maintaining consistency in the codebase.

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

119-121: LGTM: Clean implementation of appendToMain functionality

The computed property and its usage in the template are well-implemented. The code is clean and follows Vue best practices.

Also applies to: 130-140

packages/@core/ui-kit/layout-ui/src/vben-layout.vue (2)

14-14: LGTM! Good practice using a shared constant for the content area ID.

Using a shared constant for DOM element IDs ensures consistency across the application and reduces the risk of ID conflicts.


559-559: LGTM! Verify modal/drawer mounting behavior.

The ID binding enables the new appendToMain feature for modals and drawers. This implementation looks correct.

✅ Verification successful

Implementation verified - ID binding works correctly with modal/drawer components

The ID binding is properly implemented and integrated with the modal/drawer mounting system:

  • The ELEMENT_ID_MAIN_CONTENT constant is defined in shared constants
  • Both modal and drawer components correctly import and use this ID for the appendToMain feature
  • The components compute the mount target using getAppendTo which returns #${ELEMENT_ID_MAIN_CONTENT} when appendToMain is true
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that modal/drawer components reference this ID for mounting

# Search for references to the main content ID in modal/drawer components
rg -l "ELEMENT_ID_MAIN_CONTENT" --type vue --type typescript

# Search for appendToMain prop usage
ast-grep --pattern 'prop: "appendToMain"'

Length of output: 132


Script:

#!/bin/bash
# Let's try different approaches to find the relevant code

# Search for any mentions of appendToMain in the codebase
rg "appendToMain"

# Search for modal or drawer related files
fd -e ts -e vue "(modal|drawer)" 

# Search for any ID references that might be related to main content mounting
rg -i "main.*content.*id|content.*main.*id"

Length of output: 3002


Script:

#!/bin/bash
# Let's find the ELEMENT_ID_MAIN_CONTENT constant definition and verify its usage

# Search for the constant definition
rg "ELEMENT_ID_MAIN_CONTENT.*=" -A 1

# Check how it's imported and used in modal/drawer components
rg "ELEMENT_ID_MAIN_CONTENT" -B 2 -A 2

Length of output: 3180

packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetOverlay.vue (1)

10-10: ⚠️ Potential issue

Ensure proper positioning context for absolute positioning

The change from fixed to absolute positioning requires proper positioning context from parent elements. This could lead to positioning issues if parent containers don't establish the correct positioning context.

Consider one of these solutions:

  1. Add positioning context documentation:
<script setup lang="ts">
import { inject } from 'vue';
import { useScrollLock } from '@vben-core/composables';

+/**
+ * @requires Parent element must establish a positioning context (position: relative|absolute|fixed)
+ */
useScrollLock();
  1. Or revert to fixed positioning and handle appendToMain differently:
-  <div :data-dismissable-drawer="id" class="bg-overlay absolute inset-0"></div>
+  <div :data-dismissable-drawer="id" class="bg-overlay fixed inset-0"></div>

packages/@core/ui-kit/shadcn-ui/src/ui/sheet/sheet.ts Outdated Show resolved Hide resolved
docs/src/components/common-ui/vben-modal.md Outdated Show resolved Hide resolved
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: 0

🧹 Outside diff range and nitpick comments (1)
docs/src/components/common-ui/vben-modal.md (1)

112-116: Fix typo and consider adding a code example.

  1. There's a typo in the Chinese text: "这招" should be "这种"
  2. Consider adding a code example to demonstrate the usage of auto-content-height with the Page component.

Apply this change:

-打开带这招的弹窗时
+打开带这种的弹窗时

Consider adding a code example like:

<Page auto-content-height>
  <VbenModal appendToMain />
</Page>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8b44f69 and e411024.

📒 Files selected for processing (1)
  • docs/src/components/common-ui/vben-modal.md (2 hunks)
🔇 Additional comments (1)
docs/src/components/common-ui/vben-modal.md (1)

83-83: LGTM! Property additions are well-documented.

The new properties appendToMain and zIndex are clearly documented with appropriate types and default values.

Also applies to: 110-111

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

🧹 Outside diff range and nitpick comments (3)
playground/src/views/examples/drawer/index.vue (3)

20-24: Consider adding English comments for better international collaboration.

The component initialization follows good practices, but the comments are in Chinese. Consider translating them to English for better international collaboration.

-  // 连接抽离的组件
+  // Connect the separated component

47-56: Consider improvements to zIndex handling.

The implementation is good, but could be enhanced:

  1. Extract the magic number 199 as a named constant for better maintainability
  2. Translate the Chinese comment to English
+const TOP_DRAWER_Z_INDEX = 199; // Z-index for top placement drawer (must be below page header z-index of 200)

 function openInContentDrawer(placement: DrawerPlacement = 'right') {
   inContentDrawerApi.setState({ class: '', placement });
   if (placement === 'top') {
-    // 页面顶部区域的层级只有200,所以设置一个低于200的值,抽屉从顶部滑出来的时候才比较合适
-    inContentDrawerApi.setState({ zIndex: 199 });
+    // Set z-index below 200 for proper animation when drawer slides from top
+    inContentDrawerApi.setState({ zIndex: TOP_DRAWER_Z_INDEX });
   } else {
     inContentDrawerApi.setState({ zIndex: undefined });
   }
   inContentDrawerApi.open();
 }

58-62: Fix typo in comment and translate to English.

The implementation is correct, but the comment needs improvement:

-  // 这里只是用来演示方便。实际上自己使用的时候可以直接将这些配置卸载Drawer的属性里
+  // This is for demonstration purposes only. In practice, these configurations can be directly set as Drawer properties
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e411024 and 9380289.

📒 Files selected for processing (2)
  • playground/src/views/examples/drawer/index.vue (4 hunks)
  • playground/src/views/examples/vxe-table/basic.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • playground/src/views/examples/vxe-table/basic.vue
🔇 Additional comments (2)
playground/src/views/examples/drawer/index.vue (2)

112-127: LGTM! Well-structured button layout.

The button layout is well-organized with consistent spacing and clear action labels.


130-159: LGTM! Well-implemented in-content drawer demo section.

The implementation follows the established pattern and provides clear user interaction options. The description effectively communicates the purpose of this feature.

@mynetfan mynetfan merged commit e419b03 into vbenjs:main Dec 10, 2024
13 checks passed
@mynetfan mynetfan deleted the feat/moda&drawer_append_to_main branch December 10, 2024 09:37
@anncwb anncwb added the feature label Dec 11, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 11, 2024
16 tasks
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.

2 participants