Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Oct 30, 2025

Link issues

fixes #7031

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Support custom class and style attributes on ImagePreviewer by forwarding AdditionalAttributes to the root element and updating SCSS to leverage a z-index CSS variable

New Features:

  • Forward custom class and style HTML attributes to the ImagePreviewer root element via AdditionalAttributes

Bug Fixes:

Enhancements:

  • Use CSS variable (--bb-viewer-zindex) for the viewer’s z-index in the component styles

Copilot AI review requested due to automatic review settings October 30, 2025 04:56
@bb-auto bb-auto bot added the enhancement New feature or request label Oct 30, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 30, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces dynamic class/style handling in ImagePreviewer by adding builder properties, binding AdditionalAttributes in the component markup, and leveraging a CSS variable for z-index in the stylesheet.

Class diagram for updated ImagePreviewer component

classDiagram
    class ImagePreviewer {
        +List<PreviewItem> PreviewList
        +int ZIndex
        +Dictionary<string, object>? AdditionalAttributes
        -bool ShowButtons
        +string? ClassString
        +string? StyleString
        +void ShowImage()
    }
    ImagePreviewer --> PreviewItem
Loading

Flow diagram for dynamic class and style attribute handling in ImagePreviewer

flowchart TD
    A["User sets AdditionalAttributes (class/style)"] --> B["ImagePreviewer component receives AdditionalAttributes"]
    B --> C["ClassString and StyleString built using CssBuilder"]
    C --> D["<div> element binds class and style to ClassString and StyleString"]
    D --> E["CSS uses --bb-viewer-zindex variable for z-index"]
Loading

File-Level Changes

Change Details Files
Support merging user-defined class and style HTML attributes
  • Added ClassString property with CssBuilder to include default classes and AdditionalAttributes
  • Added StyleString property with CssBuilder to include default styles, conditional z-index, and AdditionalAttributes
src/BootstrapBlazor/Components/ImagePreviewer/ImagePreviewer.razor.cs
Update component markup to apply dynamic class/style and attribute binding
  • Bound AdditionalAttributes on the root
  • Replaced hardcoded class attribute with @ClassString
  • Replaced inline style with @StyleString
src/BootstrapBlazor/Components/ImagePreviewer/ImagePreviewer.razor
Enable CSS variable for z-index in styles
  • Added z-index: var(--bb-viewer-zindex, 5) to the SCSS for viewer mask/canvas
src/BootstrapBlazor/Components/ImagePreviewer/ImagePreviewer.razor.scss

Assessment against linked issues

Issue Objective Addressed Explanation
#7031 Allow the ImagePreviewer component to accept and apply 'class' and 'style' HTML attributes via AdditionalAttributes.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the 9.11.0 milestone Oct 30, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Use the Blazor attribute splatting syntax (<div @attributes="AdditionalAttributes">) instead of attributes="@AdditionalAttributes" so that extra attributes actually get applied.
  • In your StyleString builder you’re using AddClass to insert --bb-viewer-zindex, which will end up in the class list instead of style—switch to AddStyle to output it as an inline style.
  • You’re applying AdditionalAttributes both via the splatted attributes and in the CssBuilder methods, which will duplicate class/style values—either filter out those keys or remove the redundant usage.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Use the Blazor attribute splatting syntax (`<div @attributes="AdditionalAttributes">`) instead of `attributes="@AdditionalAttributes"` so that extra attributes actually get applied.
- In your StyleString builder you’re using AddClass to insert `--bb-viewer-zindex`, which will end up in the class list instead of style—switch to AddStyle to output it as an inline style.
- You’re applying AdditionalAttributes both via the splatted attributes and in the CssBuilder methods, which will duplicate class/style values—either filter out those keys or remove the redundant usage.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/ImagePreviewer/ImagePreviewer.razor.cs:99-102` </location>
<code_context>
+        .AddClassFromAttributes(AdditionalAttributes)
+        .Build();
+
+    private string? StyleString => CssBuilder.Default()
+        .AddClass($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0)
+        .AddStyleFromAttributes(AdditionalAttributes)
+        .Build();
</code_context>

<issue_to_address>
**suggestion:** Consider using AddStyle instead of AddClass for CSS custom property.

Since CSS custom properties like --bb-viewer-zindex should be set via style, using AddStyle instead of AddClass would be more appropriate if supported by CssBuilder.

```suggestion
    private string? StyleString => CssBuilder.Default()
        .AddStyle($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0)
        .AddStyleFromAttributes(AdditionalAttributes)
        .Build();
```
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/ImagePreviewer/ImagePreviewer.razor:5` </location>
<code_context>
 @attribute [BootstrapModuleAutoLoader]

-<div tabindex="-1" class="bb-previewer collapse active" id="@Id" style="z-index: @ZIndex;">
+<div attributes="@AdditionalAttributes" id="@Id" tabindex="-1" class="@ClassString" style="@StyleString">
     <div class="bb-viewer-mask"></div>
     <div class="bb-viewer-canvas">
</code_context>

<issue_to_address>
**issue (bug_risk):** The use of 'attributes' may not be standard Razor syntax.

Please confirm that your framework supports 'attributes="@AdditionalAttributes"', as incorrect usage may cause runtime errors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (54cb560) to head (c624fdf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7032   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          743       743           
  Lines        32463     32470    +7     
  Branches      4500      4500           
=========================================
+ Hits         32463     32470    +7     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit 4a6cd16 into main Oct 30, 2025
11 checks passed
@ArgoZhang ArgoZhang deleted the refactor-preview branch October 30, 2025 05:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the ImagePreviewer component to support customizable z-index through CSS variables and properly handle additional HTML attributes. The implementation allows consumers to override the default z-index value while maintaining consistency with the component's styling approach.

  • Added CSS variable --bb-viewer-zindex for flexible z-index customization
  • Refactored inline styles and classes to use CssBuilder pattern with support for AdditionalAttributes
  • Updated the Razor markup to use computed class and style strings

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
ImagePreviewer.razor.scss Adds CSS variable --bb-viewer-zindex with default value of 5 for z-index control
ImagePreviewer.razor.cs Implements ClassString and StyleString properties using CssBuilder to handle dynamic classes, styles, and z-index
ImagePreviewer.razor Updates the root div to use computed ClassString and StyleString with AdditionalAttributes support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

.Build();

private string? StyleString => CssBuilder.Default()
.AddClass($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0)
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AddClass method is being used to add CSS styles instead of the AddStyle method. Based on the CssBuilder implementation, AddClass is intended for CSS classes, not inline styles. This should use an appropriate method for adding inline styles, or the code should be corrected to properly format the style string as --bb-viewer-zindex: {ZIndex}; without using AddClass.

Suggested change
.AddClass($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0)
.AddStyle($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ImagePreview): support class/style html attirbute

2 participants