Skip to content

Commit

Permalink
Merge branch 'feature/switch-theme-presets'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tux73 committed Jan 6, 2025
2 parents ec6e1dd + 7995510 commit da26ee1
Show file tree
Hide file tree
Showing 7 changed files with 649 additions and 241 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace MudBlazor.ThemeManager.TestApp.MudThemePresets;


public class CustomThemePreset01 : IThemePreset
{
public string NamePreset { get; } = "Arco Service NET";

public MudTheme Theme { get; } = new()
{
PaletteLight = new PaletteLight()
{
Primary = Colors.Brown.Darken3,
Secondary = Colors.Green.Darken2,
AppbarBackground = Colors.Red.Default
},
PaletteDark = new PaletteDark() { Primary = Colors.Blue.Lighten1 },
LayoutProperties = new LayoutProperties() { DrawerWidthLeft = "260px", DrawerWidthRight = "300px" }
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace MudBlazor.ThemeManager.TestApp.MudThemePresets;


public class CustomThemePreset02 : IThemePreset
{
public string NamePreset { get; } = "Test Theme";

public MudTheme Theme { get; } = new()
{
PaletteLight = new PaletteLight()
{
Primary = Colors.Teal.Default,
Secondary = Colors.Green.Accent4,
AppbarBackground = Colors.BlueGray.Default
},
PaletteDark = new PaletteDark() { Primary = Colors.Blue.Lighten1 },
LayoutProperties = new LayoutProperties() { DrawerWidthLeft = "260px", DrawerWidthRight = "300px" }
};
}
56 changes: 46 additions & 10 deletions src/MudBlazor.ThemeManager.TestApp/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,67 +1,103 @@
@inherits LayoutComponentBase
@using MudBlazor.ThemeManager.TestApp.MudThemePresets
@inherits LayoutComponentBase

<MudThemeProvider @ref="@_mudThemeProvider" Theme="_themeManager.Theme" @bind-IsDarkMode="@_isDarkMode" />
<MudThemeProvider @bind-IsDarkMode="@_isDarkMode"
@ref="@_mudThemeProvider"
Theme="_themeManager.Theme" />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />

<MudLayout>
<MudAppBar Elevation="_themeManager.AppBarElevation">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudAppBar Elevation="_themeManager.AppBarElevation" >
<MudIconButton Color="Color.Inherit"
Edge="Edge.Start"
Icon="@Icons.Material.Filled.Menu"
OnClick="@((e) => DrawerToggle())" />
<MudSpacer />
<MudIconButton Icon="@Icons.Material.Filled.DarkMode" Color="Color.Inherit" OnClick="@((e) => DarkModeToggle())" Edge="Edge.End" />
<MudIconButton Color="Color.Inherit"
Edge="Edge.End"
Icon="@Icons.Material.Filled.DarkMode"
OnClick="@((e) => DarkModeToggle())" />
</MudAppBar>
<MudDrawer @bind-Open="_drawerOpen" ClipMode="_themeManager.DrawerClipMode" Elevation="_themeManager.DrawerElevation">
<MudText Typo="Typo.h6" Class="px-4 pt-2">Theme Manager</MudText>
<MudText Typo="Typo.body2" Class="px-4 mud-text-secondary">Test Application</MudText>
<MudDrawer @bind-Open="_drawerOpen"
ClipMode="_themeManager.DrawerClipMode"
Elevation="_themeManager.DrawerElevation" >
<MudText Class="px-4 pt-2"
Typo="Typo.h6" >
Theme Manager
</MudText>
<MudText Class="px-4 mud-text-secondary"
Typo="Typo.body2" >
Test Application
</MudText>
<NavMenu />
</MudDrawer>
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.False" Class="mt-16 px-16">
<MudContainer Class="mt-16 px-16"
MaxWidth="MaxWidth.False" >
@Body
</MudContainer>
</MudMainContent>
<MudThemeManagerButton OnClick="@((e) => OpenThemeManager(true))" />
<MudThemeManager Open="_themeManagerOpen" OpenChanged="OpenThemeManager" Theme="_themeManager" ThemeChanged="UpdateTheme" IsDarkMode="@_isDarkMode" />
<MudThemeManager IsDarkMode="@_isDarkMode"
Open="_themeManagerOpen"
OpenChanged="OpenThemeManager"
Theme="_themeManager"
ThemeChanged="UpdateTheme"
ThemePresets="_themePresets" />
</MudLayout>

@code {
private ThemeManagerTheme _themeManager = new();
private MudThemeProvider _mudThemeProvider;
private IEnumerable<IThemePreset>? _themePresets;

private bool _isDarkMode;
private bool _drawerOpen = true;
private bool _themeManagerOpen;


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


private void OpenThemeManager(bool value)
{
_themeManagerOpen = value;
}


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


private void UpdateTheme(ThemeManagerTheme value)
{
_themeManager = value;
StateHasChanged();
}


protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_isDarkMode = await _mudThemeProvider.GetSystemPreference();
StateHasChanged();
}

await base.OnAfterRenderAsync(firstRender);
}


protected override void OnInitialized()
{
_themePresets = [new CustomThemePreset01(), new CustomThemePreset02()];
}
}
Loading

0 comments on commit da26ee1

Please sign in to comment.