Component gallery and page samples
The gallery shows MudBlazor 9 components as working examples you can read: every example renders live beside the exact Razor source that produced it. Browse it in the live demo, or at /components when you run either host.
How a component page works
Each page lives in src/WebClient.Shared/Components/Gallery/<Group>/ and declares its route and metadata:
@page "/components/button"
@attribute [ComponentPage("Button", GalleryGroup.Actions, "Buttons start an action.", MudDocs = "button", Types = ["MudButton"])]
<ComponentPageFrame Page="GetType()">
<Example Of="typeof(ButtonVariants)" Title="Variants" Description="Emphasis comes from the variant." />
</ComponentPageFrame>
- Discovery.
GalleryCatalogfinds pages by their[ComponentPage]attribute and@pageroute. The navigation, the/componentsindex and the documentation landing page all read it, so adding a page never means editing a shared list. - One file per example. Each
<Example>renders a small component such asButtonVariants.razor. The project embeds every gallery.razorfile as a resource, andExampleSourcesshows that embedded file as the code. What you read is exactly what rendered. - Highlighting without markup.
SourceHighlighterclassifies Razor and C# tokens;CodeBlockrenders them as text spans, never as raw HTML. - Combinations.
EnumMatrix<TRow, TColumn>renders every combination of two enum parameters, such asVariant × Color, fromEnum.GetValues. Read it as a specimen table. - Playgrounds.
Playgroundputs a live component beside its controls;Snippetwrites the markup, leaving out values equal to the component’s defaults. PassOwner="this"and the playground can copy a link to its current settings and reset them.PlaygroundStatetreats every private, writable_fieldof text, number, switch, enum or color type as a setting. A link carries only the settings that differ from the defaults, and values from a link must parse and stay in range (text up to 200 characters, numbers 0–1000). - Quick search. Ctrl K (⌘ K on macOS) or the app bar’s search button opens
SiteSearchin a dialog. It indexes the labs, the gallery pages, the page samples, and every<Example>read from the embedded page sources, so a new example is searchable without registration. Example results link to the example’s anchor. - Isolation. Each example renders inside an error boundary, so one failing example cannot break the page.
Page samples
Samples under Components/Samples/ are whole screens — a dashboard, a sign-in flow, a storefront, a kanban board and more — composed only from MudBlazor components and synthetic data. Each declares [PageSample] and renders inside SamplePageFrame. They run in both hosts, so they never call a server.
Add a component page
- Pick the group folder and create
<Name>Page.razorwith@page "/components/<slug>"and[ComponentPage]. - Add one file per example, prefixed with the component name, in the same folder. Write examples to be read: short, idiomatic, meaningful synthetic data, accessible names on icon-only controls, no
h1. - Show the progression: basic usage, appearance, every combination of appearance enums, a realistic scenario, states (disabled, read-only, loading, errors), and a playground for main components.
- Use base-relative links and browser-only data so the page works in the WebAssembly demo.
- Give every control an accessible name: labels on inputs,
aria-labelon icon-only buttons,MudList,MudNavMenuand everyMudSlider(starting with its visible text, because the slider does not link its label), andAdornmentAriaLabelon adornment buttons. Inside aMudRadio, use plain elements rather thanMudStack.npm run check:demoaudits every page with axe and fails on violations our markup controls. - Run
dotnet test --filter GalleryTests. It renders every page with bUnit, fails if any example hits its error boundary, and checks that every example’s source is embedded. The integration tests prerender every gallery route over HTTP.
The visual identity
The app and this guide share one design: a printed lab manual with warm paper, ink and a vermilion accent, Fraunces for display type and IBM Plex for text and code, all self-hosted. The palette is defined once per surface, in LearningTheme.cs and the guide’s site.css, and checked against WCAG AA contrast. See DESIGN.md for the rules.