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

BitCarousel component improvements (#9705) #9711

Merged

Conversation

msynk
Copy link
Member

@msynk msynk commented Jan 22, 2025

closes #9705

Summary by CodeRabbit

  • New Features

    • Added customizable icons for left and right navigation buttons in the Carousel component
    • Enhanced Carousel and Swiper components with improved resize and pointer event handling
  • Bug Fixes

    • Corrected spelling of "separate" in Carousel component description
  • Refactor

    • Updated internal references and method names for better code clarity
    • Modified CSS selectors for more precise styling

Copy link

coderabbitai bot commented Jan 22, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces modifications to the Bit.BlazorUI carousel and swiper components, focusing on enhancing flexibility and code organization. Changes include renaming variables, updating method signatures, and adding new customization options like custom navigation icons. The modifications span multiple files across the Blazor UI project, affecting both the component implementations and their associated TypeScript and CSS files.

Changes

File Change Summary
src/BlazorUI/.../BitCarousel.razor Updated carousel container reference and icon rendering with conditional expressions
src/BlazorUI/.../BitCarousel.razor.cs Added GoLeftIcon and GoRightIcon parameters, renamed variables and methods
src/BlazorUI/.../BitCarousel.scss Modified CSS selector from :first-child to > :first-child
src/BlazorUI/.../BitSwiper.razor.cs Refactored method names and object reference handling
src/BlazorUI/.../BitSwiper.ts Updated method invocation for pointer leave event
src/BlazorUI/.../ObserversJsRuntimeExtensions.cs Modified resize observer method signatures
src/BlazorUI/.../Observers.ts Updated resize registration method parameters

Assessment against linked issues

Objective Addressed Explanation
CSS selector change
Custom icons for next/prev Added GoLeftIcon and GoRightIcon parameters
Reset timer while swiping No clear implementation visible
Accent color No changes related to accent color
ClassStyles No changes related to class styles

Poem

🎠 A carousel of code, spinning bright,
Refactored with rabbit's delight!
Icons dance, methods rename,
Flexibility is our game!
Hop, hop, hooray for clean design! 🐰


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

@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

🧹 Nitpick comments (2)
src/BlazorUI/Bit.BlazorUI/Scripts/Observers.ts (1)

5-14: Consider making the callback method name configurable.

The hardcoded "OnResize" method name reduces flexibility. Consider accepting the method name as a parameter to support different callback names for different use cases.

-        public static registerResize(id: string, element: HTMLElement, obj: DotNetObject) {
+        public static registerResize(id: string, element: HTMLElement, obj: DotNetObject, methodName: string = "OnResize") {
             const observer = new ResizeObserver(entries => {
                 const entry = entries[0];
                 if (!entry) return;
 
-                obj.invokeMethodAsync("OnResize", entry.contentRect);
+                obj.invokeMethodAsync(methodName, entry.contentRect);
             });
src/BlazorUI/Bit.BlazorUI/Components/Lists/Carousel/BitCarousel.razor.cs (1)

279-284: Ensure timer state is properly managed.

The timer state management could be improved to handle edge cases:

  1. Timer operations should be guarded against null
  2. Consider using a single await for the delay
-if (AutoPlay) _autoPlayTimer.Stop();
-await Task.Delay(50);
-if (AutoPlay) _autoPlayTimer.Start();
+if (AutoPlay && _autoPlayTimer is not null)
+{
+    _autoPlayTimer.Stop();
+    await Task.Delay(50);
+    _autoPlayTimer.Start();
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f68d7f5 and e6e135f.

📒 Files selected for processing (9)
  • src/BlazorUI/Bit.BlazorUI/Components/Lists/Carousel/BitCarousel.razor (2 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Lists/Carousel/BitCarousel.razor.cs (13 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Lists/Carousel/BitCarousel.scss (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Lists/Swiper/BitSwiper.razor.cs (6 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Lists/Swiper/BitSwiper.ts (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Extensions/JsInterop/ObserversJsRuntimeExtensions.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Scripts/Observers.ts (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Lists/Carousel/BitCarouselDemo.razor (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor.NavItems.cs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Lists/Carousel/BitCarouselDemo.razor
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (11)
src/BlazorUI/Bit.BlazorUI/Scripts/Observers.ts (1)

Line range hint 17-23: Verify object disposal.

The obj.dispose() call might cause issues if the same DotNetObject is used for multiple observers. Consider removing it and letting the caller handle disposal.

🧰 Tools
🪛 Biome (1.9.4)

[error] 2-26: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)

src/BlazorUI/Bit.BlazorUI/Extensions/JsInterop/ObserversJsRuntimeExtensions.cs (1)

8-14: LGTM! Good use of DynamicallyAccessedMembers attribute.

The attribute ensures proper trimming behavior when using AOT compilation.

src/BlazorUI/Bit.BlazorUI/Components/Lists/Swiper/BitSwiper.ts (1)

22-22: LGTM! Consistent event handler naming.

The change to "OnPointerLeave" aligns with the naming convention used for other event handlers like "OnResize".

src/BlazorUI/Bit.BlazorUI/Components/Lists/Swiper/BitSwiper.razor.cs (4)

96-101: LGTM! Method renamed for consistency.

The method has been renamed from OnRootResize to _OnResize to follow the naming convention for internal methods.


103-107: LGTM! Pointer leave handling refactored.

The pointer leave handling has been refactored to separate concerns, with _OnPointerLeave delegating to HandlePointerLeave.


230-249: LGTM! Well-structured pointer leave handling.

The HandlePointerLeave method contains a well-organized implementation with clear steps:

  1. Early return if pointer is not down
  2. Reset pointer state and cursor style
  3. Calculate swipe metrics
  4. Apply transition based on swipe speed
  5. Calculate and apply final position

298-305: LGTM! Proper disposal handling.

The disposal logic correctly handles the cleanup of the resize observer, with appropriate error handling for JSDisconnectedException.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor.NavItems.cs (1)

73-74: LGTM! Improved component descriptions.

Added clear and concise descriptions for both components:

  • Carousel: "Slideshow"
  • Swiper: "Touch slider"
src/BlazorUI/Bit.BlazorUI/Components/Lists/Carousel/BitCarousel.razor.cs (2)

50-58: LGTM! Added icon customization parameters.

New parameters allow customization of navigation button icons:

  • GoLeftIcon: Custom icon for the left navigation button
  • GoRightIcon: Custom icon for the right navigation button

224-227: LGTM! Improved code readability.

Added braces to if conditions in infinite scrolling logic, making the code more maintainable and less prone to errors.

Also applies to: 240-243

src/BlazorUI/Bit.BlazorUI/Components/Lists/Carousel/BitCarousel.scss (1)

27-29: LGTM! Improved selector specificity.

Changed to direct child selector (>) for better performance and more precise targeting.

@msynk msynk merged commit e635a93 into bitfoundation:develop Jan 23, 2025
3 checks passed
@msynk msynk deleted the 9705-blazorui-carousel-improvements branch January 23, 2025 12:13
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.

The BitCarousel component needs some improvements
1 participant