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: improve page component #5013

Merged
merged 6 commits into from
Dec 4, 2024
Merged

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 4, 2024

Description

此PR主要修改了Page 组件

  1. 添加fixed-header属性用于配置头部区域是否固定。close FEATURE: 建议Page组件header部分支持固定到顶部 #4984
  2. 新增 headerClass、footerClass属性,修改2个测试页面以演示Page的用法。
  3. 补全Page组件的文档

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 "布局组件" (Layout Components) section in the sidebar for easier navigation.
    • Added documentation for the new Page component, detailing its structure and usage.
    • Included an optional fixedHeader property in the Page component for a sticky header feature.
    • Enhanced form component functionality by adding tabbed navigation for different examples.
  • Bug Fixes

    • Adjusted layout logic to improve visual handling of overflow content.
  • Documentation

    • Updated introduction.md to include information about layout components.
    • Added new documentation for the Page component, outlining its usage and properties.

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

changeset-bot bot commented Dec 4, 2024

⚠️ No Changeset found

Latest commit: d287feb

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 4, 2024

Walkthrough

The changes include the addition of a new sidebar section for layout components in the documentation, specifically introducing "布局组件" (Layout Components) and a nested item for "Page 页面". A new documentation file for the Page component has been created, detailing its structure and properties. Additionally, the vben-layout.vue component has undergone styling modifications, including the removal of a class affecting overflow handling. The page.vue component now supports a new optional property for a fixed header, enhancing its functionality.

Changes

File Path Change Summary
docs/.vitepress/config/zh.mts Added new sidebar section "布局组件" with nested item "Page 页面".
docs/src/components/introduction.md Inserted new section "布局组件" describing its purpose before "通用组件".
docs/src/components/layout-ui/page.md New documentation for Page component, detailing structure and properties.
packages/@core/ui-kit/layout-ui/src/vben-layout.vue Removed overflow-hidden class; retained existing layout logic and event handling.
packages/effects/common-ui/package.json Added dependency "@vben-core/preferences": "workspace:*".
packages/effects/common-ui/src/components/page/page.vue Introduced optional fixedHeader property and computed headerStyle for dynamic styling.
playground/src/views/examples/modal/index.vue Added fixed-header attribute to <Page> component in modal example.

Assessment against linked issues

Objective Addressed Explanation
Support fixed header in Page component (#4984)

Suggested labels

feature

Suggested reviewers

  • anncwb
  • vince292007

Poem

In the garden of code, we hop and play,
New layouts bloom, brightening the day.
With headers fixed and styles so neat,
Our components dance, a joyful feat!
So let’s celebrate this coding spree,
A rabbit's cheer for you and me! 🐇✨

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/effects/common-ui/src/components/page/page.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)


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

🧹 Outside diff range and nitpick comments (4)
docs/src/components/introduction.md (1)

9-11: Consider adding English translations for better accessibility

Since this is an open-source project, consider adding English translations alongside the Chinese text for better international accessibility.

 ## 布局组件
+## Layout Components
 
 布局组件一般在页面内容区域用作顶层容器组件,提供一些统一的布局样式和基本功能。
+Layout components are generally used as top-level container components in page content areas, providing unified layout styles and basic functionality.
packages/effects/common-ui/src/components/page/page.vue (3)

44-54: Consider adding type safety and transitions

The computed headerStyle implementation could be improved:

  1. Add type checking for preferences.header.mode
  2. Consider adding CSS transitions for smooth header positioning
  3. Document the z-index value in a constant for better maintainability
+const HEADER_Z_INDEX = 200;
+
+type HeaderMode = 'fixed' | 'static';  // Add other valid modes
+
 const headerStyle = computed<StyleValue>(() => {
   return fixedHeader
     ? {
         position: 'sticky',
-        zIndex: 200,
+        zIndex: HEADER_Z_INDEX,
+        transition: 'top 0.3s',
         top:
-          preferences.header.mode === 'fixed' ? 'var(--vben-header-height)' : 0,
+          (preferences.header.mode as HeaderMode) === 'fixed' 
+            ? 'var(--vben-header-height)' 
+            : 0,
         borderBottom: '1px solid hsl(240 5.9% 90%)',
       }
     : undefined;
 });

