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: popup component support overlay blur effect #5359

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Jan 11, 2025

Description

为Modal和Drawer组件添加overlayBlur属性,用于设置遮罩层的模糊效果

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

    • Added overlayBlur property to Drawer and Modal components, allowing users to specify blur intensity for overlay backgrounds
    • Introduced new visual customization option for popups with configurable blur effects
  • Documentation

    • Updated documentation for Vben Drawer and Modal components to include new overlayBlur property details
  • Playground

    • Added example views demonstrating blur effect implementation for Drawer and Modal components
    • Created interactive slider to adjust overlay blur intensity

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners January 11, 2025 15:28
Copy link

changeset-bot bot commented Jan 11, 2025

⚠️ No Changeset found

Latest commit: 182974b

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 Jan 11, 2025

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.ts

Oops! Something went wrong! :(

ESLint: 9.17.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

This pull request introduces an overlayBlur property across multiple UI components including drawers, modals, and their respective documentation. The new property allows developers to specify a blur intensity for overlay backgrounds in drawer and modal components. The changes span documentation updates, TypeScript interface modifications, and Vue component implementations, providing a consistent way to add visual blur effects to popup UI elements.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-drawer.md Added overlayBlur property documentation
docs/src/components/common-ui/vben-modal.md Added overlayBlur property documentation
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts Added overlayBlur?: number to DrawerProps interface
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue Integrated overlayBlur property in component props and template
packages/@core/ui-kit/popup-ui/src/modal/modal.ts Added overlayBlur?: number to ModalProps interface
packages/@core/ui-kit/popup-ui/src/modal/modal.vue Integrated overlayBlur property in component props and template
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue Added overlayBlur property with conditional backdrop filter
packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetContent.vue Added overlayBlur property with conditional backdrop filter
playground/src/views/examples/drawer/index.vue Added openBlurDrawer function to demonstrate blur effect
playground/src/views/examples/modal/blur-demo.vue Created new demo component showcasing modal blur functionality
playground/src/views/examples/modal/index.vue Added modal blur demo and related function

Sequence Diagram

sequenceDiagram
    participant User
    participant Component
    participant Overlay
    
    User->>Component: Set overlayBlur value
    Component->>Overlay: Apply backdrop filter
    Overlay-->>Component: Update visual effect
    Component-->>User: Render blurred overlay
Loading

Possibly related PRs

Suggested labels

feature, ui, enhancement

Suggested reviewers

  • anncwb
  • vince292007

Poem

🐰 A Rabbit's Blur-y Tale 🌫️

With overlays soft and light,
Our UI now blurs just right,
A pixel dance, a gentle haze,
Transforming interfaces in magical ways!
Blur on, dear components, blur on bright! 🎨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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

🧹 Nitpick comments (14)
playground/src/views/examples/modal/blur-demo.vue (3)

8-11: Consider adding validation for the blur value

While the initial value of 5 is reasonable, consider adding runtime validation to ensure the blur value stays within acceptable performance bounds.

 const blur = ref(5);
+const validateBlur = (value: number) => {
+  return Math.max(0, Math.min(value, 30));
+};
 const [Modal, modalApi] = useVbenModal({
-  overlayBlur: blur.value,
+  overlayBlur: validateBlur(blur.value),
 });

12-16: Consider debouncing the blur updates

Frequent updates to the blur value might impact performance. Consider debouncing the watch callback.

+import { useDebounceFn } from '@vueuse/core';
+
+const updateBlur = useDebounceFn((val: number) => {
+  modalApi.setState({
+    overlayBlur: validateBlur(val),
+  });
+}, 16);
+
-watch(blur, (val) => {
-  modalApi.setState({
-    overlayBlur: val,
-  });
-});
+watch(blur, updateBlur);

19-22: Add aria-label for better accessibility

The slider control should have an aria-label for screen readers.

 <Modal title="遮罩层模糊">
   <p>调整滑块来改变遮罩层模糊程度:{{ blur }}</p>
-  <Slider v-model:value="blur" :max="30" :min="0" />
+  <Slider 
+    v-model:value="blur" 
+    :max="30" 
+    :min="0" 
+    aria-label="调整遮罩层模糊程度"
+  />
 </Modal>
playground/src/views/examples/drawer/base-demo.vue (1)

10-12: Consider extracting default state to a constant

The default state values should be extracted to named constants for better maintainability.

+const DEFAULT_DRAWER_STATE = {
+  overlayBlur: 0,
+  placement: 'right' as const,
+} as const;
+
 onClosed() {
-  drawerApi.setState({ overlayBlur: 0, placement: 'right' });
+  drawerApi.setState(DEFAULT_DRAWER_STATE);
 }
packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetContent.vue (2)

20-20: Add JSDoc comment for the overlayBlur property

Document the property's purpose and constraints for better developer experience.

+ /**
+  * Applies a blur effect to the overlay background
+  * @default undefined
+  * @min 0
+  * @example
+  * overlayBlur={5} // Applies a 5px blur effect
+  */
  overlayBlur?: number;

79-87: Consider performance optimization for blur effect

The blur effect can be performance-intensive. Consider adding will-change and transform properties for better rendering performance.

 <SheetOverlay
   v-if="open && modal"
   :style="{
     zIndex,
     position,
+    willChange: overlayBlur && overlayBlur > 0 ? 'backdrop-filter' : 'auto',
+    transform: 'translateZ(0)',
     backdropFilter:
       overlayBlur && overlayBlur > 0 ? `blur(${overlayBlur}px)` : 'none',
   }"
 />
packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (1)

88-92: Enhance overlayBlur property documentation

Add more detailed JSDoc comments including performance implications and recommended value ranges.

 /**
  * 弹窗遮罩模糊效果
+ * @description Applies a gaussian blur effect to the drawer's overlay background
+ * @default undefined
+ * @min 0
+ * @max 30 - Higher values may impact performance
+ * @example
+ * overlayBlur={5} // Applies a 5px blur effect
  */
 overlayBlur?: number;
packages/@core/ui-kit/popup-ui/src/modal/modal.ts (1)

102-105: Enhance the JSDoc documentation for overlayBlur property.

The documentation could be more descriptive by including:

  • The expected range of values
  • The unit of measurement (pixels)
  • Default behavior when not specified
 /**
- * 弹窗遮罩模糊效果
+ * 弹窗遮罩模糊效果,单位为像素(px)
+ * @default undefined - 不应用模糊效果
+ * @example
+ * // 应用 5px 的模糊效果
+ * overlayBlur: 5
  */
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (1)

86-91: Consider performance implications of backdrop-filter.

The implementation is correct, but backdrop-filter can impact rendering performance, especially on lower-end devices. Consider:

  1. Adding a maximum blur value to prevent performance issues
  2. Using CSS containment to optimize rendering
 :style="{
   zIndex,
   position,
   backdropFilter:
     overlayBlur && overlayBlur > 0 ? `blur(${overlayBlur}px)` : 'none',
+  contain: 'paint',
 }"
playground/src/views/examples/drawer/index.vue (1)

48-50: Consider parameterizing the blur value.

The blur value is hardcoded to 5. Consider making it configurable for better reusability:

