Overview

edit

Meziantou.AspNetCore.Components is a Razor class library of Blazor components and browser services.

dotnet package add Meziantou.AspNetCore.Components

Import the namespace in _Imports.razor:

@using Meziantou.AspNetCore.Components

The components need no registration. The services do; register the ones you use (the extension methods are in the Meziantou.AspNetCore.Components namespace):

builder.Services.AddClipboard();
builder.Services.AddQueryStringParameters();
builder.Services.AddTimeZoneServices();

The services are registered as scoped: one instance per user circuit in Blazor Server, one per application in Blazor WebAssembly.

Components

ComponentUse it toPage
Repeater<T>Render a template per item, with separator, empty and loading templatesRepeater and loading indicator
LoadingIndicatorShow a placeholder while data loadsRepeater and loading indicator
DataGrid<TRowData>Render a table from columns declared in markupData grid
InfiniteScrolling<T>Load more items when the user scrolls to the end of a listInfinite scrolling
GenericForm<TModel>Generate the editors of a form from the properties of a modelGenerated forms
InputDateTime<TValue>, InputEnumSelect<TEnum>, InputGuid<TValue>, InputUrl<TValue>Edit dates with a time, enums, GUIDs and URLs in an EditFormInput components
AnchorNavigationScroll to the element named by the #fragment of the URLAnchor navigation

The LogViewer component, which displays log entries, comes in its own package, Meziantou.AspNetCore.Components.LogViewer; see Log viewer.

Services

ServiceRegistrationUse it toPage
QueryStringServiceAddQueryStringParameters()Read and write component properties from the query stringQuery string
ClipboardServiceAddClipboard()Read and write text on the clipboardClipboard
TimeZoneServiceAddTimeZoneServices()Get the user's time zone and convert datesUser time zone

NavigationManager also gets extension methods to read query string values and update the URL; see Query string.

JavaScript and render modes

AnchorNavigation, InfiniteScrolling, ClipboardService and TimeZoneService call JavaScript. The scripts are static web assets of the package, under _content/Meziantou.AspNetCore.Components/, loaded on demand: there is no <script> tag to add, but the application must serve static web assets, as every Blazor application does.

JavaScript calls are only possible once the component is interactive, not during prerendering or static server-side rendering. Call these services from event handlers or from OnAfterRenderAsync. The other components (Repeater, LoadingIndicator, DataGrid, GenericForm and the inputs) also render with static server-side rendering.