Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a0d510
commit 74e54f8
Showing
6 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
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
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,28 @@ | ||
namespace BlazorApp.Services | ||
{ | ||
public interface IThemeService | ||
{ | ||
public const string DefaultTheme = "Default"; | ||
public static readonly string[] SupportedThemeList = new[] | ||
{ | ||
DefaultTheme, | ||
"Cerulean", | ||
"Cosmo", | ||
"Cyborg", | ||
"Darkly", | ||
"Flatly", | ||
}; | ||
string CurrentTheme { get; } | ||
Task ToggleTheme(string themeName); | ||
} | ||
public class ThemeService : IThemeService | ||
{ | ||
public string CurrentTheme { get; private set; } = IThemeService.DefaultTheme; | ||
|
||
public async Task ToggleTheme(string themeName) | ||
{ | ||
CurrentTheme = themeName; | ||
await Task.CompletedTask; | ||
} | ||
} | ||
} |
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,17 +1,47 @@ | ||
@inherits LayoutComponentBase | ||
|
||
@using BlazorApp.Services | ||
|
||
@inject IThemeService Theme | ||
@inject IJSRuntime JS | ||
|
||
<div class="page"> | ||
<div class="sidebar"> | ||
<NavMenu /> | ||
</div> | ||
|
||
<main> | ||
<div class="top-row px-4"> | ||
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a> | ||
<div class="dropdown"> | ||
<button class="btn btn-secondary btn-sm me-2" type="button" id="dropdownMenuButtonTheme" data-bs-toggle="dropdown" aria-expanded="false"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-palette me-1" viewBox="0 0 16 16"> | ||
<path d="M8 5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zm4 3a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zM5.5 7a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm.5 6a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3z"/> | ||
<path d="M16 8c0 3.15-1.866 2.585-3.567 2.07C11.42 9.763 10.465 9.473 10 10c-.603.683-.475 1.819-.351 2.92C9.826 14.495 9.996 16 8 16a8 8 0 1 1 8-8zm-8 7c.611 0 .654-.171.655-.176.078-.146.124-.464.07-1.119-.014-.168-.037-.37-.061-.591-.052-.464-.112-1.005-.118-1.462-.01-.707.083-1.61.704-2.314.369-.417.845-.578 1.272-.618.404-.038.812.026 1.16.104.343.077.702.186 1.025.284l.028.008c.346.105.658.199.953.266.653.148.904.083.991.024C14.717 9.38 15 9.161 15 8a7 7 0 1 0-7 7z"/> | ||
</svg>@Theme.CurrentTheme | ||
</button> | ||
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButtonTheme"> | ||
@foreach (var themeName in IThemeService.SupportedThemeList) | ||
{ | ||
<li class="dropdown-item@(themeName == Theme.CurrentTheme ? " active" : "")" | ||
@onclick=@(async () => await ToggleTheme(themeName))>@themeName</li> | ||
} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<article class="content px-4"> | ||
@Body | ||
</article> | ||
</main> | ||
</div> | ||
|
||
@code { | ||
async Task ToggleTheme(string themeName) | ||
{ | ||
if (Theme.CurrentTheme != themeName) | ||
{ | ||
await Theme.ToggleTheme(themeName); | ||
await JS.InvokeVoidAsync("ToggleTheme", themeName); | ||
} | ||
} | ||
}} |
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
7 changes: 7 additions & 0 deletions
7
BlazorBootswatchTheme/BlazorApp/wwwroot/js/bootstrap.bundle.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
BlazorBootswatchTheme/BlazorApp/wwwroot/js/bootstrap.bundle.min.js.map
Large diffs are not rendered by default.
Oops, something went wrong.