-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/switch-theme-presets'
- Loading branch information
Showing
7 changed files
with
649 additions
and
241 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/MudBlazor.ThemeManager.TestApp/MudThemePresets/CustomThemePreset01.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
}; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/MudBlazor.ThemeManager.TestApp/MudThemePresets/CustomThemePreset02.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
src/MudBlazor.ThemeManager.TestApp/Shared/MainLayout.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()]; | ||
} | ||
} |
Oops, something went wrong.