96-96: Consider adding aria attributes for accessibility

Since this is a fixed header that might affect keyboard navigation, consider adding appropriate ARIA attributes.

-      :style="headerStyle"
+      :style="headerStyle"
+      :aria-fixed="fixedHeader"
+      role="banner"

Line range hint 1-128: Consider adding tests for the fixed header functionality

While the implementation looks good, tests would help ensure the fixed header behavior works correctly across different scenarios:

  1. Test header positioning with different preference modes
  2. Test interaction with scrolling
  3. Test accessibility features

Would you like me to help create test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 24b9aa4 and 42b22bb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • docs/.vitepress/config/zh.mts (1 hunks)
  • docs/src/components/introduction.md (1 hunks)
  • docs/src/components/layout-ui/page.md (1 hunks)
  • packages/@core/ui-kit/layout-ui/src/vben-layout.vue (1 hunks)
  • packages/effects/common-ui/package.json (1 hunks)
  • packages/effects/common-ui/src/components/page/page.vue (5 hunks)
  • playground/src/views/examples/modal/index.vue (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • playground/src/views/examples/modal/index.vue
  • docs/src/components/layout-ui/page.md
🔇 Additional comments (5)
packages/effects/common-ui/package.json (1)

25-25: Verify the dependency usage scope

The new dependency @vben-core/preferences is correctly added with workspace scope. However, let's verify its usage across the codebase.

✅ Verification successful

Dependency is correctly used and imported

The @vben-core/preferences dependency is properly used in packages/effects/common-ui/src/components/page/page.vue for handling user preferences, which aligns with its intended purpose as documented in the effects README. The dependency is also correctly configured as a workspace package.

  • Used in: packages/effects/common-ui/src/components/page/page.vue
  • Package location: packages/@core/preferences
  • Documentation reference: Found in packages/effects/README.md confirming its use for user preferences
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for imports of @vben-core/preferences
rg "from '@vben-core/preferences'" --type ts --type vue

Length of output: 91


Script:

#!/bin/bash
# Search for any usage of @vben-core/preferences with broader pattern
rg "@vben-core/preferences"

# Also check for specific file extensions since the package might be used in different ways
fd -e ts -e vue -e js . -x rg -l "@vben-core/preferences" {}

Length of output: 1050

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

21-22: Documentation looks good

The prop documentation is clear and follows the existing pattern.


95-97: Verify z-index conflicts

The header's z-index of 200 might conflict with other fixed elements. Let's verify the z-index usage across the codebase.

✅ Verification successful

No z-index conflicts detected in the header component

Based on the codebase analysis, there are no z-index conflicts with the header component. The search reveals that most high z-index values are used in overlay components (z-1000+) like dialogs, tooltips, and dropdowns, which are designed to appear above regular content. The header's z-index of 200 sits in a safe range that won't interfere with these overlay components while still maintaining proper layering with regular page content.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for z-index declarations
rg "z-?index:?\s*\d+" --type css --type vue --type scss

Length of output: 85


Script:

#!/bin/bash
# Search for z-index declarations with ripgrep, including Vue files
rg "z-?index:?\s*\d+" --type-add 'vue:*.vue' --type vue --type css --type scss

Length of output: 109


Script:

#!/bin/bash
# Search for z-index declarations using simpler ripgrep command
rg "z-index" -g "*.{vue,css,scss}"

# Also search for Tailwind z-index classes
rg "z-\[?\d+\]?" -g "*.{vue,css,scss}"

Length of output: 11612

docs/.vitepress/config/zh.mts (1)

151-160: LGTM! Documentation structure is well-organized.

The new layout components section is appropriately placed before the common components section, which follows a logical hierarchy as layout components are typically top-level container components.

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

506-506: Verify scrolling behavior with fixed header.

The removal of overflow-hidden allows content to scroll naturally, which is necessary for the fixed header feature. However, please verify:

  1. No unintended horizontal scrollbars appear
  2. Content scrolls smoothly under the fixed header
  3. Layout remains stable during scrolling
✅ Verification successful

The removal of overflow-hidden is safe and appropriate for the fixed header layout.

Based on the codebase analysis:

  1. The header has its own overflow-hidden class in the wrapper div, which prevents any unwanted header content overflow
  2. The layout uses proper fixed positioning and z-indexing for the header component
  3. The sidebar has its own overflow-hidden management
  4. The content area's scrolling is properly managed through the layout structure and CSS transitions

The removal of overflow-hidden from the flex container is correct as it allows:

  • Natural content scrolling under the fixed header
  • Proper interaction between the content and fixed elements
  • Smooth transitions during layout changes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any overflow-related styles that might conflict with this change
rg -A 2 'overflow-[xy]|overflow:\s*hidden' --type css --type vue

Length of output: 94


Script:

#!/bin/bash
# Search for overflow-related styles in all files, including Vue files
rg -A 2 'overflow-[xy]|overflow:\s*hidden'

Length of output: 3628


Script:

#!/bin/bash
# Look for layout-related components and their style definitions
fd -e vue -e css layout

Length of output: 579


Script:

#!/bin/bash
# Check the parent layout components for any scroll-related styles
ast-grep --pattern 'class="$_"' packages/@core/ui-kit/layout-ui/src/vben-layout.vue

Length of output: 85


Script:

#!/bin/bash
# Let's check the content of the main layout components to understand the scroll behavior
cat packages/@core/ui-kit/layout-ui/src/vben-layout.vue packages/@core/ui-kit/layout-ui/src/components/layout-content.vue

Length of output: 15956


Script:

#!/bin/bash
# Check for any scroll-related styles in the layout components
rg -A 2 'scroll|overflow' packages/@core/ui-kit/layout-ui/

Length of output: 3288

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

🧹 Outside diff range and nitpick comments (2)
docs/src/components/layout-ui/page.md (2)

7-13: Consider adding example code to demonstrate the basic structure.

While the introduction clearly explains the component's purpose, adding a basic example code snippet would help users understand the component's structure more quickly.

Consider adding something like:

 本组件是一个基本布局组件。如果有更多的通用页面布局需求(比如双列布局等),可以根据实际需求自行封装。

+```vue
+<template>
+  <Page title="页面标题" :fixed-header="true">
+    <!-- 页面内容 -->
+    <div>页面内容</div>
+    
+    <!-- 使用插槽自定义底部 -->
+    <template #footer>
+      <div>页面底部</div>
+    </template>
+  </Page>
+</template>
+```

15-18: Enhance the basic usage section with more details.

The current usage section is quite brief. Consider adding:

  • Common use cases
  • Integration with layout systems
  • Best practices for component positioning
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 42b22bb and 28283dd.

📒 Files selected for processing (1)
  • docs/src/components/layout-ui/page.md (1 hunks)
🔇 Additional comments (1)
docs/src/components/layout-ui/page.md (1)

35-43: LGTM! Slots documentation is complete and clear.

The slots section effectively documents all available slots with clear descriptions.

docs/src/components/layout-ui/page.md Outdated Show resolved Hide resolved
docs/src/components/layout-ui/page.md Outdated Show resolved Hide resolved
docs/src/components/layout-ui/page.md 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 (2)
docs/src/components/layout-ui/page.md (1)

29-29: Enhance the fixedHeader prop description.

The description should clarify that this is specifically for the content area's header, not the app's main header, to avoid confusion.

-| fixedHeader | 固定头部在页面内容区域顶部,在滚动时保持可见 | `boolean` | `false` |
+| fixedHeader | 固定头部在页面内容区域顶部,在内容区域滚动时保持可见。注意:这是针对页面组件的头部,而不是应用的主要导航头部 | `boolean` | `false` |
playground/src/views/examples/form/basic.vue (1)

342-352: Consider extracting the description text to avoid duplication.

The description text is duplicated in both the description prop and the template content.

-    description="表单组件基础示例,请注意,该页面用到的参数代码会添加一些简单注释,方便理解,请仔细查看。"
     fixed-header
     header-class="pb-0"
     title="表单组件"
   >
     <template #description>
       <div class="text-muted-foreground">
-        <p>
-          表单组件基础示例,请注意,该页面用到的参数代码会添加一些简单注释,方便理解,请仔细查看。
-        </p>
+        <p>{{ description }}</p>
       </div>

Add this to the script section:

const description = '表单组件基础示例,请注意,该页面用到的参数代码会添加一些简单注释,方便理解,请仔细查看。';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 11cf5de and d287feb.

📒 Files selected for processing (3)
  • docs/src/components/layout-ui/page.md (1 hunks)
  • packages/effects/common-ui/src/components/page/page.vue (6 hunks)
  • playground/src/views/examples/form/basic.vue (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/effects/common-ui/src/components/page/page.vue
🧰 Additional context used
📓 Learnings (1)
docs/src/components/layout-ui/page.md (2)
Learnt from: mynetfan
PR: vbenjs/vue-vben-admin#5013
File: docs/src/components/layout-ui/page.md:23-24
Timestamp: 2024-12-04T04:43:22.179Z
Learning: 在 `docs/src/components/layout-ui/page.md` 的 `Page` 组件中,`title` 和 `description` 属性有意使用 `string|slot` 类型表示法,表示它们可以接受字符串或插槽。
Learnt from: mynetfan
PR: vbenjs/vue-vben-admin#5013
File: docs/src/components/layout-ui/page.md:31-31
Timestamp: 2024-12-04T04:41:30.161Z
Learning: 在 Vben Admin 项目的 `Page` 组件中,`extra` 内容仅通过 slots 提供,没有对应的 prop 属性。
🔇 Additional comments (4)
docs/src/components/layout-ui/page.md (2)

7-11: LGTM! Clear introduction and guidance.

The introduction effectively explains the component's purpose and provides good guidance about custom layouts.


33-33: LGTM! Important note about header rendering.

The note clearly explains when the header area will not be rendered, which is crucial for users to understand.

playground/src/views/examples/form/basic.vue (2)

338-341: LGTM! Proper usage of the new fixed-header prop.

The fixed-header prop is correctly implemented along with appropriate styling through header-class="pb-0" to adjust padding.


356-364: LGTM! Clean implementation of conditional card rendering.

The v-show directive is appropriately used for toggling between form examples based on the active tab.

@mynetfan mynetfan changed the title feat: page component support fixed header feat: improve page component Dec 4, 2024
@anncwb anncwb merged commit 17c7ce8 into vbenjs:main Dec 4, 2024
16 checks passed
@anncwb anncwb added the enhancement New feature or request label Dec 4, 2024
@mynetfan mynetfan deleted the feat/page-header-fixed branch December 5, 2024 04:32
@Coke-Code
Copy link

vben-layout取消overflow-hidden后,会导致内容区域的弹性盒子计算异常,弹性盒会异常触发Reflow,且渲染模式违背CSS规范。
使用空项目,或者Iframe视图,渲染均表现良好。
合并代码后:
image
合并代码前:
image
@mynetfan @anncwb @Rwing @dingdayu @DesignHhuang

@mynetfan
Copy link
Collaborator Author

mynetfan commented Dec 5, 2024

后续PR已经处理了这个问题,#5033

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.

FEATURE: 建议Page组件header部分支持固定到顶部
3 participants