From 35e39ff9796953141c0f050d374133d9f2a82883 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Thu, 23 Apr 2026 15:44:26 +0200 Subject: [PATCH] Add theme selection dropdown and refactor theme handling Introduce a DxComboBox in MainLayout for selecting between multiple themes. Update ThemeState to manage the current theme, provide a list of available themes, and apply the selected theme via a new SetTheme method. Refactor dark mode handling to work with the new theme system, and ensure UI updates on theme or mode changes. --- .../Components/Layout/MainLayout.razor | 7 ++- DbFirst.BlazorWebApp/Services/ThemeState.cs | 52 +++++++++++++------ 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/DbFirst.BlazorWebApp/Components/Layout/MainLayout.razor b/DbFirst.BlazorWebApp/Components/Layout/MainLayout.razor index 014ada8..18bc487 100644 --- a/DbFirst.BlazorWebApp/Components/Layout/MainLayout.razor +++ b/DbFirst.BlazorWebApp/Components/Layout/MainLayout.razor @@ -9,7 +9,12 @@
- + + About
diff --git a/DbFirst.BlazorWebApp/Services/ThemeState.cs b/DbFirst.BlazorWebApp/Services/ThemeState.cs index 2b5bc31..7b72b26 100644 --- a/DbFirst.BlazorWebApp/Services/ThemeState.cs +++ b/DbFirst.BlazorWebApp/Services/ThemeState.cs @@ -12,24 +12,46 @@ public class ThemeState } public bool IsDarkMode { get; private set; } + public string CurrentThemeName { get; private set; } = "Fluent"; + + public static readonly List AvailableThemes = ["Fluent", "BlazingBerry", "Purple", "OfficeWhite", "BootstrapExternal"]; public event Action? OnChange; - public void SetDarkMode(bool isDarkMode) + public void SetTheme(string themeName) { - if (IsDarkMode == isDarkMode) - { - return; - } - - IsDarkMode = isDarkMode; - var theme = Themes.Fluent.Clone(properties => - { - properties.Mode = isDarkMode ? ThemeMode.Dark : ThemeMode.Light; - properties.ApplyToPageElements = true; - }); - - themeChangeService.SetTheme(theme); + if (CurrentThemeName == themeName) return; + CurrentThemeName = themeName; + ApplyTheme(); OnChange?.Invoke(); } -} + + public void SetDarkMode(bool isDarkMode) + { + if (IsDarkMode == isDarkMode) return; + IsDarkMode = isDarkMode; + ApplyTheme(); + OnChange?.Invoke(); + } + + private void ApplyTheme() + { + if (CurrentThemeName == "Fluent") + { + var theme = Themes.Fluent.Clone(properties => + { + properties.Mode = IsDarkMode ? ThemeMode.Dark : ThemeMode.Light; + properties.ApplyToPageElements = true; + }); + themeChangeService.SetTheme(theme); + } + else if (CurrentThemeName == "BlazingBerry") themeChangeService.SetTheme(Themes.BlazingBerry); + else if (CurrentThemeName == "Purple") themeChangeService.SetTheme(Themes.Purple); + else if (CurrentThemeName == "OfficeWhite") themeChangeService.SetTheme(Themes.OfficeWhite); + else if (CurrentThemeName == "BootstrapExternal") themeChangeService.SetTheme(Themes.BootstrapExternal); + else + themeChangeService.SetTheme(Themes.Fluent); + + OnChange?.Invoke(); + } +} \ No newline at end of file