Skip to content

Commit

Permalink
Add BitzArt.Flux.MudBlazor package (#27)
Browse files Browse the repository at this point in the history
* Add mudblazor pkg

* Sample app to test against

* Data Provider

* Fixes

* Improve reset code readability

* Comments for readability

* Inline documentation

* Align books grid toolbar

---------

Co-authored-by: Vladimir Seldemirov <ligowsky.dev@gmail.com>
  • Loading branch information
YuriyDurov and ligowsky authored Jul 24, 2024
1 parent d7ae3a7 commit f72f607
Show file tree
Hide file tree
Showing 42 changed files with 1,195 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/Publish Flux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ jobs:
dotnet nuget push BitzArt.Flux.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
dotnet nuget push BitzArt.Flux.REST.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
dotnet nuget push BitzArt.Flux.Json.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
dotnet nuget push BitzArt.Flux.MudBlazor.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
38 changes: 36 additions & 2 deletions BitzArt.Flux.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{83E6C7
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Flux.SampleApp", "sample\BitzArt.Flux.SampleApp\BitzArt.Flux.SampleApp.csproj", "{2D85CE63-7FB6-4D97-81EF-44351A94A883}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.Flux.Json", "src\BitzArt.Flux.Json\BitzArt.Flux.Json.csproj", "{72FE978D-615D-49AF-B69A-4D676EA7254F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Flux.Json", "src\BitzArt.Flux.Json\BitzArt.Flux.Json.csproj", "{72FE978D-615D-49AF-B69A-4D676EA7254F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.Flux.Json.Tests", "tests\BitzArt.Flux.Json.Tests\BitzArt.Flux.Json.Tests.csproj", "{2ED3365D-9DC2-4177-866F-46D1A15CBF61}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Flux.Json.Tests", "tests\BitzArt.Flux.Json.Tests\BitzArt.Flux.Json.Tests.csproj", "{2ED3365D-9DC2-4177-866F-46D1A15CBF61}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MudBlazor", "MudBlazor", "{FB04F142-5BDC-4B3A-9EFF-AFE14F9A7014}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitzArt.Flux.MudBlazor", "src\MudBlazor\BitzArt.Flux.MudBlazor\BitzArt.Flux.MudBlazor.csproj", "{AB6F442A-B032-41A0-955D-467F66CECD53}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MudBlazor", "MudBlazor", "{0BA6ECD8-3FF5-4E88-8C65-F169F184FE33}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MudBlazor.SampleApp.Shared", "sample\MudBlazor\MudBlazor.SampleApp.Shared\MudBlazor.SampleApp.Shared.csproj", "{F2A4D102-0354-4D03-8D59-8953C8A6056A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MudBlazor.SampleApp", "sample\MudBlazor\MudBlazor.SampleApp\MudBlazor.SampleApp.csproj", "{EFCA3026-BF48-46F3-BAF4-9B6A5DC39A0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MudBlazor.SampleApp.Client", "sample\MudBlazor\MudBlazor.SampleApp.Client\MudBlazor.SampleApp.Client.csproj", "{1D0CBDFE-7989-40B5-AFED-92D1BA64C36B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -68,6 +80,22 @@ Global
{2ED3365D-9DC2-4177-866F-46D1A15CBF61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2ED3365D-9DC2-4177-866F-46D1A15CBF61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2ED3365D-9DC2-4177-866F-46D1A15CBF61}.Release|Any CPU.Build.0 = Release|Any CPU
{AB6F442A-B032-41A0-955D-467F66CECD53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB6F442A-B032-41A0-955D-467F66CECD53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB6F442A-B032-41A0-955D-467F66CECD53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB6F442A-B032-41A0-955D-467F66CECD53}.Release|Any CPU.Build.0 = Release|Any CPU
{F2A4D102-0354-4D03-8D59-8953C8A6056A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2A4D102-0354-4D03-8D59-8953C8A6056A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2A4D102-0354-4D03-8D59-8953C8A6056A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2A4D102-0354-4D03-8D59-8953C8A6056A}.Release|Any CPU.Build.0 = Release|Any CPU
{EFCA3026-BF48-46F3-BAF4-9B6A5DC39A0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFCA3026-BF48-46F3-BAF4-9B6A5DC39A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFCA3026-BF48-46F3-BAF4-9B6A5DC39A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFCA3026-BF48-46F3-BAF4-9B6A5DC39A0F}.Release|Any CPU.Build.0 = Release|Any CPU
{1D0CBDFE-7989-40B5-AFED-92D1BA64C36B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D0CBDFE-7989-40B5-AFED-92D1BA64C36B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D0CBDFE-7989-40B5-AFED-92D1BA64C36B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D0CBDFE-7989-40B5-AFED-92D1BA64C36B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -81,6 +109,12 @@ Global
{2D85CE63-7FB6-4D97-81EF-44351A94A883} = {83E6C753-C4C4-4C4E-8627-E9077F557159}
{72FE978D-615D-49AF-B69A-4D676EA7254F} = {A0FAE66D-5574-463E-8723-E28ECEE565EE}
{2ED3365D-9DC2-4177-866F-46D1A15CBF61} = {A3976FBB-F37A-4468-955D-8B2FCC79ACD0}
{FB04F142-5BDC-4B3A-9EFF-AFE14F9A7014} = {A0FAE66D-5574-463E-8723-E28ECEE565EE}
{AB6F442A-B032-41A0-955D-467F66CECD53} = {FB04F142-5BDC-4B3A-9EFF-AFE14F9A7014}
{0BA6ECD8-3FF5-4E88-8C65-F169F184FE33} = {83E6C753-C4C4-4C4E-8627-E9077F557159}
{F2A4D102-0354-4D03-8D59-8953C8A6056A} = {0BA6ECD8-3FF5-4E88-8C65-F169F184FE33}
{EFCA3026-BF48-46F3-BAF4-9B6A5DC39A0F} = {0BA6ECD8-3FF5-4E88-8C65-F169F184FE33}
{1D0CBDFE-7989-40B5-AFED-92D1BA64C36B} = {0BA6ECD8-3FF5-4E88-8C65-F169F184FE33}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {251D5A13-6C1B-4B0D-A6F5-3B95FF4C0F54}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
104 changes: 104 additions & 0 deletions sample/MudBlazor/MudBlazor.SampleApp.Client/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
@inherits LayoutComponentBase

<MudThemeProvider Theme="@_theme" IsDarkMode="_isDarkMode" />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />
<MudLayout>
<MudAppBar Elevation="1">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudText Typo="Typo.h5" Class="ml-3">Application</MudText>
<MudSpacer />
<MudIconButton Icon="@(DarkLightModeButtonIcon)" Color="Color.Inherit" OnClick="@DarkModeToggle" />
<MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End" />
</MudAppBar>
<MudDrawer @bind-Open="_drawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
<NavMenu />
</MudDrawer>
<MudMainContent Class="mt-16 pa-4">
@Body
</MudMainContent>
</MudLayout>


<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

@code {
private bool _drawerOpen = true;
private bool _isDarkMode = true;
private MudTheme? _theme = null;

protected override void OnInitialized()
{
base.OnInitialized();

_theme = new()
{
PaletteLight = _lightPalette,
PaletteDark = _darkPalette,
LayoutProperties = new LayoutProperties()
};
}


private void DrawerToggle()
{
_drawerOpen = !_drawerOpen;
}

private void DarkModeToggle()
{
_isDarkMode = !_isDarkMode;
}

private readonly PaletteLight _lightPalette = new()
{
Black = "#110e2d",
AppbarText = "#424242",
AppbarBackground = "rgba(255,255,255,0.8)",
DrawerBackground = "#ffffff",
GrayLight = "#e8e8e8",
GrayLighter = "#f9f9f9",
};

private readonly PaletteDark _darkPalette = new()
{
Primary = "#7e6fff",
Surface = "#1e1e2d",
Background = "#1a1a27",
BackgroundGray = "#151521",
AppbarText = "#92929f",
AppbarBackground = "rgba(26,26,39,0.8)",
DrawerBackground = "#1a1a27",
ActionDefault = "#74718e",
ActionDisabled = "#9999994d",
ActionDisabledBackground = "#605f6d4d",
TextPrimary = "#b2b0bf",
TextSecondary = "#92929f",
TextDisabled = "#ffffff33",
DrawerIcon = "#92929f",
DrawerText = "#92929f",
GrayLight = "#2a2833",
GrayLighter = "#1e1e2d",
Info = "#4a86ff",
Success = "#3dcb6c",
Warning = "#ffb545",
Error = "#ff3f5f",
LinesDefault = "#33323e",
TableLines = "#33323e",
Divider = "#292838",
OverlayLight = "#1e1e2d80",
};

public string DarkLightModeButtonIcon => _isDarkMode switch
{
true => Icons.Material.Rounded.AutoMode,
false => Icons.Material.Outlined.DarkMode,
};
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<MudNavMenu>
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
<MudNavLink Href="books" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Book">Books</MudNavLink>

</MudNavMenu>


Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
<RootNamespace>MudBlazor.SampleApp.Client</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.*" />
<PackageReference Include="MudBlazor" Version="7.4.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MudBlazor.SampleApp.Shared\MudBlazor.SampleApp.Shared.csproj" />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions sample/MudBlazor/MudBlazor.SampleApp.Client/Pages/BooksPage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@page "/books"

@if (_initialized)
{
<div class="books-page">
<MudBlazor.MudTable
@ref="BooksDataProvider.Table"
T="Book"
ServerData="BooksDataProvider.Data"
>
<ToolBarContent>
<MudGrid Spacing="4" Class="pt-2">
<MudItem xs="12" sm="12" md="6" Class="align-content-center">
<MudText Typo="Typo.h4">Books</MudText>
</MudItem>

<MudItem xs="12" sm="6" md="3" Class="align-content-center">
<MudSelect
T="Author"
Placeholder="Author"
Variant="Variant.Outlined"
Margin="Margin.Dense"
AnchorOrigin="Origin.BottomCenter"
ValueChanged="OnAuthorSelectedAsync"
Class="pt-0">

<MudSelectItem Value="(Author)null!">Select Author</MudSelectItem>
@foreach (var author in _authors)
{
<MudSelectItem Value="@author">@author.Name</MudSelectItem>
}

</MudSelect>
</MudItem>

<MudItem xs="12" sm="6" md="3" Class="align-content-center">
<MudTextField
T="string"
DebounceInterval="300"
OnDebounceIntervalElapsed="OnSearchAsync"
Placeholder="Search"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Medium">
</MudTextField>
</MudItem>
</MudGrid>
</ToolBarContent>

<HeaderContent>
<MudTh>
<MudTableSortLabel T="Book" SortLabel="id">
ID
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel T="Book" SortLabel="author">
Author
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel T="Book" SortLabel="title">
Title
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel T="Book" SortLabel="publish">
Publish Year
</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="ID">
@context.Id
</MudTd>
<MudTd DataLabel="Author">
@_authors.FirstOrDefault(x => x.Id == context.AuthorId)?.Name
</MudTd>
<MudTd DataLabel="Title">
@context.Title
</MudTd>
<MudTd DataLabel="Publish Year">
@context.PublishYearDisplay
</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[] { 5 }" HideRowsPerPage="true" />
</PagerContent>
</MudBlazor.MudTable>
</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using BitzArt.Flux;
using BitzArt.Flux.MudBlazor;
using Microsoft.AspNetCore.Components;
using System.Web;

namespace MudBlazor.SampleApp.Client.Pages;

public partial class BooksPage : ComponentBase
{
private IEnumerable<Author> _authors = null!;
private Author? _selectedAuthor;

private string? _search;

[Inject] private IFluxSetContext<Author> Authors { get; set; } = null!;
[Inject] private IFluxSetDataProvider<Book> BooksDataProvider { get; set; } = null!;

private bool _initialized = false;

protected override async Task OnInitializedAsync()
{
BooksDataProvider.GetParameters = GetBooksParameters;

await base.OnInitializedAsync();
_authors = await Authors.GetAllAsync();
_initialized = true;

await InvokeAsync(StateHasChanged);
}

private object[] GetBooksParameters(TableState state)
{
var query = HttpUtility.ParseQueryString(string.Empty);

if (_selectedAuthor is not null) query["authorId"] = _selectedAuthor.Id.ToString();
if (!string.IsNullOrWhiteSpace(state.SortLabel)) query["order"] = state.SortLabel;
if (state.SortDirection == SortDirection.Descending) query["desc"] = "true";
if (!string.IsNullOrWhiteSpace(_search)) query["search"] = _search;

var queryString = query.Count > 0 ? $"?{query}" : string.Empty;

return [queryString];
}

private async Task OnAuthorSelectedAsync(Author author)
{
_selectedAuthor = author;
await BooksDataProvider.ResetAndReloadAsync();
}

private async Task OnSearchAsync(string value)
{
_search = value;
await BooksDataProvider.ResetAndReloadAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.books-page ::deep .mud-table .mud-table-toolbar {
height: inherit !important;
padding-inline-start: 1rem !important;
padding-inline-end: 1rem !important;
}

.books-page ::deep .mud-table .mud-table-smalldevices-sortselect {
padding-top: 1rem !important;
}
10 changes: 10 additions & 0 deletions sample/MudBlazor/MudBlazor.SampleApp.Client/Pages/HomePage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@page "/"

<PageTitle>Home</PageTitle>

<MudText Typo="Typo.h3" GutterBottom="true">Hello, world!</MudText>

<MudText Typo="Typo.body2">
This sample application shows how you can use Flux with MudBlazor. <br/>
Navigate to the <MudLink Href="/books">Books</MudLink> page to see it in action.
</MudText>
Loading

0 comments on commit f72f607

Please sign in to comment.