Bakverk.Blazor
1.0.11
dotnet add package Bakverk.Blazor --version 1.0.11
NuGet\Install-Package Bakverk.Blazor -Version 1.0.11
<PackageReference Include="Bakverk.Blazor" Version="1.0.11" />
<PackageVersion Include="Bakverk.Blazor" Version="1.0.11" />
<PackageReference Include="Bakverk.Blazor" />
paket add Bakverk.Blazor --version 1.0.11
#r "nuget: Bakverk.Blazor, 1.0.11"
#:package Bakverk.Blazor@1.0.11
#addin nuget:?package=Bakverk.Blazor&version=1.0.11
#tool nuget:?package=Bakverk.Blazor&version=1.0.11
<img src="src/Bakverk.Blazor/wwwroot/icon.svg" width="96" alt="Bakverk.Blazor logo: a cinnamon bun" align="right" />
Bakverk.Blazor
My common Blazor component library, built on MudBlazor.
Install
dotnet add package Bakverk.Blazor
Setup
builder.Services.AddBakverkBlazor(); // includes AddMudServices() and BvThemeService
In _Imports.razor:
@using MudBlazor
@using Bakverk.Blazor
In index.html / App.razor, one stylesheet and one script, both in <head>:
<link rel="stylesheet" href="_content/Bakverk.Blazor/bakverk.blazor.css" />
<script src="_content/Bakverk.Blazor/bakverk.blazor.js" data-fontawesome-kit="your-kit-id"></script>
bakverk.blazor.cssimports Roboto, MudBlazor's CSS andcss/accessibility.css(focus rings,.skip-link,.visually-hidden).bakverk.blazor.jsloads MudBlazor's JS, plus Font Awesome ifdata-fontawesome-kitis set (falls back to the free CDN build if the kit is blocked, e.g. on localhost). Adddata-no-mudblazorif the app already includesMudBlazor.min.js.- Focus ring styling can be overridden with
--bv-focus-ring-width,--bv-focus-ring-outerand--bv-focus-ring-inner. - A focusable
role="listbox",grid,treeortreegrid(or anything witharia-activedescendant) gets no ring around itself; it should mark its active item instead.
In the layout, BvThemeProvider in place of MudThemeProvider, plus the usual MudBlazor providers:
<BvThemeProvider />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />
Demo
src/Bakverk.Blazor.Demo is a Blazor WebAssembly app that shows every component and style, with a dark mode toggle. It remembers the chosen theme and dark mode in localStorage (see ThemePreferences.cs).
dotnet run --project src/Bakverk.Blazor.Demo
Tests
src/Bakverk.Blazor.Tests: unit tests.src/Bakverk.Blazor.UiTests: Playwright tests that start the demo app and drive every component in headless Chromium.
dotnet build src/Bakverk.Blazor.slnx
pwsh src/Bakverk.Blazor.UiTests/bin/Debug/net11.0/playwright.ps1 install chromium
dotnet test src/Bakverk.Blazor.slnx
Conventions
- All components use the
Bvprefix:BvCard,BvConfirmDialog, … - Components build on MudBlazor; they don't replace it. Use
Mud*directly when noBv*wrapper exists.
Components
BvMonacoEditor
Monaco code editor (0.50.0, bundled). Nothing is downloaded until the first editor renders, and no script tags are needed.
<BvMonacoEditor @ref="_editor" Value="@_yaml" Language="yaml" DarkMode="@_isDarkMode" />
@code {
private BvMonacoEditor _editor = default!;
private async Task Save() => _yaml = await _editor.GetValueAsync();
}
Or two-way binding (one interop call per edit): <BvMonacoEditor @bind-Value="_text" Language="markdown" WordWrap />
Parameters: Value/ValueChanged, Language, ReadOnly, WordWrap, LineNumbers, Minimap, DarkMode, Height (default 600px), Class, Style.
BvMarkdownEditor
Simple, block-based markdown editor. Markdown shortcuts (# , - , 1. , [] , > , ```, ---) convert as you type, <kbd>Tab</kbd> indents list items, and anything the blocks can't represent (tables, …) is kept as raw markdown.
<BvMarkdownEditor @bind-Value="_markdown" />
<BvMarkdownEditor @ref="_editor" Value="@_markdown" OnChange="@(() => _dirty = true)" />
@code {
private BvMarkdownEditor _editor = default!;
private void Save() => _markdown = _editor.GetMarkdown();
}
Parameters: Value/ValueChanged, OnChange (raised on every edit without serializing).
BvMarkdownSplitEditor
Advanced markdown editor: markdown source in BvMonacoEditor with a live BvMarkdown preview beside it, stacked on narrow screens.
<BvMarkdownSplitEditor @bind-Value="_markdown" DarkMode="@_isDarkMode" Height="70vh" />
Parameters: Value/ValueChanged, ShowPreview (default true), WordWrap (default true), LineNumbers, ReadOnly, DarkMode, Height (default 600px), Class, Style.
BvMarkdown
Renders markdown as styled HTML (Markdig with GitHub-style extensions: tables, task lists, …). Styles are scoped to the component, so no stylesheet is needed. Raw HTML is passed through, so only render trusted content.
<BvMarkdown Value="@_markdown" />
Themes
BvThemes is a catalog of named MudThemes, each with a light and a dark palette: Fjord, Taiga, Frost, Bilberry, Cloudberry, Heather, Skerry, Polar Night, Granite, Rosehip, Tarn, Midnight Sun, Blue Hour, Harbor and Lavender (BvThemes.InitialName). BvThemes.Get(name) falls back to Lavender for unknown names.
BvThemes.OtherNames holds themes with more character that aren't in BvThemes.Names, so a menu built from Names won't list them. Pick one explicitly with Themes.SetTheme(BvThemes.BadlandsName):
- Badlands: cel-shaded comic look in the Borderlands Wiki's colors. Black pages with a maroon frame and gold links in dark mode, the same maroon, burnt orange and purple on light pages in light mode, black ink outlines with hard offset shadows on raised surfaces (cards, menus, popovers, dialogs), and uppercase Impact headings and buttons.
- Meadow: cozy farming-village look. Parchment, leaf green, berry pink and lavender by day, dusky indigo by night, storybook serif headings, soft rounded corners and a gentle ledge under raised surfaces.
BvThemeService (registered by AddBakverkBlazor()) holds the selected ThemeName and IsDark, and raises ThemeNameChanged and ThemeChanged. Persisting the choice is up to the app.
BvThemeProvider renders a MudThemeProvider that follows BvThemeService, and toggles dark mode when <kbd>F8</kbd> is pressed anywhere on the page, including inside an editor. Read Themes.IsDark (and subscribe to ThemeChanged) instead of keeping a local dark mode flag.
@inject BvThemeService Themes
<BvThemeProvider />
<MudIconButton Icon="@Icons.Material.Filled.DarkMode" OnClick="@Themes.ToggleAsync" aria-keyshortcuts="F8" />
@foreach (var name in BvThemes.Names)
{
<MudMenuItem OnClick="@(() => Themes.SetTheme(name))">@name</MudMenuItem>
}
AddBakverkBlazor(c => ...) passes the configuration on to AddMudServices.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Markdig (>= 1.6.0)
- Microsoft.AspNetCore.Components.Web (>= 11.0.0)
- MudBlazor (>= 9.14.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.