Rf
is a static helper class made with optimized functions to help when developing in Blazor.
A Static Helper Class
Rf
is a static helper class made with optimized functions to help when developing in Blazor.
Below list out the functions of Rf
.
Class
Use Rf.Class
to generate a quickly concatenate classes together by string.
// Concatenates a list of classes together.
public static string Class(params string[] classes)
... CssClass=@Rf.Class("class-a", "class-b") ...
ClassWhen
Use Rf.ClassWhen
to generate a dynamic class list in line or from the code behind.
// Concatenates classes together based on when show is true.
public static string ClassWhen(params (string cssClass, bool show)[] classes)
... CssClass=@Rf.ClassWhen(("has-text-grey", IsDeleted)) ...
StyleWhen
Use Rf.StyleWhen
to generate a dynamic style attribute in line or from the code behind.
// Concatenates styles together based on when show is true. Only returns styles that are not null or whitespace in either style name or value.
public static string StyleWhen(params (string styleName, string value, bool show)[] styles)
string value = Rf.StyleWhen(("color", "green", true));
//value -> color:green;
bool IsDeleted = true;
bool IsSpecial = false;
value = Rf.StyleWhen(("color", "#333", IsDeleted)
, ("background-color", "yellow", IsSpecial));
//value -> color:#333;
Setting up RForge is simple. Follow the below steps to add RForge Blazor components to your project.
RForge Blazor components are installed via Nuget. There are two packages. One for the blazor app and one for the library if any.
dotnet add package RForge.Blazor
Install-Package RForge.Blazor
This is optional but may be useful if you want to use common enums across the backend and frontend.
dotnet add package RForge.Abstractions
Install-Package RForge.Abstractions
To simplify namespacing while using RForge,
the package is designed with most all components sitting within the root RForge
namespace.
You may want to include the following namespaces in your _import.razor
for ease of use.
@using RForgeBlazor
@using RForgeBlazor.Services
@using RForge.Abstractions
Namespace | Purpose |
---|---|
RForgeBlaozr |
Houses all of the blazor components. |
RForgeBlaozr.Services |
Houses interfaces you may need to communicate with certain components. |
RForgeBlaozr.Abstractions |
Common enums used through out the components. |
In order for some components to work they must first have their services registered.
Open up Program.cs
and add the following line before the var app = builder.Build();
.
using RForgeBlazor;
//...
builder.Services.AddRfForgeBlazorServices();
//...
var app = builder.Build();
RForge makes use of Bulma CSS to stylize the components. Add / install Bulma and add the CSS file to the head. Link to download: Bulma releases.