-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(ImagePreview): support class/style html attirbute #7032
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
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIntroduces 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 componentclassDiagram
class ImagePreviewer {
+List<PreviewItem> PreviewList
+int ZIndex
+Dictionary<string, object>? AdditionalAttributes
-bool ShowButtons
+string? ClassString
+string? StyleString
+void ShowImage()
}
ImagePreviewer --> PreviewItem
Flow diagram for dynamic class and style attribute handling in ImagePreviewerflowchart 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"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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 ofattributes="@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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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-zindexfor flexible z-index customization - Refactored inline styles and classes to use
CssBuilderpattern with support forAdditionalAttributes - 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) |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
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.
| .AddClass($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0) | |
| .AddStyle($"--bb-viewer-zindex: {ZIndex};", ZIndex > 0) |
Link issues
fixes #7031
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
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:
Bug Fixes:
Enhancements: