Redesign header: theme toggle, user avatar, burger menu

The app was dark-only with the email shown as plain text and a bare
"Abmelden" button. Header now has:

- A light/dark theme toggle (sun/moon icon). Choice persists via
  localStorage and is applied before first paint (inline script in
  <head>) to avoid a flash of the wrong theme; falls back to the
  system preference on first visit. Added a light CSS variable set
  alongside the existing dark palette.
- A circular user icon (head-and-shoulders) showing the email as a
  tooltip, replacing the plain-text address.
- A burger-menu dropdown with the email, disabled placeholder items
  ("Tags verwalten", "Einstellungen" — marked "bald") to make room
  for future features, and the actual Abmelden action.

Dropdown opens/closes via a small vanilla-JS handler in base.html
(click outside or Escape closes it), consistent with the project's
no-build-step, mostly-HTMX frontend.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Erik Thiele
2026-07-20 23:01:22 +02:00
parent dca6033c40
commit 4f99d51f9e
3 changed files with 144 additions and 4 deletions

View File

@@ -49,3 +49,31 @@
{% macro spinner(size=16) -%}
{{ base('<path d="M21 12a9 9 0 1 1-6.219-8.56"/>', size) }}
{%- endmacro %}
{% macro sun(size=16) -%}
{{ base('<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>', size) }}
{%- endmacro %}
{% macro moon(size=16) -%}
{{ base('<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>', size) }}
{%- endmacro %}
{% macro menu(size=16) -%}
{{ base('<line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="18" y2="18"/>', size) }}
{%- endmacro %}
{% macro user(size=16) -%}
{{ base('<circle cx="12" cy="12" r="10"/><circle cx="12" cy="10" r="3"/><path d="M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662"/>', size) }}
{%- endmacro %}
{% macro log_out(size=16) -%}
{{ base('<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" x2="9" y1="12" y2="12"/>', size) }}
{%- endmacro %}
{% macro sliders(size=16) -%}
{{ base('<line x1="21" x2="14" y1="4" y2="4"/><line x1="10" x2="3" y1="4" y2="4"/><line x1="21" x2="12" y1="12" y2="12"/><line x1="8" x2="3" y1="12" y2="12"/><line x1="21" x2="16" y1="20" y2="20"/><line x1="12" x2="3" y1="20" y2="20"/><line x1="14" x2="14" y1="2" y2="6"/><line x1="8" x2="8" y1="10" y2="14"/><line x1="16" x2="16" y1="18" y2="22"/>', size) }}
{%- endmacro %}
{% macro tag(size=16) -%}
{{ base('<path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"/><circle cx="7.5" cy="7.5" r="1.5"/>', size) }}
{%- endmacro %}

View File

