Added theme switcher

This commit is contained in:
ayurishchev committed 2026-08-26 21:18:58 +03:00
1 parent 51402c590a
commit 6410273cf8
4 files changed
+98 -7

No files matched your search

+34 -2
View File
@@ -14,6 +14,21 @@
<title>Cloud IP Validator — Admin</title>
<link rel="stylesheet" href="/static/vendor/fonts.css">
<link rel="stylesheet" href="/static/dashboard.css">
<script>
// Apply a saved theme choice before first paint, so a page load never
// flashes the OS-default theme before switching to the stored one. Runs
// synchronously, after the stylesheet link above (browsers block a
// same-document script on a preceding <link rel="stylesheet"> until it
// loads), and before body markup starts rendering.
(function () {
try {
var saved = localStorage.getItem('theme');
if (saved === 'light' || saved === 'dark') {
document.documentElement.setAttribute('data-theme', saved);
}
} catch (e) {}
})();
</script>
<script src="/static/vendor/htmx.min.js"></script>
<script src="/static/vendor/alpine.min.js" defer></script>
{{end}}
@@ -60,10 +75,27 @@
</nav>
<div class="sidebar-foot">
<span class="pulse-dot"></span>
control-api
<span class="sidebar-foot-status"><span class="pulse-dot"></span>control-api</span>
<button type="button" class="theme-toggle" id="themeToggle" aria-label="Переключить тему" title="Переключить тему">
<svg class="icon-sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
<svg class="icon-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.8A9 9 0 1 1 11.2 3 7 7 0 0 0 21 12.8Z"/></svg>
</button>
</div>
</aside>
<script>
(function () {
var btn = document.getElementById('themeToggle');
if (!btn) return;
function effectiveTheme() {
return getComputedStyle(document.documentElement).colorScheme.indexOf('dark') !== -1 ? 'dark' : 'light';
}
btn.addEventListener('click', function () {
var next = effectiveTheme() === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', next);
try { localStorage.setItem('theme', next); } catch (e) {}
});
})();
</script>
{{end}}
{{define "topbar_mobile"}}