Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Shared/DarkModeToggle.razor
T
Joseph Doherty 9cff87fe85 docs(comments): strip internal task/milestone/bundle bookkeeping from code comments
Remove project bookkeeping citations from shipped code comments across the
solution: hyphenated task IDs (WP-14, StoreAndForward-025), milestone/task/
issue refs (M3, Task 4, Audit Log #23, #21), Bundle X task-bundle labels,
and C/D/K/S/T phase labels.

Comment text only — no code logic, string/log literals, or XML-doc structure
changed. Genuine descriptions are preserved (only the citation is stripped),
and technical lookalikes are retained (UTF-8, SHA-256, T00:00:00, M365,
UTC-5, pre-C4/pre-C5 schema versions). Flagged by the new CommentChecker
TaskReferenceInComment / TrackingReferenceInComment checks plus targeted
grep passes; full solution builds clean, append-only guard tests pass.
2026-07-07 11:03:26 -04:00

55 lines
1.9 KiB
Plaintext

@inject IJSRuntime JS
@* Dark-mode toggle. Pure JS-interop + localStorage — no DI service and no
server state. The actual theme switch happens in the browser via window.sbTheme
(wwwroot/js/theme.js); this button just drives toggle() and reflects the result.
The page-load default (no-flash) is owned by the inline pre-hydration script in
App.razor, not here. *@
<button type="button"
class="rail-btn sb-theme-toggle"
aria-label="Toggle dark mode"
aria-pressed="@(_isDark ? "true" : "false")"
title="@(_isDark ? "Switch to light mode" : "Switch to dark mode")"
@onclick="ToggleAsync">
<i class="bi @(_isDark ? "bi-sun" : "bi-moon-stars")" aria-hidden="true"></i>
</button>
@code {
/// <summary>Mirrors the browser's current theme so the glyph + aria-pressed stay in sync.</summary>
private bool _isDark;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
// Reflect the persisted theme once the circuit is interactive. Prerender
// has no JS runtime, so guard the call; a disconnect/blip just leaves the
// button on its default (light) glyph until the next render.
try
{
var mode = await JS.InvokeAsync<string>("sbTheme.get");
var isDark = mode == "dark";
if (isDark != _isDark)
{
_isDark = isDark;
StateHasChanged();
}
}
catch (JSException) { }
catch (JSDisconnectedException) { }
catch (InvalidOperationException) { }
}
private async Task ToggleAsync()
{
try
{
var mode = await JS.InvokeAsync<string>("sbTheme.toggle");
_isDark = mode == "dark";
}
catch (JSException) { }
catch (JSDisconnectedException) { }
catch (InvalidOperationException) { }
}
}