@@ -4,13 +4,34 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}LinkVault{% endblock %}</title>
<script>
/* Theme so früh wie möglich setzen, damit die Seite nicht kurz hell aufblitzt. */
(function () {
try {
var stored = localStorage.getItem('linkvault-theme');
if (stored === 'light' || stored === 'dark') {
document.documentElement.setAttribute('data-theme', stored);
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
document.documentElement.setAttribute('data-theme', 'light');
}
} catch (e) {}
})();
</script>
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
<style>
:root {
color-scheme: dark;
--bg: #0f172a; --panel: #1e293b; --panel2: #273449;
--text: #e2e8f0; --muted: #94a3b8; --accent: #6366f1;
--accent-hover: #818cf8; --border: #334155; --danger: #ef4444;
}
:root[data-theme="light"] {
color-scheme: light;
--bg: #f8fafc; --panel: #ffffff; --panel2: #f1f5f9;
--text: #0f172a; --muted: #64748b; --accent: #6366f1;
--accent-hover: #4f46e5; --border: #e2e8f0; --danger: #dc2626;
}
body { transition: background-color .15s, color .15s; }
* { box-sizing: border-box; }
body {
margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
@@ -136,6 +157,7 @@
display: inline-flex; align-items: center; justify-content: center;
width: 30px; height: 30px; padding: 0;
}
.theme-icon-dark, .theme-icon-light { display: inline-flex; }
.icon-warn { color: #eab308; }
.icon-bookmark-active { color: #eab308; }
@@ -149,6 +171,30 @@
text-align: center; padding: 16px 24px; margin-top: 24px;
color: var(--muted); font-size: .8rem; border-top: 1px solid var(--border);
}
.user-menu { position: relative; display: flex; align-items: center; gap: 4px; }
.user-dropdown {
position: absolute; top: calc(100% + 8px); right: 0; min-width: 230px;
background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
box-shadow: 0 12px 32px rgba(0,0,0,.35); padding: 6px; z-index: 50;
}
:root[data-theme="light"] .user-dropdown { box-shadow: 0 12px 32px rgba(15,23,42,.14); }
.dropdown-email {
padding: 8px 10px; font-size: .8rem; color: var(--muted);
word-break: break-all;
}
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }
.dropdown-item {
display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
background: transparent; color: var(--text); border: none; border-radius: 6px;
padding: 8px 10px; font-size: .875rem; font-weight: 400; cursor: pointer;
}
.dropdown-item:hover:not(:disabled) { background: var(--panel2); }
.dropdown-item:disabled { color: var(--muted); cursor: default; opacity: .65; }
.dropdown-item .soon {
margin-left: auto; font-size: .65rem; text-transform: uppercase; letter-spacing: .04em;
background: var(--panel2); color: var(--muted); padding: 2px 6px; border-radius: 99px;
}
</style>
</head>
<body>
@@ -156,5 +202,49 @@
<footer class="app-footer">
&copy; {{ app_author }} &middot; Version {{ app_version }} &middot; {{ app_host }}
</footer>
<script>
(function () {
var themeBtn = document.getElementById('theme-toggle');
if (themeBtn) {
var dark = themeBtn.querySelector('.theme-icon-dark');
var light = themeBtn.querySelector('.theme-icon-light');
var applyIcon = function (theme) {
dark.style.display = theme === 'light' ? 'none' : 'inline-flex';
light.style.display = theme === 'light' ? 'inline-flex' : 'none';
};
applyIcon(document.documentElement.getAttribute('data-theme') === 'light' ? 'light' : 'dark');
themeBtn.addEventListener('click', function () {
var next = document.documentElement.getAttribute('data-theme') === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', next);
try { localStorage.setItem('linkvault-theme', next); } catch (e) {}
applyIcon(next);
});
}
var menuBtn = document.getElementById('menu-toggle');
var dropdown = document.getElementById('user-dropdown');
if (menuBtn && dropdown) {
var close = function () {
dropdown.hidden = true;
menuBtn.setAttribute('aria-expanded', 'false');
};
var open = function () {
dropdown.hidden = false;
menuBtn.setAttribute('aria-expanded', 'true');
};
menuBtn.addEventListener('click', function (e) {
e.stopPropagation();
if (dropdown.hidden) open(); else close();
});
document.addEventListener('click', function (e) {
if (!dropdown.hidden && !dropdown.contains(e.target) && e.target !== menuBtn) close();
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') close();
});
}
})();
</script>
</body>
</html>

View File

@@ -10,10 +10,32 @@
{{ icons.alert(size=14) }} KI aus
</span>
{% endif %}
<span>{{ user.email }}</span>
<form method="post" action="/logout" style="margin:0;">
<button class="ghost" type="submit">Abmelden</button>
</form>
<button id="theme-toggle" type="button" class="ghost icon-btn" title="Farbschema wechseln">
<span class="theme-icon-dark">{{ icons.moon() }}</span>
<span class="theme-icon-light">{{ icons.sun() }}</span>
</button>
<div class="user-menu">
<button type="button" class="ghost icon-btn" title="{{ user.email }}">{{ icons.user() }}</button>
<button id="menu-toggle" type="button" class="ghost icon-btn" title="Menü"
aria-haspopup="true" aria-expanded="false">{{ icons.menu() }}</button>
<div id="user-dropdown" class="user-dropdown" hidden>
<div class="dropdown-email">{{ user.email }}</div>
<div class="dropdown-sep"></div>
<button type="button" class="dropdown-item" disabled>
{{ icons.tag(size=15) }} Tags verwalten <span class="soon">bald</span>
</button>
<button type="button" class="dropdown-item" disabled>
{{ icons.sliders(size=15) }} Einstellungen <span class="soon">bald</span>
</button>
<div class="dropdown-sep"></div>
<form method="post" action="/logout" style="margin:0;">
<button type="submit" class="dropdown-item">{{ icons.log_out(size=15) }} Abmelden</button>
</form>
</div>
</div>
</div>
</header>