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 IconUrl parameter to BitButton component (#9863) #9864

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

msynk
Copy link
Member

@msynk msynk commented Feb 12, 2025

closes #9863

Summary by CodeRabbit

  • New Features

    • The button component now supports displaying a custom image icon through a new image URL option.
  • Style

    • Updated icon styling ensures consistent appearance across various button sizes.
  • Documentation

    • Demo examples have been expanded to illustrate the new image icon functionality, including configurations for reversed icon displays.

Copy link

coderabbitai bot commented Feb 12, 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 changes update the BitButton component to support image icons using a new property, IconUrl. Conditional logic was added to the Razor component to render an <img> element when IconUrl is provided and the button is not in a loading state, while leaving the existing IconName logic unchanged. The code-behind now includes the new IconUrl property, and the SCSS file introduces a new CSS class and variable enhancements for consistent icon sizing. Demo files have been updated to showcase and document the usage of the new attribute.

Changes

File(s) Change Summary
src/BlazorUI/.../BitButton.razor Added conditional rendering to display an <img> element when IconUrl is provided, while preserving the existing IconName rendering logic.
src/BlazorUI/.../BitButton.razor.cs Introduced a new nullable property IconUrl to allow custom icon URLs.
src/BlazorUI/.../BitButton.scss Added the .bit-btn-icnu class and integrated the --bit-btn-icn-size variable into the existing button size classes for consistent icon styling.
src/BlazorUI/Demo/.../BitButtonDemo.* Updated demo files (.razor, .razor.cs, .razor.samples.cs) to include examples that utilize the new IconUrl attribute, demonstrating image icon usage.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant B as BitButton
    participant R as Renderer

    U->>B: Render Button (with IconUrl value)
    B->>R: Check if in loading state
    alt Button is loading
        R-->>B: Render spinner indication
    else Button is not loading
        B->>R: Evaluate rendering conditions
        alt IconName provided
            R-->>B: Render icon using IconName
        else
            B->>R: Check if IconUrl is provided
            alt IconUrl exists
                R-->>B: Render <img> with IconUrl
            end
        end
    end
Loading

Poem

I'm a rabbit with a hop and a click,
New icon images now do the trick.
Conditional logic makes the button shine,
Rendered smoothly, every line.
Hoppy coding days, oh so slick! 🥕

(Happy hops to a brighter UI!)


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.

@msynk msynk changed the title Add IconUrl parameter to BitBtton component (#9863) Add IconUrl parameter to BitButton component (#9863) Feb 12, 2025
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: 1

🔭 Outside diff range comments (1)
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor (1)

97-100: ⚠️ Potential issue

Add IconUrl support to anchor tag rendering.

The anchor tag rendering block only supports IconName but not IconUrl. For consistency, add the same IconUrl support here.

Apply this diff to add IconUrl support:

        @if (IconName.HasValue())
        {
            <i style="@Styles?.Icon" class="bit-btn-icn bit-icon bit-icon--@IconName @Classes?.Icon" />
        }
+       else if(IconUrl.HasValue())
+       {
+           <img src="@IconUrl" style="@Styles?.Icon" class="bit-btn-icnu @Classes?.Icon" />
+       }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fcf1a9 and 0dfa849.

⛔ Files ignored due to path filters (1)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Web/wwwroot/images/bit-logo.svg is excluded by !**/*.svg
📒 Files selected for processing (6)
  • src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.scss (4 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 (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Buttons/BitButtonDemo.razor.samples.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (5)
src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.razor (1)

29-32: LGTM! Clean implementation of the image icon support.

The implementation correctly handles the IconUrl parameter, using the existing style and class infrastructure while maintaining mutual exclusivity with IconName.

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

118-121: LGTM! Well-documented parameter addition.

The IconUrl parameter is correctly implemented with proper nullability and clear XML documentation.

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

53-59: Verify the availability of the demo image.

The examples use "/images/bit-logo.svg" which might not be available in the project.

Run the following script to check if the image exists:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check if the demo image exists in the public/static directories

# Search for the image file
fd 'bit-logo.svg' --type f

Length of output: 452


Demo image verified
The image file exists in the expected location (src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/wwwroot/images/bit-logo.svg) and in related paths, confirming that the /images/bit-logo.svg reference is valid.

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

91-102: LGTM! Verify the image URL.

The examples effectively demonstrate the new IconUrl parameter with different button variants and positions. The implementation follows the existing demo patterns and provides comprehensive coverage of the feature.

Run the following script to verify the image URL:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Verify that the image file exists in the public directory.

# Test: Check if the image file exists. Expect: File exists.
fd --type file "bit-logo.svg" --exec file {}

Length of output: 226


I'm noticing that the previous verification command failed because the external file command wasn’t available in the environment. Let's try a different approach that avoids invoking the file command. Please run the following shell script to search for the image file using the more universally available find command:

If this script returns one or more paths (especially something like public/images/bit-logo.svg or a similar location), it will confirm that the image URL /images/bit-logo.svg referenced in the component points to an existing file.

Once you run this script, please manually verify the output to ensure the image file is located where expected.


🏁 Script executed:

#!/bin/bash
# Verify that the image file bit-logo.svg exists anywhere in the repository.
find . -type f -name "bit-logo.svg"

Length of output: 471


Image URL Verified

The file bit-logo.svg was found at locations corresponding to the public directories (e.g., within Bit.BlazorUI.Demo.Client.Core/wwwroot/images/), confirming that the URL /images/bit-logo.svg correctly points to an existing image file.

src/BlazorUI/Bit.BlazorUI/Components/Buttons/BitButton/BitButton.scss (1)

66-69: LGTM! Well-structured icon sizing implementation.

The changes introduce a robust system for URL-based icon sizing:

  • New .bit-btn-icnu class ensures consistent width and height for icons.
  • Size variables scale appropriately with button sizes (small: 1.5, medium: 2, large: 2.5).
  • Implementation follows existing patterns and maintains consistency.

Also applies to: 326-326, 338-338, 350-350

@msynk msynk merged commit 332071e into bitfoundation:develop Feb 12, 2025
3 checks passed
@msynk msynk deleted the 9863-blazorui-button-iconurl branch February 12, 2025 10:10
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 BitButton requires an IconUrl parameter
2 participants