Add @attributes merging, class prefixing, lazy evaluation, and NullIfEmpty helpers#2
Draft
Add @attributes merging, class prefixing, lazy evaluation, and NullIfEmpty helpers#2
Conversation
…luation Co-authored-by: Kebechet <37485681+Kebechet@users.noreply.github.com>
Co-authored-by: Kebechet <37485681+Kebechet@users.noreply.github.com>
…cumentation Co-authored-by: Kebechet <37485681+Kebechet@users.noreply.github.com>
Co-authored-by: Kebechet <37485681+Kebechet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add class merging functionality to ClassBuilder
Add @attributes merging, class prefixing, lazy evaluation, and NullIfEmpty helpers
Dec 30, 2025
Kebechet
requested changes
Dec 30, 2025
Co-authored-by: Kebechet <37485681+Kebechet@users.noreply.github.com>
Kebechet
requested changes
Dec 30, 2025
Comment on lines
+78
to
+80
| public AttributeBuilder Add(string parameterName, bool when, Func<object?> valueFactory) | ||
| public AttributeBuilder Add(string parameterName, bool canAdd, Func<object?> valueFactory) | ||
| { | ||
| if (!when) | ||
| if (!canAdd) |
Owner
There was a problem hiding this comment.
order is still incorrect. Look at other ones and fix
Contributor
Author
There was a problem hiding this comment.
Fixed in 4543e23. Changed parameter order to Add(bool canAdd, string parameterName, Func<object?> valueFactory) to match the AddIf pattern where the condition comes first.
Co-authored-by: Kebechet <37485681+Kebechet@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Successfully implemented all features from the issue to achieve feature parity with BlazorComponentUtilities plus recommended enhancements.
✅ Features Implemented
1. Merge
classfrom@attributesAddClassFromAttributes()method for ClassBuilder2. Merge
stylefrom@attributesAddStyleFromAttributes()method for StyleBuilder3. Class prefixing
SetPrefix()andClearPrefix()methods4.
NullIfEmpty()helpernullfor empty/whitespace strings5. Lazy evaluation overloads
ClassBuilder:Add(Func<bool>, string),Add(bool canAdd, Func<string>)StyleBuilder:Add(Func<bool>, ...),Add(..., bool canAdd, Func<string>),Add(..., bool canAdd, Func<double>, ...)AttributeBuilder:Add(bool canAdd, string, Func<object?>)canAddto match existing conventionsAddIfpattern6. Raw style injection
AddVerbatim()method for StyleBuilder📊 Testing
📚 Documentation
🔧 Code Quality
📁 Files Changed
Original prompt
This section details on the original issue you should resolve
<issue_title>Improve based on BlazorComponentUtilities</issue_title>
<issue_description># ✅ Feature checklist (parity gaps + recommended additions)
This issue tracks features currently missing in Kebechet.Blazor.ClassBuilder (compared to BlazorComponentUtilities) plus closely-related additions that complete the
@attributesstory.✅ 1) Merge
classfrom@attributesclassvalues from an attributes dictionary (e.g., BlazorAdditionalAttributes/@attributes) intoClassBuilder.attributes == null→ no-op."class") → no-op.ToString()), document it.Proposed API
ClassBuilder AddClassFromAttributes(IReadOnlyDictionary<string, object?>? attributes, string key = "class")Example
✅ 2) Merge
stylefrom@attributesstylevalues from an attributes dictionary intoStyleBuilder.attributes == null→ no-op."style") → no-op.ToString()), document it.Proposed API
StyleBuilder AddStyleFromAttributes(IReadOnlyDictionary<string, object?>? attributes, string key = "style")Example
✅ 3) Class prefixing (
SetPrefix-style)-).@attributesclasses (recommended: do not prefix attribute classes).Proposed API
ClassBuilder SetPrefix(string? prefix, string separator = "-")ClassBuilder ClearPrefix()Example
✅ 4)
NullIfEmpty()helpernullinstead of empty/whitespace so Blazor won’t render empty attributes.ClassBuilderandStyleBuilder(optionallyAttributeBuildertoo, if it returns strings).Proposed API
string? ClassBuilder.NullIfEmpty()string? StyleBuilder.NullIfEmpty()Example
✅ 5) Lazy evaluation overloads (avoid work unless needed)
Func<bool>conditions to evaluate condition late.Func<string>,Func<object?>) so expensive values are only computed if condition is true.Proposed API (examples)
ClassBuilder Add(Func<bool> when, string value)ClassBuilder Add(bool when, Func<string> valueFactory)StyleBuilder Add(string name, bool when, Func<string> valueFactory, string? unit = null)AttributeBuilder Add(string name, bool when, Func<object?> valueFactory)Example
✅ 6) Raw style injection (alignment with merge story)
AddStyleFromAttributes.Proposed API
StyleBuilder AddVerbatim(string cssSnippet)StyleBuilder AddRaw(string cssSnippet)Example
✅ Test checklist (must-have)
Class merg...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.