Darkmode für Shop und Admin mit animiertem Umschalten

- Schalter (Sonne/Mond) im Kopf des Shops, in der Admin-Seitenleiste und oben in der mobilen Admin-Ansicht
- Ohne eigene Wahl folgt das Design der Systemeinstellung; die Wahl wird im Browser gemerkt, kein Aufblitzen beim Laden
- Umschalten: neues Farbschema breitet sich als Kreis vom Schalter aus (View Transitions), sonst sanfte Überblendung; reduzierte Bewegung wird beachtet
- Gold-Logo im dunklen Admin und Login; Rechnung bleibt immer hell ([data-theme="light"] aus den Tokens)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvuGvHpbAQ4syfuLuRvutL
This commit is contained in:
Claude 2026-10-19 20:10:29 +00:00 committed by Maaxxs
parent 21aa679504
commit 813f6e3cc9
10 changed files with 178 additions and 6 deletions

View file

@ -23,6 +23,8 @@ for (const [k, v] of Object.entries(t.type.families)) css += ` --font-${k}: ${v
for (const fam of ["spacing", "radius", "layout", "breakpoint"])
for (const tok of t[fam]?.tokens ?? []) css += ` --${tok.name}: ${tok.value};\n`;
css += block(first) + "\n color-scheme: light;\n}\n";
// Für Bereiche, die im Darkmode hell bleiben sollen (z. B. Rechnung)
css += `[data-theme="${first}"] {\n${block(first)}\n color-scheme: light;\n background-color: var(--surface);\n color: var(--ink);\n}\n`;
for (const th of themes.slice(1)) {
css += `[data-theme="${th}"] {\n${block(th)}\n color-scheme: ${th};\n background-color: var(--surface);\n color: var(--ink);\n}\n`;
}

View file

@ -5,6 +5,7 @@ import { can, requireAdmin } from "@/lib/auth";
import { logout } from "@/lib/auth-actions";
import { getSettings } from "@/lib/settings";
import { Icon } from "@/components/Icon";
import { ThemeToggle } from "@/components/ThemeToggle";
import { AdminNav } from "@/components/admin/AdminNav";
import { MobileAdminNav } from "@/components/admin/MobileAdminNav";
import { ADMIN_NAV } from "@/components/admin/nav";
@ -24,7 +25,8 @@ export default async function AdminLayout({ children }: { children: React.ReactN
<div className="ad-side__foot">
<p>{[user.firstName, user.lastName].filter(Boolean).join(" ") || user.email}</p>
<p className="ad-muted">{user.role?.name}</p>
<div style={{ display: "flex", gap: "var(--space-3)", marginTop: "var(--space-3)", flexWrap: "wrap" }}>
<div style={{ display: "flex", gap: "var(--space-3)", marginTop: "var(--space-3)", flexWrap: "wrap", alignItems: "center" }}>
<ThemeToggle className="ad-theme-btn" />
<Link href="/" target="_blank" className="body-sm" style={{ display: "inline-flex", gap: 4, alignItems: "center" }}>
<Icon name="external" size="sm" /> Shop ansehen
</Link>
@ -39,7 +41,9 @@ export default async function AdminLayout({ children }: { children: React.ReactN
const brand = (
<Link href="/admin" className="ad-side__brand">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src="/brand/bildmarke-ink.png" alt="" />
<img className="sm-logo--ink" src="/brand/bildmarke-ink.png" alt="" />
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className="sm-logo--gold" src="/brand/bildmarke-gold.png" alt="" />
<span>
<strong>{settings.general.shopName}.</strong>
<small>Verwaltung</small>
@ -62,7 +66,10 @@ export default async function AdminLayout({ children }: { children: React.ReactN
{foot}
</MobileAdminNav>
<strong style={{ letterSpacing: "0.24em", fontWeight: 400, textTransform: "uppercase" }}>{settings.general.shopName}.</strong>
<span style={{ display: "inline-flex" }}>
<ThemeToggle />
<Link className="sm-header__btn" href="/" aria-label="Shop ansehen"><Icon name="external" /></Link>
</span>
</div>
<main className="ad-main">{children}</main>
</div>

View file

@ -15,7 +15,9 @@ export default async function AdminLogin({ searchParams }: { searchParams: Promi
<main className="ad-login">
<div className="ad-login__box">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src="/brand/logo-ink.png" alt="Sanamare" style={{ width: 200, margin: "0 auto var(--space-6)" }} />
<img className="sm-logo--ink" src="/brand/logo-ink.png" alt="Sanamare" style={{ width: 200, margin: "0 auto var(--space-6)" }} />
{/* eslint-disable-next-line @next/next/no-img-element */}
<img className="sm-logo--gold" src="/brand/logo-gold.png" alt="Sanamare" style={{ width: 200, margin: "0 auto var(--space-6)" }} />
<div className="ad-card">
<div className="ad-card__body">
<h1 className="display-sm" style={{ marginBottom: "var(--space-2)" }}>Verwaltung</h1>

View file

@ -10,6 +10,7 @@ import "@/styles/tokens.css";
import "@/styles/bundle.css";
import "@/styles/shop.css";
import { getSettings } from "@/lib/settings";
import { themeScript } from "@/components/ThemeToggle";
// Settings come from the database, so nothing here can be prerendered at build time.
export const dynamic = "force-dynamic";
@ -25,7 +26,12 @@ export async function generateMetadata(): Promise<Metadata> {
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="de">
// data-theme setzt das Skript vor dem ersten Zeichnen, daher weicht es vom Server-HTML ab
<html lang="de" suppressHydrationWarning>
<head>
<meta name="theme-color" content="#f7f4ee" />
<script dangerouslySetInnerHTML={{ __html: themeScript }} />
</head>
<body>{children}</body>
</html>
);

View file

@ -48,7 +48,7 @@ export default async function InvoicePage({ params, searchParams }: { params: Pr
const showBank = !credit && !d.paid && (d.paymentCode === "invoice" || d.paymentCode === "prepayment") && d.bank;
return (
<div className="inv-page">
<div className="inv-page" data-theme="light">
<div className="inv-toolbar">
<span>{credit ? "Stornorechnung" : "Rechnung"} {invoice.number}</span>
<PrintButton />

View file

@ -0,0 +1,100 @@
"use client";
import { useEffect, useState } from "react";
export const THEME_KEY = "sm-theme";
type Theme = "light" | "dark";
const current = (): Theme => (document.documentElement.dataset.theme === "dark" ? "dark" : "light");
function apply(theme: Theme) {
document.documentElement.dataset.theme = theme;
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", theme === "dark" ? "#0d0d0f" : "#f7f4ee");
}
/**
* Hell/Dunkel umschalten. Ohne eigene Wahl folgt der Shop der Systemeinstellung.
* Animation: Das neue Farbschema breitet sich als Kreis vom Schalter aus (View Transitions), sonst sanfte Überblendung.
*/
export function ThemeToggle({ className = "sm-header__btn" }: { className?: string }) {
const [theme, setTheme] = useState<Theme | null>(null);
useEffect(() => {
setTheme(current());
// Systemwechsel übernehmen, solange niemand selbst gewählt hat
const mq = window.matchMedia("(prefers-color-scheme: dark)");
const onChange = () => {
let stored: string | null = null;
try {
stored = localStorage.getItem(THEME_KEY);
} catch {}
if (stored) return;
const next = mq.matches ? "dark" : "light";
apply(next);
setTheme(next);
};
mq.addEventListener("change", onChange);
return () => mq.removeEventListener("change", onChange);
}, []);
const toggle = (e: React.MouseEvent<HTMLButtonElement>) => {
const next: Theme = current() === "dark" ? "light" : "dark";
try {
localStorage.setItem(THEME_KEY, next);
} catch {}
const root = document.documentElement;
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const doc = document as Document & { startViewTransition?: (cb: () => void) => { ready: Promise<void> } };
if (reduce || !doc.startViewTransition) {
root.classList.add("theme-fading");
apply(next);
setTheme(next);
setTimeout(() => root.classList.remove("theme-fading"), 500);
return;
}
const rect = e.currentTarget.getBoundingClientRect();
const x = rect.left + rect.width / 2;
const y = rect.top + rect.height / 2;
const radius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
root.classList.add("theme-switching");
const t = doc.startViewTransition(() => {
apply(next);
setTheme(next);
});
t.ready
.then(() =>
root.animate(
{ clipPath: [`circle(0px at ${x}px ${y}px)`, `circle(${radius}px at ${x}px ${y}px)`] },
{ duration: 700, easing: "cubic-bezier(0.65, 0, 0.35, 1)", pseudoElement: "::view-transition-new(root)" },
).finished,
)
.catch(() => {})
.finally(() => root.classList.remove("theme-switching"));
};
const label = theme === null ? "Farbschema wechseln" : theme === "dark" ? "Helles Design einschalten" : "Dunkles Design einschalten";
return (
<button type="button" className={`${className} sm-theme-toggle`} onClick={toggle} aria-label={label} title={label}>
<svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" className="sm-theme-toggle__icon">
<mask id="sm-moon-mask">
<rect x="0" y="0" width="24" height="24" fill="#fff" />
<circle className="sm-theme-toggle__cut" cx="24" cy="4" r="7" fill="#000" />
</mask>
<circle className="sm-theme-toggle__core" cx="12" cy="12" r="5" mask="url(#sm-moon-mask)" fill="currentColor" />
<g className="sm-theme-toggle__rays" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round">
<line x1="12" y1="1.5" x2="12" y2="3.5" />
<line x1="12" y1="20.5" x2="12" y2="22.5" />
<line x1="1.5" y1="12" x2="3.5" y2="12" />
<line x1="20.5" y1="12" x2="22.5" y2="12" />
<line x1="4.6" y1="4.6" x2="6" y2="6" />
<line x1="18" y1="18" x2="19.4" y2="19.4" />
<line x1="4.6" y1="19.4" x2="6" y2="18" />
<line x1="18" y1="6" x2="19.4" y2="4.6" />
</g>
</svg>
</button>
);
}
/** Läuft vor dem ersten Zeichnen, damit nichts hell aufblitzt. */
export const themeScript = `(function(){try{var t=localStorage.getItem("${THEME_KEY}");if(t!=="light"&&t!=="dark")t=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";document.documentElement.dataset.theme=t}catch(e){}})()`;

View file

@ -4,6 +4,7 @@ import { getCurrentUser } from "@/lib/auth";
import { getSettings } from "@/lib/settings";
import { Icon } from "../Icon";
import { MobileNav, NavLinks } from "./NavLinks";
import { ThemeToggle } from "../ThemeToggle";
export async function Header() {
const [settings, count, user] = await Promise.all([getSettings(), getCartCount(), getCurrentUser()]);
@ -36,6 +37,7 @@ export async function Header() {
</div>
<NavLinks links={a.navigation} />
<div className="sm-header__actions">
<ThemeToggle />
<Link className="sm-header__btn" href="/suche" aria-label="Suchen">
<Icon name="search" />
</Link>

View file

@ -249,3 +249,6 @@ a.ad-kpi:hover { border-color: var(--line-strong); }
.ad-picker__item:hover { background: var(--surface); }
.ad-picker__item input { accent-color: var(--noir); }
.ad-picker__item strong { font-weight: 500; font-size: 15px; }
.ad-theme-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; margin: -6px 0 -6px -8px; border: 0; border-radius: 50%; background: none; cursor: pointer; }
.ad-theme-btn:hover { background: var(--surface-sunken); }
.ad-theme-btn svg { width: 18px; height: 18px; }

View file

@ -183,6 +183,7 @@ button { font: inherit; color: inherit; }
.sm-header__count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill); background: var(--noir); color: var(--on-noir); font-size: 11px; line-height: 18px; font-weight: 500; text-align: center; }
.sm-header__promo { background: var(--noir); color: var(--on-noir); text-align: center; font-size: 13px; line-height: 20px; padding: var(--space-2) var(--space-4); letter-spacing: 0.04em; }
.sm-header__promo a { color: var(--gold); }
html[data-theme="dark"] .sm-header__promo { background: var(--surface-sunken); color: var(--ink-muted); border-bottom: var(--hairline) solid var(--line); }
/* ---------- Breadcrumb ---------- */
.sm-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; padding: 0; list-style: none; font-size: 14px; line-height: 20px; color: var(--ink-muted); }
@ -327,3 +328,23 @@ button { font: inherit; color: inherit; }
.sm-tile .sm-ph { aspect-ratio: 3 / 4; }
.sm-tile__label { position: absolute; left: var(--space-4); right: var(--space-4); bottom: var(--space-4); display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); background: var(--surface-raised); border-radius: var(--radius-sm); font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; }
.sm-tile__label .sm-icon { width: 18px; height: 18px; color: var(--gold-deep); }
/* Darkmode-Schalter: Sonne wird zum Mond */
.sm-theme-toggle { color: var(--ink); }
.sm-theme-toggle__icon { overflow: visible; transition: transform 600ms cubic-bezier(0.65, 0, 0.35, 1); }
.sm-theme-toggle__core { transform-origin: 12px 12px; transition: r 500ms cubic-bezier(0.65, 0, 0.35, 1); }
.sm-theme-toggle__cut { transition: cx 500ms cubic-bezier(0.65, 0, 0.35, 1), cy 500ms cubic-bezier(0.65, 0, 0.35, 1); }
.sm-theme-toggle__rays { transform-origin: 12px 12px; transition: transform 500ms cubic-bezier(0.65, 0, 0.35, 1), opacity 300ms; }
html[data-theme="dark"] .sm-theme-toggle__icon { transform: rotate(-40deg); }
html[data-theme="dark"] .sm-theme-toggle__core { r: 8.5px; }
html[data-theme="dark"] .sm-theme-toggle__cut { cx: 17px; cy: 7px; }
html[data-theme="dark"] .sm-theme-toggle__rays { transform: scale(0.4) rotate(90deg); opacity: 0; }
.sm-theme-toggle:hover .sm-theme-toggle__rays { transform: rotate(22deg); }
html[data-theme="dark"] .sm-theme-toggle:hover .sm-theme-toggle__rays { transform: scale(0.4) rotate(90deg); }
/* Umschalten: Kreis vom Schalter aus (View Transitions), sonst Überblendung */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }
html.theme-fading, html.theme-fading * { transition: background-color 450ms ease, color 450ms ease, border-color 450ms ease, fill 450ms ease !important; }
@media (prefers-reduced-motion: reduce) { .sm-theme-toggle__icon, .sm-theme-toggle__core, .sm-theme-toggle__cut, .sm-theme-toggle__rays { transition: none; } }

View file

@ -56,6 +56,35 @@
--shadow-lg: 0 16px 48px #16141126;
color-scheme: light;
}
[data-theme="light"] {
--surface: #f7f4ee;
--surface-raised: #ffffff;
--surface-sunken: #efeadf;
--line: #e2dbcd;
--line-strong: #8c8270;
--ink: #161411;
--ink-muted: #5d574d;
--ink-subtle: #7d766b;
--gold: #c6a24c;
--gold-deep: #7a5e1a;
--gold-soft: #f4ebd3;
--on-gold: #161411;
--noir: #161411;
--on-noir: #f7f4ee;
--success: #1e6a5c;
--success-soft: #e0f1ec;
--danger: #a8322b;
--danger-soft: #f9e4e2;
--link: var(--gold-deep);
--focus-ring: var(--gold-deep);
--overlay: #161411a6;
--shadow-sm: 0 1px 2px #16141114;
--shadow-md: 0 4px 12px #1614111a, 0 1px 2px #1614110f;
--shadow-lg: 0 16px 48px #16141126;
color-scheme: light;
background-color: var(--surface);
color: var(--ink);
}
[data-theme="dark"] {
--surface: #0d0d0f;
--surface-raised: #17171a;