Quick Start
Only 2 steps to create automation component
Installation
Install-Package ComponentBuilder
using ComponentBuilder;
//...
builder.Services.AddComponentBuilder();
//...
Start
Inherits
BlazorComponentBase
instead of ComponentBaseFor .razor file component must add
@attributes="AdditionalAttributes"
attribute for automation features with specified HTML elementDefine
CssClassAttribute
for component or parameters
Example for .razor
file
.razor
fileCreate
Element.razor
file
@inherits BlazorComponentBase
<span @attributes="AdditionalAttributes"> <!--@attributes is necessary-->
@ChildContent
</span>
@code{
[Parameter] public RenderFragment? ChildContent { get; set; }
[Parameter][CssClass("active")] public bool Active { get; set; }
}
Execution in razor
<Element>Hello</Element>
<span>Hello</span>
<Element Active>Active Hello</Element>
<span class="active">Active Hello</span>
In Element.cs
class
Element.cs
classCreate
Element
class
[HtmlTag("span")]
public class Element : BlazorComponentBase, IHasChildContent
{
[Parameter] public RenderFragment? ChildContent { get; set; }
[Parameter][CssClass("active")] public bool Active { get; set; }
}
Execution in razor
<Element>Hello</Element>
<span>Hello</span>
<Element Active>Active Hello</Element>
<span class="active">Active Hello</span>
As you can see, using component classes can fully automate components, but the downside is that it requires a certain amount of concrete thinking, especially when dealing with complex components. Of course you can mix the two, but as long as it increases efficiency, it's a good idea.
Last updated