HAVIT Blazor Bootstrap Documentation
repository·main·Indexed 20 days ago
https://github.com/havit/havit.blazorA free collection of Bootstrap 5.3-based components for ASP.NET Blazor. The library includes Havit.Blazor.ApplicationInsights for telemetry tracking, an MCP server for AI-assisted API documentation, and Havit.Bootstrap for managing and compiling customized Bootstrap CSS.
What's inside HAVIT Blazor Bootstrap
- HAVIT Blazor Bootstrap is a free component bundle providing Bootstrap 5.3 components specifically designed for ASP.NET Blazor applications. It includes a wide range of UI elements categorized into Forms, Buttons & Indicators, Data & Grid, Layout & Typography, Navigation, Modals & Interactions, and Special components. For interactive documentation and live demos, visit havit.blazor.eu.
Use the HAVIT Blazor Documentation MCP Server
mainThe HAVIT Blazor Documentation MCP (Model Context Protocol) server allows AI assistants (like GitHub Copilot) to access API documentation for HAVIT Blazor components. It provides tools to look up component parameters, properties, events, methods, and supporting types (enums, settings classes, delegates).Important development notes for Havit.Bootstrap
mainWhen working with the Havit.Bootstrap repository, adhere to these constraints:
- Customization: Do not modify files inside the
bootstrapfolder directly, except when performing a version update. All HAVIT-specific overrides must be implemented within thescssfolder. - Linting: The project uses its own
.editorconfigsettings, which differ from standard HAVIT settings to maintain compatibility with Bootstrap'sstylelintconfigurations.
- Customization: Do not modify files inside the
Display Toast notifications using HxMessenger
mainTo display toast messages, do not use the
HxToastcomponent directly in your user code. Instead, use theHxMessengerservice pattern:- Use
HxMessengeras a wrapper forHxToastContainerto manage the display area. - Dispatch messages through the
IHxMessengerServiceto triggerHxToastnotifications.
- Use
How HxMarkdown handles HTML security
mainBy default,
HxMarkdownis secure. TheSanitizeHtmlparameter (which defaults totrue) ensures that any HTML tags present in the input Markdown string are escaped before rendering.If you are processing content from a trusted source and want to allow raw HTML to pass through to the output, set
SanitizeHtmltofalseeither on the component instance or globally viaHxMarkdown.Defaults.SanitizeHtml.Use the HxMarkdown component
mainThe
HxMarkdowncomponent converts Markdown text into HTML and renders it using Bootstrap typography. It is designed to be a standalone parser without external dependencies.To use the component, pass your Markdown string to the
Contentparameter. You can also apply a custom CSS class viaCssClassto wrap the output in a<div>.@* Basic usage *@ <HxMarkdown Content="@markdownString" /> @* Usage with a custom CSS class *@ <HxMarkdown Content="@markdownString" CssClass="my-custom-class" />Test the MCP server with Copilot Chat
mainOnce the server is configured in your IDE, you can interact with it using natural language in Copilot Chat. For example, askingWhat parameters does HxButton have?will trigger theget_component_docstool to retrieve the relevant API documentation. For direct endpoint testing, you can use the provided.httpfile located atHavit.Blazor.Documentation.Mcp.http.Use Modals and Dialogs in HAVIT Blazor
mainHAVIT Blazor provides several components for handling modal interactions and dialogs:
HxMessageBox: A component used to display simple message boxes.HxModal: A component that renders a modal dialog following the Bootstrap Modal pattern.HxDialogBase: A base class designed to simplify the implementation of your own custom modal dialogs.HxOffcanvas: A component that renders a Bootstrap Offcanvas (also known as a Drawer).
Setup Havit.Blazor.ApplicationInsights
mainTo use Havit.Blazor.ApplicationInsights, follow these three steps:
1. Register services
Register the services in both your Server project and WebAssembly (Client) project using
AddBlazorApplicationInsights.Note on Configuration:
- If the
<HxApplicationInsights>component is prerendered or used in SSR, configure the options in the server project. - If rendered in WebAssembly without prerendering, configure in the client project.
2. Add the script component
Place the
<HxApplicationInsights />component inside the<head>element of your root layout orApp.razor. It must be placed before any other scripts.3. Inject and use
Inject
IBlazorApplicationInsightsinto your components to track events and other telemetry.// 1. Register services (Server or Client Program.cs) builder.Services.AddBlazorApplicationInsights(options => { options.JsSdkOptions.ConnectionString = "your-connection-string"; });// 2. Add script component (App.razor or Root Layout) @using Havit.Blazor.ApplicationInsights.Components <head> <HxApplicationInsights @rendermode="..." /> </head>// 3. Inject and use @inject IBlazorApplicationInsights AppInsights @code { protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await AppInsights.TrackEventAsync(new EventTelemetry { Name = "my-event" }); } } }- If the
Build and compile Havit.Bootstrap CSS
mainHavit.Bootstrap requires NodeJS (NPM or YARN) to compile, vendor-prefix, and minify CSS. The compilation process incorporates HAVIT-specific overrides located in the
scssfolder.Prerequisites
- NodeJS
- NPM or YARN
Build Commands
- Install dependencies: Run
yarnto install necessary packages. - One-time build: Use the
cssscript to compile, prefix, and minify the CSS. - Development mode: Use the
watchscript to act as a file-watcher; it will automatically re-run compilation scripts whenever changes are saved. - Deployment: Use the
publish-to-blazorscript to move the compiled files from thedistfolder toHavit.Blazor.Components.Web.Bootstrap/wwwroot.
yarn # To compile once yarn css # To watch for changes yarn watch # To publish to Blazor yarn publish-to-blazorUse Telemetry Initializers to attach tags
mainTelemetry initializers allow you to attach static tags (key-value pairs) to every telemetry item. Because the JS SDK does not support dynamic callbacks from .NET per item, tags are set at registration time.
Default telemetry initializer
Set this during service registration in
Program.csto ensure tags are present even on the initial auto-tracked page view.Runtime telemetry initializer
Use
AddTelemetryInitializerAsyncto attach tags dynamically during the application lifecycle.// Via options (Registration) builder.Services.AddBlazorApplicationInsights(options => { options.DefaultTelemetryInitializer = new TelemetryInitializer { CloudRoleName = "MyBlazorApp", ApplicationVersion = "1.2.3" }; }); // At runtime await AppInsights.AddTelemetryInitializerAsync(new TelemetryInitializer { CloudRoleName = "MyBlazorApp", ApplicationVersion = "1.2.3" });Configure Logging for WebAssembly
mainThe library includes an ASP.NET Core logging provider that forwards
ILoggerentries to Application Insights as traces or exceptions. This is primarily designed for Interactive WebAssembly.Register the provider
In your WebAssembly (Client) project (
Program.cs), you must explicitly callAddConfigurationbecause the WASM host does not readappsettings.jsonautomatically:builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging")); builder.Logging.AddBlazorApplicationInsights();Configure log levels
In
wwwroot/appsettings.json, use the provider aliasBlazorApplicationInsightsto set log levels:{ "Logging": { "LogLevel": { "Default": "Warning" }, "BlazorApplicationInsights": { "LogLevel": { "Default": "Error", "MyApp.Pages": "Warning" } } } }