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

Improve Float feature of BitButton (#9358) #9359

Merged

Conversation

msynk
Copy link
Member

@msynk msynk commented Nov 30, 2024

closes #9358

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new FloatOffset parameter for enhanced floating button positioning.
    • Added new CSS classes for improved button styling and positioning.
    • Updated button demo examples to showcase new functionalities, including loading states and float customization.
  • Bug Fixes

    • Improved clarity in parameter documentation for floating behavior.
  • Documentation

    • Enhanced examples and descriptions in the button demo for better user understanding.
  • Chores

    • Updated project file structure and syntax for better maintainability.

Copy link

coderabbitai bot commented Nov 30, 2024

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 changes in this pull request enhance the BitButton component within the Bit.BlazorUI namespace. Key updates include improved documentation for existing parameters, the introduction of a new FloatOffset parameter, and modifications to CSS classes to better handle floating behavior. The project file has been updated to include a new folder for utilities, and the demo files have been refined to better showcase the button's features, including new examples and enhanced customization options.

Changes

File Change Summary
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor.cs Updated documentation for Float and FloatAbsolute, added FloatOffset, modified CSS class registration logic.
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.scss Added new CSS classes for button positioning, introduced --bit-btn-float-offset variable, modified existing classes to use this variable.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Bit.BlazorUI.Demo.Client.Core.csproj Updated BuildIsolatedScssFiles target syntax, added folder for PullToRefresh.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor Changed title of floating example, added FloatOffset property, updated button examples for clarity.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.cs Updated parameter descriptions, added FloatOffset, modified initialization of floatPosition.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.samples.cs Expanded examples with new attributes, removed old examples, added new functionalities and styles.

Assessment against linked issues

Objective Addressed Explanation
Improve documentation for Float and FloatAbsolute parameters (9358)
Add FloatOffset parameter (9358)
Correct CSS style for positioning related to floating (9358)
Improve implementation of FloatAbsolute (9358) No changes were made to the implementation logic.
Address incorrect documentation (9358) Some documentation was updated, but not all.

🐰 In the garden where buttons float,
With offsets and styles, we now gloat.
A toggle here, a dropdown there,
Our buttons dance without a care!
With colors bright and functions grand,
A whimsical world at our command! 🌼


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

@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: 2

🧹 Outside diff range and nitpick comments (10)
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.scss (1)

101-114: Refactor floating button classes for better maintainability

The floating button classes have duplicated z-index values and lack documentation.

Consider these improvements:

+ // Full-width button variant
 .bit-btn-flw {
     width: 100%;
-    z-index: $zindex-base;
+    @extend %bit-btn-float-base;
 }

+ // Base styles for floating buttons
+ %bit-btn-float-base {
+    z-index: $zindex-base;
+ }

+ // Absolute positioned floating action button
 .bit-btn-fab {
     position: absolute;
-    z-index: $zindex-base;
+    @extend %bit-btn-float-base;
 }

+ // Fixed positioned floating button
 .bit-btn-ffx {
     position: fixed;
-    z-index: $zindex-base;
+    @extend %bit-btn-float-base;
 }
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor.cs (2)

81-85: Enhance FloatOffset parameter documentation

While the parameter implementation is correct, the documentation could be more helpful by specifying:

  • Expected format (e.g., CSS units like px, rem, etc.)
  • Examples of valid values
  • Default value if any

Example enhancement:

 /// <summary>
-/// Specifies the offset of the floating button.
+/// Specifies the offset of the floating button using CSS units (e.g., "16px", "1rem").
+/// When not specified, default offset from the CSS class is used.
 /// </summary>

Line range hint 260-274: Consider extracting default position to a constant

The position handling is comprehensive, but the default position ("bit-btn-brg") could be extracted to a constant for better maintainability.

+private const string DEFAULT_FLOAT_POSITION_CLASS = "bit-btn-brg";
+
 ClassBuilder.Register(() => (Float || FloatAbsolute) ? FloatPosition switch
 {
     BitPosition.TopRight => "bit-btn-trg",
     BitPosition.TopCenter => "bit-btn-tcr",
     BitPosition.TopLeft => "bit-btn-tlf",
     BitPosition.CenterLeft => "bit-btn-clf",
     BitPosition.BottomLeft => "bit-btn-blf",
     BitPosition.BottomCenter => "bit-btn-bcr",
     BitPosition.BottomRight => "bit-btn-brg",
     BitPosition.CenterRight => "bit-btn-crg",
     BitPosition.Center => "bit-btn-ctr",
-    _ => "bit-btn-brg"
+    _ => DEFAULT_FLOAT_POSITION_CLASS
 } : string.Empty);
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.cs (3)

90-95: Consider enhancing FloatOffset documentation with examples

While the description is clear, it would be helpful to provide examples of valid offset values (e.g., "10px", "1rem", etc.) to guide developers.

             Name = "FloatOffset",
             Type = "string?",
             DefaultValue = "null",
-            Description = "Specifies the offset of the floating button.",
+            Description = "Specifies the offset of the floating button. Examples: \"10px\", \"1rem\", \"2em\".",

102-102: Enhance FloatPosition parameter documentation

The current description could be more informative about how this parameter interacts with Float and FloatAbsolute features.

-            Description = "Specifies the position of the floating button.",
+            Description = "Specifies the position of the floating button when Float or FloatAbsolute is enabled. Controls the anchor point relative to either the viewport or container.",

698-707: Improve LINQ chain readability

The LINQ expression for creating dropdown items could be more readable with proper indentation.

-    private readonly List<BitDropdownItem<BitPosition>> floatPositionList = Enum.GetValues<BitPosition>()
-                                                                                .Cast<BitPosition>()
-                                                                                .Select(enumValue => new BitDropdownItem<BitPosition>
-                                                                                {
-                                                                                    Value = enumValue,
-                                                                                    Text = enumValue.ToString()
-                                                                                })
-                                                                                .ToList();
+    private readonly List<BitDropdownItem<BitPosition>> floatPositionList = Enum.GetValues<BitPosition>()
+        .Cast<BitPosition>()
+        .Select(enumValue => new BitDropdownItem<BitPosition>
+        {
+            Value = enumValue,
+            Text = enumValue.ToString()
+        })
+        .ToList();
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.samples.cs (2)

169-172: Consider enhancing the FloatAbsolute demo container

While the implementation is correct, consider these improvements to make the demo more intuitive:

  1. Add visual indicators for the container boundaries
  2. Include examples of different container sizes
  3. Demonstrate interaction with scrollable content
 <div style="position: relative; border: 1px gray solid">
+    <div style="position: absolute; top: 0; left: 0; padding: 4px; background: rgba(0,0,0,0.1)">Container with relative positioning</div>
     <BitButton FloatAbsolute FloatPosition="@floatPosition" FloatOffset="@floatOffset" IconName="@BitIconName.Edit" IconOnly />
     <div style="height: 300px; overflow: auto">

181-188: Consider enhancing the float position dropdown items

While the implementation is functional, consider adding descriptions to help users understand each position's effect.

 private readonly List<BitDropdownItem<BitPosition>> floatPositionList = Enum.GetValues<BitPosition>()
     .Cast<BitPosition>()
     .Select(enumValue => new BitDropdownItem<BitPosition>
     {
         Value = enumValue,
-        Text = enumValue.ToString()
+        Text = enumValue.ToString(),
+        Description = GetPositionDescription(enumValue)
     })
     .ToList();

+private static string GetPositionDescription(BitPosition position) => position switch
+{
+    BitPosition.TopLeft => "Aligns to the top-left corner",
+    BitPosition.TopRight => "Aligns to the top-right corner",
+    BitPosition.BottomLeft => "Aligns to the bottom-left corner",
+    BitPosition.BottomRight => "Aligns to the bottom-right corner",
+    _ => string.Empty
+};
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor (2)

217-219: Consider adding input validation for FloatOffset.

The UI controls look good, but the FloatOffset TextField might benefit from input validation to ensure valid numeric values.

-<BitTextField Label="FloatOffset" @bind-Value="floatOffset" Immediate />
+<BitTextField Label="FloatOffset" @bind-Value="floatOffset" Immediate 
+              Type="BitTextFieldType.Number" 
+              Min="0" />

223-229: Consider adding ARIA attributes for better accessibility.

The FloatAbsolute example effectively demonstrates the feature with scrollable content. Consider enhancing accessibility for screen readers.

-<BitButton FloatAbsolute FloatPosition="floatPosition" FloatOffset="@floatOffset" IconName="@BitIconName.Edit" IconOnly />
+<BitButton FloatAbsolute FloatPosition="floatPosition" FloatOffset="@floatOffset" 
+          IconName="@BitIconName.Edit" IconOnly
+          aria-label="Edit" role="button" />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 14d2664 and 9479db4.

📒 Files selected for processing (6)
  • src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor.cs (3 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.scss (3 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Bit.BlazorUI.Demo.Client.Core.csproj (2 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.cs (2 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.samples.cs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Bit.BlazorUI.Demo.Client.Core.csproj
🔇 Additional comments (11)
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.scss (2)

22-22: LGTM: Well-structured float offset variable

The new --bit-btn-float-offset variable follows naming conventions and uses the spacing function for consistency.


92-95: LGTM: No-text button variant

The .bit-btn-ntx class appropriately handles padding and icon margin reset for buttons without text.

src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor.cs (3)

69-79: Documentation improvements align with PR objectives

The updated documentation clearly distinguishes between viewport-relative (Float) and container-relative (FloatAbsolute) positioning, making it easier for developers to choose the appropriate option.


253-258: LGTM: Clean class registration implementation

The class registration logic correctly handles both floating modes with appropriate CSS class names following the established naming pattern.


278-279: LGTM: Clean float offset style implementation

The float offset style registration correctly uses CSS custom properties and handles null values appropriately.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.cs (1)

81-81: Documentation improvements look good!

The updated descriptions clearly differentiate between viewport-relative and container-relative positioning for the Float features.

Also applies to: 88-88

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.samples.cs (3)

164-165: LGTM: Float controls implementation

The implementation provides intuitive controls for demonstrating the Float feature's positioning and offset capabilities.


167-167: LGTM: Float feature demonstration

The floating button implementation effectively showcases the Float feature with dynamic position and offset controls.


178-179: LGTM: Float parameters implementation

The state variables for float parameters are correctly implemented with appropriate types.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor (2)

212-212: LGTM! Title change is consistent with component terminology.

The rename from "Floating" to "Float" better aligns with the component's property names.


221-221: LGTM! Good demonstration of FloatOffset feature.

The example effectively shows how to use both Float and FloatOffset properties together.

@msynk msynk merged commit f36e9ff into bitfoundation:develop Dec 1, 2024
3 checks passed
@msynk msynk deleted the 9358-blazorui-button-float-improvements branch December 1, 2024 14:22
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 new Float feature of the BitButton needs some improvements
3 participants