Agent skill
blazor-mudblazor-guidelines
Blazor component best practices and MudBlazor usage for ISLAMU Event. Covers Server + WebAssembly hybrid, MudBlazor components, lifecycle, state management, and render modes.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/blazor-mudblazor-guidelines
SKILL.md
Blazor + MudBlazor Guidelines
π― Purpose
Provides best practices for building UI components with Blazor (Server + WebAssembly hybrid) and MudBlazor in the ISLAMU Event project.
β‘ When This Skill Activates
Triggered by:
- Keywords: "blazor", "component", "razor", "mudblazor", "ui", "page", "dialog", "render", "parameter"
- File patterns:
**/*.razor,**/*.razor.cs,**/*.Client/**/*.cs - Content patterns:
@page,@inject,<Mud,Parameter,EventCallback
ποΈ ISLAMU Event Blazor Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Blazor Hybrid Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Explore.Blazor (Server) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Server-side Blazor (BFF pattern) β β
β β β’ OIDC Authentication with Keycloak β β
β β β’ Cookie-based auth β β
β β β’ HttpContext access β β
β β β’ Components/Pages/*.razor β β
β β β’ @rendermode="InteractiveAuto" β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β Explore.Blazor.Client (WebAssembly) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Client-side Blazor (WASM) β β
β β β’ Runs in browser β β
β β β’ No server access β β
β β β’ Shared components β β
β β β’ Layout/MainLayout.razor β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Render Mode: InteractiveAuto β
β ββ Starts with Server (fast initial load) β
β ββ Downloads WASM in background β
β ββ Switches to client-side after download β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Resources
| Resource | Description |
|---|---|
| component-structure.md | Blazor lifecycle, @code blocks, parameters |
| mudblazor-components.md | MudGrid, MudButton, MudDialog, MudTable |
| state-management.md | CascadingValue, EventCallback, services |
| render-modes.md | InteractiveAuto, Server, WebAssembly |
| common-patterns.md | Forms, dialogs, tables, navigation |
β‘ Quick Reference
Basic Component Structure
@page "/events"
@using MudBlazor
@inject HttpClient Http
@inject NavigationManager NavigationManager
<PageTitle>Events</PageTitle>
<MudContainer MaxWidth="MaxWidth.Large">
<MudText Typo="Typo.h4" Class="mb-4">Events</MudText>
@if (_events == null)
{
<MudProgressCircular Indeterminate="true" />
}
else
{
<MudGrid>
@foreach (var evt in _events)
{
<MudItem xs="12" md="6" lg="4">
<MudCard>
<MudCardContent>
<MudText Typo="Typo.h5">@evt.Title</MudText>
<MudText Typo="Typo.body2">@evt.Description</MudText>
</MudCardContent>
<MudCardActions>
<MudButton Variant="Variant.Text" Color="Color.Primary"
OnClick="@(() => NavigateToDetails(evt.Id))">
View Details
</MudButton>
</MudCardActions>
</MudCard>
</MudItem>
}
</MudGrid>
}
</MudContainer>
@code {
private List<EventListDto>? _events;
protected override async Task OnInitializedAsync()
{
_events = await Http.GetFromJsonAsync<List<EventListDto>>("api/v1/events");
}
private void NavigateToDetails(Guid id)
{
NavigationManager.NavigateTo($"/events/{id}");
}
}
MudBlazor Grid System
<MudGrid>
<MudItem xs="12" sm="6" md="4" lg="3">
<!-- Full width on mobile, half on tablet, 1/3 on desktop, 1/4 on large -->
</MudItem>
</MudGrid>
Breakpoints:
xs- Extra small (mobile)sm- Small (tablet portrait)md- Medium (tablet landscape)lg- Large (desktop)xl- Extra large
Component Parameters
@* Parent Component *@
<EventCard Event="@selectedEvent" OnDelete="HandleDelete" />
@* Child Component: EventCard.razor *@
<MudCard>
<MudCardContent>
<MudText>@Event.Title</MudText>
</MudCardContent>
<MudCardActions>
<MudButton OnClick="DeleteClicked" Color="Color.Error">Delete</MudButton>
</MudCardActions>
</MudCard>
@code {
[Parameter]
public EventDto Event { get; set; } = null!;
[Parameter]
public EventCallback<Guid> OnDelete { get; set; }
private async Task DeleteClicked()
{
await OnDelete.InvokeAsync(Event.Id);
}
}
Dependency Injection
@inject IMediator Mediator
@inject ISnackbar Snackbar
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthStateProvider
@inject IDialogService DialogService
@code {
protected override async Task OnInitializedAsync()
{
// Use injected services
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
}
}
Render Modes
@* Interactive Auto (project default) *@
@rendermode InteractiveAuto
@* Interactive Server only *@
@rendermode InteractiveServer
@* Interactive WebAssembly only *@
@rendermode InteractiveWebAssembly
@* Static Server Rendering (no interactivity) *@
@* No @rendermode directive *@
β Do's
- β
DO use
@rendermode="InteractiveAuto"(project default) - β DO use MudBlazor components over custom HTML
- β
DO use
[Parameter]for component inputs - β
DO use
EventCallback<T>for child β parent communication - β
DO use
@injectfor dependency injection - β
DO use
OnInitializedAsyncfor async initialization - β
DO use
MudGrid/MudItemfor responsive layouts - β
DO use
ISnackbarfor notifications (not JavaScript alert) - β
DO use
StateHasChanged()when updating from non-UI events - β
DO implement
IDisposablefor event cleanup
β Don'ts
- β DON'T use raw HTML when MudBlazor component exists
- β DON'T use JavaScript interop for what MudBlazor provides
- β DON'T forget
@rendermodeon interactive components - β DON'T use
[Parameter]properties without{ get; set; } - β DON'T call
StateHasChanged()unnecessarily (impacts performance) - β DON'T access HttpContext in WASM components (server only)
- β DON'T use
OnAfterRenderfor data fetching (useOnInitializedAsync)
π¨ Common MudBlazor Components
MudButton
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="HandleClick">
Click Me
</MudButton>
MudTextField
<MudTextField @bind-Value="title" Label="Event Title" Required="true" />
MudSelect
<MudSelect @bind-Value="selectedStatus" Label="Status">
@foreach (var status in statuses)
{
<MudSelectItem Value="@status">@status.Name</MudSelectItem>
}
</MudSelect>
MudDialog
<MudDialog>
<DialogContent>
<MudText>Are you sure you want to delete this event?</MudText>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Error" Variant="Variant.Filled" OnClick="Confirm">Delete</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
void Cancel() => MudDialog.Cancel();
void Confirm() => MudDialog.Close(DialogResult.Ok(true));
}
MudTable
<MudTable Items="@events" Hover="true" Breakpoint="Breakpoint.Sm">
<HeaderContent>
<MudTh>Title</MudTh>
<MudTh>Date</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Title">@context.Title</MudTd>
<MudTd DataLabel="Date">@context.StartDate.ToShortDateString()</MudTd>
<MudTd DataLabel="Actions">
<MudIconButton Icon="@Icons.Material.Filled.Edit" OnClick="@(() => Edit(context.Id))" />
</MudTd>
</RowTemplate>
</MudTable>
π Component Lifecycle
Constructor
β
SetParametersAsync
β
OnInitialized / OnInitializedAsync β Data fetching here
β
OnParametersSet / OnParametersSetAsync
β
BuildRenderTree (first render)
β
OnAfterRender / OnAfterRenderAsync(firstRender: true) β JS interop here
β
[Parameters changed? β OnParametersSet again]
β
[StateHasChanged called? β Re-render]
β
OnAfterRender / OnAfterRenderAsync(firstRender: false)
β
Dispose (if IDisposable)
π ISLAMU Event Specific Patterns
Theme Management (Dark/Light)
@* App.razor pattern *@
@inject IHttpContextAccessor HttpContextAccessor
@code {
var theme = HttpContextAccessor.HttpContext?.Request.Cookies["theme"];
var isDark = theme == "dark";
}
<CascadingValue Value="isDark" Name="InitialTheme">
<Routes @rendermode="InteractiveAuto" />
</CascadingValue>
Authentication State
<CascadingAuthenticationState>
<AuthorizeView>
<Authorized>
<MudText>Welcome, @context.User.Identity?.Name!</MudText>
</Authorized>
<NotAuthorized>
<MudButton Href="/login">Login</MudButton>
</NotAuthorized>
</AuthorizeView>
</CascadingAuthenticationState>
Global Imports (_Imports.razor)
@using MudBlazor
@using MudBlazor.Services
@using Explore.Blazor
@using Explore.Blazor.Client
@using Microsoft.AspNetCore.Components.Authorization
π Deep Dive
For comprehensive guidance:
- Component Structure: component-structure.md
- MudBlazor Components: mudblazor-components.md
- State Management: state-management.md
- Render Modes: render-modes.md
- Common Patterns: common-patterns.md
Related Skills:
clean-architecture-rules- Ensures components are in correct layercqrs-mediatr-guidelines- MediatR usage from Blazorbackend-dev-guidelines- API integration
Enforcement Level: π‘ SUGGEST (Provides guidance, doesn't block)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
riot-games
Manage Riot Games account, track stats across League, Valorant, and more
parcel
Provides comprehensive guidance for Parcel bundler including zero-configuration setup, asset handling, hot module replacement, and production builds. Use when the user asks about Parcel, needs to set up a build tool quickly, or work with Parcel's automatic configuration.
bbs
Manage issues with The Fold's CAS-native BBS (Bulletin Board System). Use for creating, updating, searching, and tracking issues. Invoke when the user wants to create tickets, find work, check issue status, or manage dependencies.
jito-bundles-and-priority-fees
Master Jito bundles for MEV protection and priority fee optimization on Solana - bundle submission, tip strategies, and transaction landing. Use for trading bots, high-priority transactions, and MEV-aware applications.
observability-monitoring-monitor-setup
You are a monitoring and observability expert specializing in implementing comprehensive monitoring solutions. Set up metrics collection, distributed tracing, log aggregation, and create insightful da
makefile-review
Didn't find tool you were looking for?