Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/atc-net/atc-blazor

A common set of Blazor libraries
https://github.com/atc-net/atc-blazor

blazor components-library

Last synced: 1 day ago
JSON representation

A common set of Blazor libraries

Awesome Lists containing this project

README

        

[![NuGet Version](https://img.shields.io/nuget/v/Atc.Blazor.ColorThemePreference.svg?logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/Atc.Blazor.ColorThemePreference)

# Atc.Blazor

This repository contains packages with components for Blazor application:

| Package | Description |
|---|---|
| Atc.Blazor.ColorThemePreference | A library for detecting the user preferred color theme |

## Requirements

* [.NET 8 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)

## Get started Atc.Blazor

### Installation for Atc.Blazor

```powershell
Install-Package Atc.Blazor
```

### How to Use `NavigationManager.TryGetQueryString`

```csharp
int myInt = 0;

NavigationManager.TryGetQueryString("myKey", out var myInt)
```

### How to Use `QueryStringParameterAttribute` and `SetPropertiesWithDecoratedQueryStringParameterFromQueryString`

```csharp
@page "/"
@inject NavigationManager NavigationManager

My age is: @Age

@code
{
[QueryStringParameter]
public int Age { get; set; }

public override Task SetParametersAsync(ParameterView parameters) // Overload from Blazor components lifecycle
{
this.SetPropertiesWithDecoratedQueryStringParameterFromQueryString(NavigationManager); // Bind from url-qyery-parameter 'age' to property 'Age'
return base.SetParametersAsync(parameters);
}
}
```

```csharp
@page "/"
@inject NavigationManager NavigationManager

My age is: @Age

@code
{
[QueryStringParameter("myAge")]
public int Age { get; set; }

public override Task SetParametersAsync(ParameterView parameters) // Overload from Blazor components lifecycle
{
this.SetPropertiesWithDecoratedQueryStringParameterFromQueryString(NavigationManager); // Bind from url-qyery-parameter 'myAge' to property 'Age'
return base.SetParametersAsync(parameters);
}
}
```

### How to Use `QueryStringParameterAttribute` and `UpdateQueryStringFromPropertiesWithDecoratedQueryStringParameter`

```csharp
@page "/"
@inject NavigationManager NavigationManager

Update url

@code
{
[QueryStringParameter]
public int Age { get; set; }

public void UpdateQueryStringWithAge(int age)
{
this.Age = age;
this.UpdateQueryString(NavigationManager);
}
}
```

## Get started Atc.Blazor.ColorThemePreference

### Installation for Atc.Blazor.ColorThemePreference

```powershell
Install-Package Atc.Blazor.ColorThemePreference
```

### How to Setup

Modify `Program.cs` by adding to the service builder:

```csharp
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add("#app");
builder.RootComponents.Add("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddColorThemePreferenceDetector(); // Require package: Atc.Blazor.ColorThemePreference

await builder.Build().RunAsync();
```

Modify `index.html` by adding:

```html

```

### How to Use

```csharp
@inject IColorThemePreferenceDetector colorThemePreferenceDetector;

Use Light-Mode: @useLightMode


Use Dark-Mode: @useDarkMode

@code
{
private bool useLightMode;
private bool useDarkMode;

protected override async Task OnInitializedAsync()
{
useLightMode = await colorThemePreferenceDetector.UseLightMode();
useDarkMode = await colorThemePreferenceDetector.UseDarkMode();

await base.OnInitializedAsync();
}
}
```

## How to contribute

[Contribution Guidelines](https://atc-net.github.io/introduction/about-atc#how-to-contribute)

[Coding Guidelines](https://atc-net.github.io/introduction/about-atc#coding-guidelines)