-function openBlurDrawer() {
+function openBlurDrawer(blurValue: number = 5) {
-  baseDrawerApi.setState({ overlayBlur: 5 }).open();
+  baseDrawerApi.setState({ overlayBlur: blurValue }).open();
 }
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (1)

71-71: Consider using a more specific type for overlayBlur.

The type for overlayBlur is implicitly any. Consider using number | undefined to match the documented type and improve type safety.

- overlayBlur,
+ overlayBlur: overlayBlur as number | undefined,
packages/@core/ui-kit/popup-ui/src/modal/modal.vue (1)

80-80: Consider using a more specific type for overlayBlur.

For consistency with the drawer component and improved type safety, consider using number | undefined instead of implicit any.

- overlayBlur,
+ overlayBlur: overlayBlur as number | undefined,
docs/src/components/common-ui/vben-drawer.md (1)

104-104: Consider enhancing the overlayBlur property documentation.

While the property is documented, consider adding:

  1. The valid range of values (e.g., 0-20)
  2. Example usage
  3. Visual impact description
docs/src/components/common-ui/vben-modal.md (1)

114-114: Consider enhancing the overlayBlur property documentation.

For consistency with the drawer component, consider adding:

  1. The valid range of values
  2. Example usage
  3. Visual impact description
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb9c8db and 182974b.

📒 Files selected for processing (12)
  • docs/src/components/common-ui/vben-drawer.md (1 hunks)
  • docs/src/components/common-ui/vben-modal.md (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (2 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue (2 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (2 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/sheet/SheetContent.vue (2 hunks)
  • playground/src/views/examples/drawer/base-demo.vue (1 hunks)
  • playground/src/views/examples/drawer/index.vue (2 hunks)
  • playground/src/views/examples/modal/blur-demo.vue (1 hunks)
  • playground/src/views/examples/modal/index.vue (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Test (ubuntu-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (8)
packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (1)

28-28: LGTM!

The property definition is consistent with the interface.

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

9-9: LGTM!

The implementation follows the existing pattern for modal initialization.

Also applies to: 51-53


88-90: LGTM!

The function implementation is consistent with other modal opening functions.


190-195: LGTM!

The card implementation follows the established pattern and includes clear description.

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

131-133: LGTM!

The button implementation follows the established pattern and includes clear labeling.

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

144-144: LGTM! Correct binding of overlayBlur property.

The overlayBlur property is correctly bound to the SheetContent component.

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

200-200: LGTM! Correct binding of overlayBlur property.

The overlayBlur property is correctly bound to the DialogContent component.

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

Line range hint 71-71: Verify the overlayBlur functionality across components.

The overlayBlur property is implemented consistently in both modal and drawer components. Please verify:

  1. The blur effect works correctly with different values
  2. The feature degrades gracefully when overlayBlur is undefined
  3. Performance impact of the blur effect on different devices

Run the following script to find all usages and test cases:

Also applies to: 80-80

✅ Verification successful

The overlayBlur feature is properly implemented and consistent across components

The verification shows:

  • Consistent implementation in both modal and drawer components
  • Proper reactive state management with dynamic updates
  • Graceful handling through component lifecycle events

The feature is working as intended and follows the established component patterns. No issues found with the overlayBlur functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all test files and examples using overlayBlur
echo "Searching for test files and examples..."
rg -l "overlayBlur" --type vue --type ts

# Find any performance-related tests
echo "Searching for performance tests..."
rg -l "performance|benchmark" --type test

Length of output: 311


Script:

#!/bin/bash
# Search for overlayBlur usage without type restrictions
echo "Searching for overlayBlur usage..."
rg -l "overlayBlur"

# Search for modal and drawer related files
echo "Searching for modal and drawer components..."
fd -e vue -e ts -e js "modal|drawer" --type f

# Look for specific implementation details
echo "Searching for blur effect implementation..."
rg -l "backdrop-filter.*blur|filter.*blur"

Length of output: 2397


Script:

#!/bin/bash
# Check implementation in core components
echo "Modal implementation:"
rg -A 5 "overlayBlur" "packages/@core/ui-kit/popup-ui/src/modal/modal.vue"

echo "\nDrawer implementation:"
rg -A 5 "overlayBlur" "packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue"

# Check test coverage
echo "\nTest coverage:"
rg -A 5 "overlayBlur" "packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts" "packages/@core/ui-kit/popup-ui/src/drawer/__tests__/drawer-api.test.ts"

# Check demo implementation
echo "\nDemo implementation:"
rg -A 5 "overlayBlur" "playground/src/views/examples/modal/blur-demo.vue"

Length of output: 1410

@mynetfan mynetfan merged commit 6719e26 into vbenjs:main Jan 11, 2025
14 checks passed
@mynetfan mynetfan deleted the feat/popup-overlay-blur branch January 11, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant