### ClearSettings Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example demonstrating the use of ILocalStorageSettingsService.ClearSettings to reset all user preferences to their default values.
```csharp
await LocalStorageSettings.ClearSettings();
```
--------------------------------
### HUIAppBar with Actions Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-core.md
Provides an example of HUIAppBar, including how to set logo sources and add action buttons like help and settings to the toolbar.
```razor
@code {
private void OnMenuClick()
{
// Handle menu toggle
}
}
```
--------------------------------
### Register TitleService with Configuration
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of registering the TitleService with dependency injection in Program.cs, using configuration settings from appsettings.json. This is part of the UI configuration setup.
```csharp
// In Program.cs
services.Configure(configuration.GetSection("HedinUI"));
```
--------------------------------
### ResetAsync Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of using IHUISettingsService.ResetAsync to reset all application settings to defaults. It shows how to bind this action to a button click event.
```csharp
@inject IHUISettingsService HUISettings
@code {
private async Task ResetSettings()
{
await HUISettings.ResetAsync();
}
}
```
--------------------------------
### Tooltip Configuration Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/configuration.md
Shows how to apply a HUITooltip to a MudIconButton, with a note on the default instant display duration.
```razor
```
--------------------------------
### GetSettings Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of using the ILocalStorageSettingsService.GetSettings method to retrieve and use user settings, such as the current theme. It injects the service and calls GetSettings.
```csharp
@inject ILocalStorageSettingsService LocalStorageSettings
@code {
protected override async Task OnInitializedAsync()
{
var settings = await LocalStorageSettings.GetSettings();
CurrentTheme = settings.Theme;
}
}
```
--------------------------------
### Stored Settings Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/configuration.md
Demonstrates the structure of stored settings for UI components, including table configurations and theme preferences.
```json
{
"TableSettings": [
{
"TableId": "users-grid",
"ColumnOrder": {
"Name": 0,
"Email": 1,
"Created": 2
},
"ColumnVisibility": {
"Name": false,
"Email": false,
"Created": false
}
}
],
"Theme": 1 // 0 = Light, 1 = Dark
}
```
--------------------------------
### HUIStatusChip Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-content.md
Demonstrates the usage of HUIStatusChip with different severities and icons to display status information.
```razor
```
--------------------------------
### HUIDataGrid Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-data.md
Example of how to use the HUIDataGrid component with server-side data loading, search, and column configuration.
```razor
@page "/users"
@inject HttpClient Http
@code {
private HUIDataGrid grid;
private bool isLoading;
private string searchTerm = "";
private async Task> LoadData(GridState state)
{
isLoading = true;
try
{
var response = await Http.PostAsJsonAsync("api/users/grid", new {
Page = state.Page,
PageSize = state.PageSize,
SortBy = state.SortDefinitions?.FirstOrDefault()?.SortBy,
Search = searchTerm
});
var result = await response.Content.ReadAsAsync>();
return result;
}
finally
{
isLoading = false;
}
}
private class UserModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public DateTime CreatedDate { get; set; }
}
}
```
--------------------------------
### SetSettings Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of how to modify and persist user settings using ILocalStorageSettingsService.SetSettings. It first retrieves settings, modifies a property (Theme), and then saves the updated settings.
```csharp
var settings = await LocalStorageSettings.GetSettings();
settings.Theme = ThemeMode.Light;
await LocalStorageSettings.SetSettings(settings);
```
--------------------------------
### Basic Setup in Program.cs
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/README.md
Configure your Blazor application to use Hedin.UI services. This involves registering the UI configuration with the service collection.
```csharp
using Hedin.UI;
var builder = WebAssemblyBuilder.CreateDefault(args);
builder.RootComponents.Add("#app");
// Register Hedin.UI services
builder.Services.AddUIConfiguration(builder.Configuration);
await builder.Build().RunAsync();
```
--------------------------------
### HUIButton Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-core.md
Demonstrates the usage of HUIButton, showing how to display a loading indicator and disable the button when an operation is in progress.
```razor
Save Changes
@code {
private bool isSaving;
private async Task HandleSave()
{
isSaving = true;
await ApiClient.SaveUser(user);
isSaving = false;
}
}
```
--------------------------------
### HUINavMenu Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-content.md
Demonstrates how to use the HUINavMenu component, either by auto-generating menu items from assemblies or by creating them manually.
```razor
@inject IHUIPageHelper PageHelper
@code {
private List menuItems = new();
protected override async Task OnInitializedAsync()
{
// Auto-generate menu from components
var appAssembly = typeof(Program).Assembly;
menuItems = await PageHelper.GetMenuItems(new[] { appAssembly });
// Or create manually
menuItems = new()
{
new HUIMenuItem(
displayName: "Dashboard",
url: "/dashboard",
parentUrl: null,
order: 1,
icon: Icons.Material.Filled.Dashboard
),
new HUIMenuItem(
displayName: "Users",
url: "/users",
parentUrl: null,
order: 2,
icon: Icons.Material.Filled.People,
policy: "AdminOnly"
),
new HUIMenuItem(
displayName: "Add User",
url: "/users/add",
parentUrl: "/users",
order: 1
)
};
}
}
```
--------------------------------
### HUITooltip Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-content.md
Shows how to use the HUITooltip component to add a tooltip to a MudIconButton.
```razor
```
--------------------------------
### StatefulComponentBase Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of using the generic StatefulComponentBase to manage state for a component. The Model property is automatically managed.
```csharp
@page "/filters"
@inherits StatefulComponentBase
@code {
private class FilterModel
{
public string SearchTerm { get; set; }
public bool Active { get; set; }
}
private void ApplyFilters()
{
Model.SearchTerm = searchInput;
Model.Active = activeToggle;
}
}
```
--------------------------------
### GetMenuItems Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of how to use the IHUIPageHelper.GetMenuItems method to retrieve menu items for the application. It injects the service and calls GetMenuItems with the application's assembly.
```csharp
@inject IHUIPageHelper PageHelper
@code {
private List menuItems;
protected override async Task OnInitializedAsync()
{
var appAssembly = typeof(Program).Assembly;
menuItems = await PageHelper.GetMenuItems(new[] { appAssembly });
}
}
```
--------------------------------
### HUIThemeProvider Theme Management Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-core.md
Illustrates how to wrap the application with HUIThemeProvider to manage theme switching and persistence, ensuring consistent theming across components.
```razor
@Body
```
--------------------------------
### OrderModel Implementation of IHUIGridItem
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/types.md
Example implementation of the IHUIGridItem interface. Demonstrates how to map order status to severity levels for row styling in data grids.
```csharp
public class OrderModel : IHUIGridItem
{
public int Id { get; set; }
public string OrderNumber { get; set; }
public OrderStatus Status { get; set; }
public Severity Severity => Status switch
{
OrderStatus.Completed => Severity.Success,
OrderStatus.Pending => Severity.Info,
OrderStatus.Cancelled => Severity.Error,
_ => Severity.Normal
};
}
```
--------------------------------
### Install Hedin.UI Package
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/README.md
Add the Hedin.UI NuGet package to your Blazor project.
```bash
dotnet add package Hedin.UI
```
--------------------------------
### HUIBreadcrumbs Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-content.md
Shows how to implement HUIBreadcrumbs with a list of BreadcrumbItem objects to provide navigation context.
```razor
```
--------------------------------
### HUIChatLine Conversation Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/types.md
Example of creating a list of HUIChatLine objects to represent a conversation. Used with HUIChatPanel to display chat messages.
```csharp
var conversation = new List
{
new HUIChatLine { Role = HUIChatRole.User, Text = "Hello", Timestamp = DateTime.Now },
new HUIChatLine { Role = HUIChatRole.Assistant, Text = "Hi there!", Timestamp = DateTime.Now }
};
```
--------------------------------
### Page Content with HUIPage and HUIPageTable
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/README.md
Structure a page using `HUIPage` for layout and `HUIPageTable` for displaying data. This example shows how to define columns for a product list and handle a button click to open an add dialog.
```razor
@inherits ProductsPage
@code {
private List products;
protected override async Task OnInitializedAsync()
{
products = await ApiClient.GetProducts();
}
private async Task OpenAddDialog()
{
// Open add product dialog
}
}
```
--------------------------------
### OrderModel with Severity Property
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-data.md
Example C# model implementing IHUIGridItem, demonstrating how to derive a MudBlazor Severity level from an OrderStatus.
```csharp
public class OrderModel : IHUIGridItem
{
public int Id { get; set; }
public string OrderNumber { get; set; }
public DateTime OrderDate { get; set; }
public Severity Severity
{
get => Status switch
{
OrderStatus.Completed => Severity.Success,
OrderStatus.Pending => Severity.Info,
OrderStatus.Cancelled => Severity.Error,
_ => Severity.Normal
};
}
}
```
--------------------------------
### Register Hedin.UI Services Extension Method
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of registering all Hedin.UI services in Program.cs using the AddUIConfiguration extension method. This simplifies service registration for the UI components.
```csharp
// In Program.cs
builder.Services.AddUIConfiguration(builder.Configuration);
```
--------------------------------
### HUIMainContainer Layout Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-core.md
Shows how to structure an application layout using HUIMainContainer, including slots for app bar, navigation menu, and main content.
```razor
@Body
```
--------------------------------
### Configure ShowDevEnvWarning in appsettings.json
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/services.md
Example of how to configure the ShowDevEnvWarning setting in the application's appsettings.json file. This setting is part of the HedinUI configuration section.
```json
// In appsettings.json
{
"HedinUI": {
"AppTitle": "My Application",
"ShowDevEnvWarning": true
}
}
```
--------------------------------
### Stateful Component Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/README.md
Shows how to create a stateful component that preserves its model across navigation using StatefulComponentBase. The UserFilterModel is automatically persisted and restored.
```csharp
@page "/users"
@inherits StatefulComponentBase
@code {
private class UserFilterModel
{
public string SearchTerm { get; set; }
public bool ActiveOnly { get; set; }
}
// Model is automatically persisted and restored
}
```
--------------------------------
### HUIPageHelper Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/helpers-extensions.md
Injects the IHUIPageHelper service to retrieve menu items by scanning assemblies. Used for building navigation menus dynamically.
```csharp
@inject IHUIPageHelper PageHelper
@code {
private List menuItems;
protected override async Task OnInitializedAsync()
{
var assembly = typeof(Program).Assembly;
menuItems = await PageHelper.GetMenuItems(new[] { assembly });
}
}
```
--------------------------------
### Register Hedin.UI Services
Source: https://github.com/hedinbil/hedin-ui/blob/main/docs/getting-started.md
Add this to your Program.cs file to register Hedin.UI services. Ensure you have the Hedin.UI NuGet package installed.
```csharp
using Hedin.UI;
builder.Services.AddUIConfiguration(builder.Configuration);
```
--------------------------------
### HUIChatPanel Example Usage
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-content.md
Demonstrates how to use the HUIChatPanel component to display and manage a conversation, including sending messages and handling loading states.
```razor
@code {
private HUIChatPanel chatPanel;
private List messages = new();
private bool isWaitingForResponse;
private async Task HandleSendMessage(string message)
{
messages.Add(new HUIChatLine
{
Role = HUIChatRole.User,
Text = message,
Timestamp = DateTime.Now
});
isWaitingForResponse = true;
var response = await ApiClient.GetAiResponse(message);
messages.Add(new HUIChatLine
{
Role = HUIChatRole.Assistant,
Text = response,
Timestamp = DateTime.Now
});
isWaitingForResponse = false;
}
}
```
--------------------------------
### HUIBlogPost Usage Example
Source: https://github.com/hedinbil/hedin-ui/blob/main/_autodocs/api-reference/components-specialized.md
Demonstrates how to use the HUIBlogPost component to display a blog post with a title, author, date, content, and attachments. Includes handling attachment downloads.
```razor
Today we're excited to announce major new features...