feat: add light theme toggle
This commit is contained in:
1 parent
448e7a723d
commit
2fcb29e3fe
8 files changed
+132
-13
No files matched your search
@@ -8,6 +8,7 @@ const STATUS_LABEL = {
|
||||
ignore: "скрыта",
|
||||
};
|
||||
const PER_PAGE = 60;
|
||||
const THEME_KEY = "sb.theme";
|
||||
|
||||
const state = {
|
||||
view: "library",
|
||||
@@ -141,6 +142,27 @@ function applyMaintenance(open) {
|
||||
maintenanceToggle.addEventListener("click", () => applyMaintenance(!maintenanceOpen));
|
||||
applyMaintenance(maintenanceOpen);
|
||||
|
||||
const themeToggle = $("#themeToggle");
|
||||
function syncThemeButton() {
|
||||
const light = document.documentElement.dataset.theme === "light";
|
||||
themeToggle.title = light ? "Тёмная тема" : "Светлая тема";
|
||||
themeToggle.setAttribute("aria-label", themeToggle.title);
|
||||
themeToggle.setAttribute("aria-pressed", String(light));
|
||||
}
|
||||
themeToggle.addEventListener("click", () => {
|
||||
const light = document.documentElement.dataset.theme === "light";
|
||||
if (light) {
|
||||
delete document.documentElement.dataset.theme;
|
||||
} else {
|
||||
document.documentElement.dataset.theme = "light";
|
||||
}
|
||||
try {
|
||||
localStorage.setItem(THEME_KEY, light ? "dark" : "light");
|
||||
} catch (_) {}
|
||||
syncThemeButton();
|
||||
});
|
||||
syncThemeButton();
|
||||
|
||||
function esc(value) {
|
||||
return String(value ?? "")
|
||||
.replaceAll("&", "&")
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>SteamBase — библиотека и рекомендации</title>
|
||||
<link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
|
||||
<script>
|
||||
try {
|
||||
if (localStorage.getItem("sb.theme") === "light") document.documentElement.dataset.theme = "light";
|
||||
} catch (_) {}
|
||||
</script>
|
||||
<link rel="stylesheet" href="/static/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
@@ -18,6 +23,18 @@
|
||||
<button class="tab" data-view="recommend">Рекомендации</button>
|
||||
</nav>
|
||||
<div class="stats" id="stats"></div>
|
||||
<button id="themeToggle" class="icon-btn theme-toggle" type="button"
|
||||
title="Светлая тема" aria-label="Переключить тему" aria-pressed="false">
|
||||
<svg class="icon-sun" viewBox="0 0 24 24" width="16" height="16" fill="none"
|
||||
stroke="currentColor" stroke-width="1.8" stroke-linecap="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" width="16" height="16" fill="none"
|
||||
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div id="filtersBackdrop" class="filters-backdrop" hidden></div>
|
||||
|
||||
@@ -749,6 +749,80 @@ textarea { resize: vertical; min-height: 54px; }
|
||||
}
|
||||
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
|
||||
|
||||
.theme-toggle .icon-moon { display: none; }
|
||||
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }
|
||||
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }
|
||||
|
||||
/* light theme */
|
||||
html[data-theme="light"] {
|
||||
color-scheme: light;
|
||||
--bg: #f4f1e9;
|
||||
--bg-2: #fffcf5;
|
||||
--panel: #ffffff;
|
||||
--panel-2: #f3efe5;
|
||||
--text: #172033;
|
||||
--muted: #5c687c;
|
||||
--border: rgba(23, 32, 51, .13);
|
||||
--border-strong: rgba(23, 32, 51, .24);
|
||||
--accent: #a8620d;
|
||||
--accent-2: #0f766e;
|
||||
--danger: #be123c;
|
||||
--shadow: 0 18px 48px rgba(50, 40, 20, .16);
|
||||
}
|
||||
html[data-theme="light"] body {
|
||||
background:
|
||||
radial-gradient(1100px 600px at 85% -10%, rgba(15, 118, 110, .08), transparent 60%),
|
||||
radial-gradient(900px 500px at 0% 0%, rgba(168, 98, 13, .08), transparent 55%),
|
||||
var(--bg);
|
||||
}
|
||||
html[data-theme="light"] .topbar { background: rgba(247, 244, 236, .82); }
|
||||
html[data-theme="light"] .tabs,
|
||||
html[data-theme="light"] .stat,
|
||||
html[data-theme="light"] .ghost,
|
||||
html[data-theme="light"] .more,
|
||||
html[data-theme="light"] .chip,
|
||||
html[data-theme="light"] .modal-close,
|
||||
html[data-theme="light"] .modal-back { background: rgba(23, 32, 51, .035); }
|
||||
html[data-theme="light"] .layout.filters-unpinned .filters { background: #fbf8f1; }
|
||||
html[data-theme="light"] .cover,
|
||||
html[data-theme="light"] .cover .fallback {
|
||||
background: linear-gradient(145deg, #e9e2d5, #f7f3ea);
|
||||
color: rgba(23, 32, 51, .72);
|
||||
}
|
||||
html[data-theme="light"] .ghost,
|
||||
html[data-theme="light"] .genre,
|
||||
html[data-theme="light"] .chip,
|
||||
html[data-theme="light"] .modal-desc,
|
||||
html[data-theme="light"] .modal-desc.about { color: #3a4760; }
|
||||
html[data-theme="light"] .genre {
|
||||
background: rgba(23, 32, 51, .055);
|
||||
border-color: rgba(23, 32, 51, .08);
|
||||
}
|
||||
html[data-theme="light"] .card-desc { color: #4a566d; }
|
||||
html[data-theme="light"] .card-desc.loading,
|
||||
html[data-theme="light"] .card-desc.missing-desc,
|
||||
html[data-theme="light"] .dp-note { color: #6f7b8f; }
|
||||
html[data-theme="light"] .bar { background: rgba(23, 32, 51, .1); }
|
||||
html[data-theme="light"] .badge {
|
||||
background: rgba(250, 247, 240, .85);
|
||||
border-color: rgba(23, 32, 51, .12);
|
||||
}
|
||||
html[data-theme="light"] .badge.review { color: #0f766e; }
|
||||
html[data-theme="light"] .badge.review.warn { color: #a8620d; }
|
||||
html[data-theme="light"] .toast { background: rgba(255, 252, 245, .97); }
|
||||
html[data-theme="light"] .skeleton .cover,
|
||||
html[data-theme="light"] .skeleton .line {
|
||||
background: linear-gradient(100deg, #e8e2d6 30%, #f5f0e6 50%, #e8e2d6 70%);
|
||||
background-size: 200% 100%;
|
||||
}
|
||||
html[data-theme="light"] .st-backlog { color: #475569; }
|
||||
html[data-theme="light"] .st-playing { color: #047857; }
|
||||
html[data-theme="light"] .st-played { color: #1d4ed8; }
|
||||
html[data-theme="light"] .st-nostalgia { color: #6d28d9; }
|
||||
html[data-theme="light"] .st-tribute { color: #92400e; }
|
||||
html[data-theme="light"] .st-ignore { color: #be123c; }
|
||||
html[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c9c0ad; }
|
||||
|
||||
/* skeleton */
|
||||
.skeleton { pointer-events: none; }
|
||||
.skeleton .cover { background: linear-gradient(100deg, #131a28 30%, #1b2436 50%, #131a28 70%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
|
||||
|
||||
Reference in new issue
Block a user