Skip to content

Commit 36af3c4

Browse files
committed
Overhaul ThemeToggler
1 parent 74dc35f commit 36af3c4

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/LinkDotNet.Blog.Web/Features/Home/Components/NavMenu.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</li>
5555

5656
<AccessControl CurrentUri="@currentUri"></AccessControl>
57-
<li><ThemeToggler Class="nav-link"></ThemeToggler></li>
57+
<li class="nav-item d-flex align-items-center justify-content-center"><ThemeToggler Class="nav-link"></ThemeToggler></li>
5858
<li class="d-flex">
5959
<SearchInput SearchEntered="NavigateToSearchPage"></SearchInput>
6060
</li>

src/LinkDotNet.Blog.Web/Features/Home/Components/ThemeToggler.razor

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,41 @@
22
@inject IJSRuntime JSRuntime
33
@inject ILocalStorageService LocalStorageService
44

5-
<span class="@Class theme-toggle" style="cursor: pointer" @onclick="ToggleMode"> Color Mode</span>
5+
<div class="position-relative d-inline-block @Class cursor-pointer" role="button" @onclick="ToggleMode" title="Toggle theme">
6+
7+
@if (currentTheme == "light")
8+
{
9+
<svg xmlns="http://www.w3.org/2000/svg"
10+
width="20"
11+
height="20"
12+
viewBox="0 0 24 24"
13+
fill="none"
14+
stroke="currentColor"
15+
class="text-secondary">
16+
<circle cx="12" cy="12" r="5"/>
17+
<line x1="12" y1="1" x2="12" y2="3"/>
18+
<line x1="12" y1="21" x2="12" y2="23"/>
19+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
20+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
21+
<line x1="1" y1="12" x2="3" y2="12"/>
22+
<line x1="21" y1="12" x2="23" y2="12"/>
23+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
24+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
25+
</svg>
26+
}
27+
else
28+
{
29+
<svg xmlns="http://www.w3.org/2000/svg"
30+
width="20"
31+
height="20"
32+
viewBox="0 0 24 24"
33+
fill="none"
34+
stroke="currentColor"
35+
class="text-white">
36+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
37+
</svg>
38+
}
39+
</div>
640

741
@code {
842
[Parameter]
@@ -22,6 +56,7 @@
2256
: await JSRuntime.InvokeAsync<string>("getCurrentSystemPreference");
2357

2458
await JSRuntime.InvokeVoidAsync("setTheme", currentTheme);
59+
StateHasChanged();
2560
}
2661
}
2762

0 commit comments

Comments
 (0)