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

Add BitCollapse component (#9695) #9722

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Cyrus-Sushiant
Copy link
Member

@Cyrus-Sushiant Cyrus-Sushiant commented Jan 23, 2025

This closes #9695

Summary by CodeRabbit

  • New Features

    • Added a new Collapse component to the Bit BlazorUI library
    • Introduced ability to show/hide sections of content dynamically
    • Supports custom styling and right-to-left layouts
  • Documentation

    • Created demo page for Collapse component
    • Added navigation links for the new component
  • Styles

    • Implemented SCSS styles for Collapse component
    • Added custom styling options for root, expanded, and content states

Copy link

coderabbitai bot commented Jan 23, 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 a new BitCollapse component to the Bit.BlazorUI library, enabling developers to create collapsible content sections. The implementation includes a Razor component, a corresponding code-behind file, SCSS styles, and a class for managing custom styles. A demo page is also added to showcase the component's functionality, including basic usage, custom styling, and right-to-left support. The changes integrate the new component into the existing navigation and styling framework.

Changes

File Change Summary
src/BlazorUI/.../BitCollapse.razor New Blazor component for collapsible content
src/BlazorUI/.../BitCollapse.razor.cs Component code-behind with parameters and styling logic
src/BlazorUI/.../BitCollapse.scss Styling definitions for collapse component
src/BlazorUI/.../BitCollapseClassStyles.cs Custom styles configuration class
src/BlazorUI/.../components.scss Added import for new collapse styles
src/BlazorUI/.../BitCollapseDemo.razor Demo page showcasing collapse component features
src/BlazorUI/.../MainLayout.razor.NavItems.cs Added navigation item for collapse component

Assessment against linked issues

Objective Addressed Explanation
Implement Collapse component
Support content expansion/collapse
Enhance user interface organization

Poem

🐰 A collapsible tale of code so neat,
Bits folding in, a digital treat!
Expand and hide with magical flair,
UI dancing without a care 🎉
Rabbit's code, a compact delight! 🌟


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

🧹 Nitpick comments (10)
src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.razor (2)

10-13: Enhance accessibility attributes for the collapsible region.

The role="region" is good, but additional ARIA attributes would improve accessibility:

 <div role="region"
+     aria-expanded="@Expanded"
      style="@Styles?.Content"
      class="bit-col-con @(Expanded ? "bit-col-cex" : "bit-col-cco") @Classes?.Content"
      tabindex="@(IsEnabled ? 0 : -1)">

4-9: Consider adding keyboard interaction support.

The root element should handle keyboard events (Enter/Space) to toggle the collapse state when focused.

 <div @ref="RootElement" @attributes="HtmlAttributes"
      id="@_Id"
      style="@StyleBuilder.Value"
      class="@ClassBuilder.Value"
      dir="@Dir?.ToString().ToLower()"
-     aria-label="@AriaLabel">
+     aria-label="@AriaLabel"
+     @onkeydown="@OnKeyDown"
+     role="button">
src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapseClassStyles.cs (1)

3-19: Consider adding validation and helper methods.

The class could benefit from:

  1. Method to validate CSS class names
  2. Helper method to combine multiple classes
  3. Constructor with default values
 public class BitCollapseClassStyles
 {
+    public BitCollapseClassStyles()
+    {
+        Root = string.Empty;
+        Expanded = string.Empty;
+        Content = string.Empty;
+    }
+
+    private static string ValidateCssClass(string? value)
+    {
+        if (string.IsNullOrWhiteSpace(value)) return string.Empty;
+        // Add CSS class validation logic if needed
+        return value;
+    }
+
     /// <summary>
     /// Custom CSS classes/styles for the root element of the BitCollapse.
     /// </summary>
-    public string? Root { get; set; }
+    public string? Root 
+    { 
+        get => _root;
+        set => _root = ValidateCssClass(value);
+    }
+    private string? _root;
src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.razor.cs (1)

21-22: Add event callback for state changes.

Consider adding an event callback to notify parent components of state changes.

 [Parameter, ResetClassBuilder, ResetStyleBuilder]
 public bool Expanded { get; set; }
+
+[Parameter]
+public EventCallback<bool> ExpandedChanged { get; set; }
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.cs (2)

77-80: Add state change error handling.

Consider demonstrating error handling for state changes in the demo.

 private void OnExpandCollapseClick()
 {
-    expanded = !expanded;
+    try
+    {
+        expanded = !expanded;
+        StateHasChanged();
+    }
+    catch (Exception ex)
+    {
+        // Demo error handling
+        Console.WriteLine($"Error toggling state: {ex.Message}");
+    }
 }

5-39: Add performance optimization examples.

Consider adding examples demonstrating performance optimization techniques:

  1. Lazy loading of content
  2. Virtualization for large content
  3. Debounced collapse/expand
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.samples.cs (1)

17-32: Consider using CSS variables for better maintainability.

While the example effectively demonstrates both inline styles and CSS classes, consider:

  1. Using CSS variables instead of hardcoded colors (e.g., var(--bit-primary-color) instead of #0054C6)
  2. Preferring CSS classes over inline styles for better maintainability
-    background-color: #333;
+    background-color: var(--bit-background-color);
-    border: 1px solid #ff0000;
+    border: 1px solid var(--bit-error-color);
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor (1)

22-49: Consider extracting repeated Lorem ipsum text to a constant.

The examples contain duplicate Lorem ipsum text. Consider extracting it to a constant in the code-behind file to improve maintainability.

+private const string LoremIpsumText = "Lorem ipsum dolor sit amet...";
-Lorem ipsum dolor sit amet, consectetur adipiscing elit...
+@LoremIpsumText
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.scss (1)

4-8: Use theme variables for consistent styling.

Replace hardcoded color values with theme variables to maintain consistency with the design system.

 .custom-expanded {
     padding: 10px;
-    background-color: #808080;
-    border: 1px solid #0054C6;
+    background-color: $clr-bg-sec;
+    border: 1px solid $clr-pri;
 }
src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.scss (1)

22-22: Consider making transition duration configurable.

The transition duration is hardcoded to 300ms. Consider making it configurable through a CSS variable to allow customization.

-    transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
+    transition: all var(--bit-collapse-transition-duration, 300ms) cubic-bezier(0.4, 0, 0.2, 1) 0ms;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f200dab and 17f190f.

📒 Files selected for processing (12)
  • src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.razor (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.scss (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapseClassStyles.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Styles/components.scss (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.cs (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.samples.cs (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.scss (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Home/ComponentsSection.razor (2 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor.NavItems.cs (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/compilerconfig.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (10)
src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.razor.cs (1)

33-38: Consider adding transition completion handling.

The CSS class registration looks good, but consider adding transition end event handling for better animation control.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor.samples.cs (2)

5-15: LGTM! Clear and effective basic example.

The example effectively demonstrates the core functionality of the BitCollapse component with a toggle button and state management.


34-44: LGTM! Well-implemented RTL support.

The example properly demonstrates RTL functionality with appropriate Persian text and consistent toggle behavior.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Surfaces/Collapse/BitCollapseDemo.razor (2)

1-10: LGTM! Clear component metadata and description.

The component's route, metadata, and description are well-structured and follow the established pattern.


11-20: LGTM! Well-structured basic example implementation.

The example effectively demonstrates the component's usage with proper component composition.

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

121-121: LGTM! Properly integrated navigation item.

The Collapse component is correctly added to the Surfaces section, maintaining alphabetical order and following the established pattern.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Home/ComponentsSection.razor (1)

188-190: LGTM! Consistent component link implementation.

The Collapse component link is properly integrated into the Surfaces section, following the established pattern and styling.

src/BlazorUI/Bit.BlazorUI/Components/Surfaces/Collapse/BitCollapse.scss (1)

28-28: Review margin compensation approach.

Using negative margins to compensate for padding might cause layout shifts. Consider using height: 0 and padding: 0 in the collapsed state instead.

 .bit-col-cco {
     opacity: 0;
     max-height: 0;
-    margin: spacing(-1.5) 0;
+    padding: 0;
 }
src/BlazorUI/Bit.BlazorUI/Styles/components.scss (1)

71-71: LGTM!

The BitCollapse component import is correctly placed in the Surfaces section, maintaining the established organization pattern.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/compilerconfig.json (1)

368-373: LGTM!

The compiler configuration for BitCollapseDemo follows the established pattern and maintains consistency with other component configurations.

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 BlazorUI needs a Collapse component
1 participant