Add a persistent dark mode toggle

This commit is contained in:
Mikei386 committed 2026-11-14 19:32:44 +01:00
1 parent 196b7ff660
commit 74326805de
3 files changed
+192 -39

No files matched your search

+148 -39
View File
@@ -10,6 +10,32 @@
--danger: #a12f40;
--surface: rgb(255 255 255 / 72%);
--surface-solid: #f8fbfc;
--ambient-purple: #d9dffb;
--ambient-green: #d3efe4;
--focus: #2864ab;
--panel-edge: rgb(255 255 255 / 95%);
--nav-active: linear-gradient(120deg, #d4ede2, #e6f3ee);
--nav-outline: #16756026;
--hover: #145e5710;
--nav-icon-bg: rgb(255 255 255 / 68%);
--avatar-bg: #d7eee3;
--badge-bg: #11645712;
--badge-text: #305e54;
--danger-button: #a12f40;
--danger-button-hover: #812232;
--privacy-bg: linear-gradient(125deg, #e8f8ee, #def2eaad);
--control-border: #7c979e;
--control-bg: rgb(255 255 255 / 84%);
--table-heading: #e8eff487;
--table-hover: #dcefe870;
--row-muted: #e5eaee;
--row-muted-badge: #27455414;
--row-ordered: #ffe6ce;
--row-arrived: #d6efdd;
--dialog-backdrop: rgb(23 40 51 / 45%);
--swatch-outline: rgb(20 47 55 / 40%);
--message-bg: #e1f0e6;
--message-text: #24613f;
--radius: 20px;
--shadow: 0 14px 36px rgb(28 62 83 / 8%), inset 0 1px 0 rgb(255 255 255 / 85%);
font-family:
@@ -23,14 +49,53 @@
color: var(--ink);
background: var(--paper);
}
:root[data-theme="dark"] {
color-scheme: dark;
--ink: #e4eef2;
--muted: #a9bac4;
--green: #86ddc4;
--light: #203e3c;
--line: #93b0bf38;
--paper: #10181f;
--danger: #ffa2aa;
--surface: rgb(26 40 49 / 86%);
--surface-solid: #1b2933;
--ambient-purple: #25263e;
--ambient-green: #183a38;
--focus: #9ac5ff;
--panel-edge: #9fbac626;
--nav-active: linear-gradient(120deg, #264741, #203737);
--nav-outline: #86ddc438;
--hover: #86ddc418;
--nav-icon-bg: #111c24;
--avatar-bg: #264741;
--badge-bg: #76cdb323;
--badge-text: #a5e0cf;
--danger-button: #a12f40;
--danger-button-hover: #872637;
--privacy-bg: linear-gradient(125deg, #223d37, #1b302fbf);
--control-border: #67808a;
--control-bg: #14212a;
--table-heading: #283945;
--table-hover: #263d44;
--row-muted: #29343e;
--row-muted-badge: #afc5d022;
--row-ordered: #493421;
--row-arrived: #213e32;
--dialog-backdrop: rgb(6 11 16 / 72%);
--swatch-outline: #a5bbc680;
--message-bg: #223e33;
--message-text: #ade1c4;
--shadow: 0 14px 36px rgb(0 0 0 / 24%), inset 0 1px 0 rgb(255 255 255 / 5%);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
background:
radial-gradient(ellipse at 88% 2%, #d9dffb, transparent 55%),
radial-gradient(ellipse at 24% 5%, #d3efe4, transparent 52%), var(--paper);
radial-gradient(ellipse at 88% 2%, var(--ambient-purple), transparent 55%),
radial-gradient(ellipse at 24% 5%, var(--ambient-green), transparent 52%), var(--paper);
background-repeat: no-repeat;
background-size: 100% 56rem;
}
@@ -57,10 +122,12 @@ button {
cursor: pointer;
}
:focus-visible {
outline: 3px solid #2864ab;
outline: 3px solid var(--focus);
outline-offset: 3px;
}
.shell {
--shell-padding: clamp(16px, 2.3vw, 34px);
position: relative;
display: grid;
grid-template-columns: 238px minmax(0, 1fr);
align-items: start;
@@ -68,7 +135,36 @@ button {
min-height: 100svh;
max-width: 1640px;
margin-inline: auto;
padding: clamp(16px, 2.3vw, 34px);
padding: var(--shell-padding);
}
.theme-toggle {
position: absolute;
z-index: 2;
top: var(--shell-padding);
right: var(--shell-padding);
width: 44px;
height: 44px;
padding: 0;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--surface-solid);
color: var(--green);
box-shadow: var(--shadow);
font-size: 22px;
line-height: 1;
}
.theme-toggle:hover {
background: var(--light);
}
.theme-sun,
[data-theme="dark"] .theme-moon {
display: none;
}
[data-theme="dark"] .theme-sun {
display: inline;
}
.shell:not(.shell--guest) .theme-toggle:not([hidden]) ~ .main-wrap main {
padding-top: 56px;
}
.sidebar {
position: sticky;
@@ -79,7 +175,7 @@ button {
display: flex;
flex-direction: column;
background: var(--surface-solid);
border: 1px solid rgb(255 255 255 / 90%);
border: 1px solid var(--panel-edge);
border-radius: var(--radius);
box-shadow: var(--shadow);
}
@@ -134,15 +230,15 @@ nav > a {
margin: 3px 0;
}
nav > a[aria-current] {
background: linear-gradient(120deg, #d4ede2, #e6f3ee);
background: var(--nav-active);
color: var(--green);
box-shadow: inset 0 0 0 1px #16756026;
box-shadow: inset 0 0 0 1px var(--nav-outline);
font-weight: 700;
}
nav > a:hover,
.profile-link:hover,
.profile-link[aria-current] {
background-color: #145e5710;
background-color: var(--hover);
text-decoration: none;
}
.nav-icon {
@@ -152,7 +248,7 @@ nav > a:hover,
height: 26px;
place-items: center;
border-radius: 8px;
background: rgb(255 255 255 / 68%);
background: var(--nav-icon-bg);
color: var(--green);
font-size: 15px;
}
@@ -180,7 +276,7 @@ td small {
}
.avatar {
flex-shrink: 0;
background: #d7eee3;
background: var(--avatar-bg);
color: var(--green);
width: 38px;
height: 38px;
@@ -203,7 +299,7 @@ td small {
font-size: 12px;
}
.logout:hover {
background: #145e5710;
background: var(--hover);
color: var(--ink);
}
.main-wrap {
@@ -211,10 +307,10 @@ td small {
}
.badge {
display: inline-block;
background: #11645712;
background: var(--badge-bg);
padding: 5px 10px;
border-radius: 999px;
color: #305e54;
color: var(--badge-text);
font-size: 11px;
font-weight: 600;
white-space: nowrap;
@@ -290,11 +386,11 @@ p {
background: var(--light);
}
.danger {
background: var(--danger);
border-color: var(--danger);
background: var(--danger-button);
border-color: var(--danger-button);
}
.danger:hover {
background: #812232;
background: var(--danger-button-hover);
}
.stats {
display: grid;
@@ -305,7 +401,7 @@ p {
.stat,
.panel,
.login-card {
border: 1px solid rgb(255 255 255 / 95%);
border: 1px solid var(--panel-edge);
border-radius: var(--radius);
background: var(--surface);
box-shadow: var(--shadow);
@@ -330,7 +426,7 @@ p {
color: var(--muted);
}
.privacy {
background: linear-gradient(125deg, #e8f8ee, #def2eaad);
background: var(--privacy-bg);
}
.privacy strong {
font-size: clamp(1.55rem, 2.6vw, 2.1rem);
@@ -364,7 +460,7 @@ p {
flex: 1 1 10rem;
min-height: 44px;
padding: 8px 12px;
border: 1px solid #7c979e;
border: 1px solid var(--control-border);
border-radius: 10px;
background: var(--surface-solid);
color: var(--ink);
@@ -422,7 +518,7 @@ table {
}
th {
padding: 14px 22px;
background: #e8eff487;
background: var(--table-heading);
color: var(--muted);
font-size: 11px;
text-transform: uppercase;
@@ -435,7 +531,7 @@ td {
}
tbody tr:hover,
tbody tr:focus-within {
background: #dcefe870;
background: var(--table-hover);
}
td.quantity {
font-size: 18px;
@@ -465,12 +561,12 @@ td.quantity {
.order-row--unavailable:focus-within,
.spool-row--in-use,
.spool-row--in-use:hover {
background: #e5eaee;
color: #4d6069;
background: var(--row-muted);
color: var(--muted);
}
.spool-row--in-use .badge {
color: var(--muted);
background: #27455414;
background: var(--row-muted-badge);
}
.spool-row--in-use td.quantity {
color: inherit;
@@ -478,12 +574,12 @@ td.quantity {
.order-row--ordered,
.order-row--ordered:hover,
.order-row--ordered:focus-within {
background: #ffe6ce;
background: var(--row-ordered);
}
.order-row--arrived,
.order-row--arrived:hover,
.order-row--arrived:focus-within {
background: #d6efdd;
background: var(--row-arrived);
}
.order-status-form {
display: grid;
@@ -494,9 +590,9 @@ td.quantity {
width: 100%;
min-height: 36px;
padding: 6px 8px;
border: 1px solid #7c979e;
border: 1px solid var(--control-border);
border-radius: 8px;
background: white;
background: var(--control-bg);
color: var(--ink);
}
.order-status-form button {
@@ -551,7 +647,7 @@ td.quantity {
box-shadow: var(--shadow);
}
.consume-dialog::backdrop {
background: rgb(23 40 51 / 45%);
background: var(--dialog-backdrop);
}
.consume-dialog h2 {
margin-bottom: 8px;
@@ -680,9 +776,9 @@ td.quantity {
.field textarea {
width: 100%;
padding: 11px 12px;
border: 1px solid #7c979e;
border: 1px solid var(--control-border);
border-radius: 10px;
background: rgb(255 255 255 / 84%);
background: var(--control-bg);
color: var(--ink);
min-height: 44px;
}
@@ -708,9 +804,9 @@ td.quantity {
text-align: left;
}
.color-trigger {
border: 1px solid #7c979e;
border: 1px solid var(--control-border);
border-radius: 10px;
background: rgb(255 255 255 / 84%);
background: var(--control-bg);
}
.color-trigger::after {
content: "";
@@ -750,11 +846,11 @@ td.quantity {
flex: 0 0 16px;
width: 16px;
height: 16px;
border: 1px solid rgb(20 47 55 / 40%);
border: 1px solid var(--swatch-outline);
border-radius: 50%;
}
.color-dot--unknown {
border: 1px dashed #7c979e;
border: 1px dashed var(--control-border);
}
.field small,
.helptext {
@@ -781,8 +877,8 @@ td.quantity {
}
.message {
padding: 14px 18px;
background: #e1f0e6;
color: #24613f;
background: var(--message-bg);
color: var(--message-text);
font-size: 13px;
border-radius: 12px;
margin-bottom: 24px;
@@ -830,7 +926,7 @@ td.quantity {
.skip:focus {
position: absolute;
z-index: 9;
background: #fff;
background: var(--surface-solid);
padding: 15px;
}
.split {
@@ -961,8 +1057,21 @@ td.quantity {
}
@media (max-width: 760px) {
.shell {
--shell-padding: 12px;
display: block;
padding: 12px;
}
.shell .theme-toggle {
top: calc(var(--shell-padding) + 8px);
right: calc(var(--shell-padding) + 8px);
}
.theme-toggle:not([hidden]) + .sidebar .brand {
margin-right: 46px;
}
.shell:not(.shell--guest) .theme-toggle:not([hidden]) ~ .main-wrap main {
padding-top: 26px;
}
.shell--guest .theme-toggle:not([hidden]) + .sidebar {
margin-right: 52px;
}
.sidebar {
position: static;
+39
View File
@@ -0,0 +1,39 @@
"use strict";
(() => {
const key = "fil-a-management-theme";
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)");
let preference;
let toggle;
try {
preference = window.localStorage.getItem(key);
} catch {
// The system theme still works when browser storage is unavailable.
}
function applyTheme() {
const dark = preference === "dark" || (preference !== "light" && systemTheme.matches);
document.documentElement.dataset.theme = dark ? "dark" : "light";
toggle?.setAttribute("aria-pressed", String(dark));
if (toggle) toggle.title = dark ? "Hellmodus einschalten" : "Dunkelmodus einschalten";
}
applyTheme();
systemTheme.addEventListener("change", applyTheme);
document.addEventListener("DOMContentLoaded", () => {
toggle = document.querySelector("[data-theme-toggle]");
applyTheme();
toggle.hidden = false;
toggle.addEventListener("click", () => {
preference = document.documentElement.dataset.theme === "dark" ? "light" : "dark";
try {
window.localStorage.setItem(key, preference);
} catch {
// The current page can still use the chosen theme.
}
applyTheme();
});
});
})();
+5
View File
@@ -5,12 +5,17 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{% block title %}Fil-A-Management{% endblock %}</title>
<script src="{% static 'filament/theme.js' %}"></script>
<link rel="stylesheet" href="{% static 'filament/app.css' %}">
<script src="{% static 'filament/catalog.js' %}" defer></script>
</head>
<body>
<a class="skip" href="#main">Zum Inhalt springen</a>
<div class="shell{% if not user.is_authenticated %} shell--guest{% endif %}">
<button class="theme-toggle" type="button" aria-label="Dunkelmodus" aria-pressed="false" data-theme-toggle hidden>
<span class="theme-moon" aria-hidden="true">☾</span>
<span class="theme-sun" aria-hidden="true">☀</span>
</button>
<aside class="sidebar">
<a class="brand" href="/"><span class="brand-icon" aria-hidden="true">◉</span><span>Fil-A-Management</span></a>
{% if user.is_authenticated %}