Mörkt läge som följer systemet, med val för ljust och mörkt
Temat har nu tre lägen (automatiskt, ljust, mörkt) och följer webbläsarens eller systemets inställning som standard. Ett skript i <head> sätter temat innan sidan ritas så att mörkt läge inte blinkar till ljust. Kartplattorna dämpas i mörkt läge. Tester och README ingår. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c58f70bdd
commit
96399ba2d8
9 files changed
+160
-18
No files matched your search
+7
-2
@@ -7,6 +7,7 @@ import { I18nProvider } from "@/i18n/client";
|
||||
import { dictionaries } from "@/i18n/core";
|
||||
import { getLocale } from "@/i18n/server";
|
||||
import { TablerJs } from "@/components/tabler-js";
|
||||
import { THEME_BOOT_SCRIPT, parseThemeMode, serverTheme } from "@/lib/theme";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: { default: "Bokplanerare", template: "%s · Bokplanerare" },
|
||||
@@ -15,10 +16,14 @@ export const metadata: Metadata = {
|
||||
|
||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const locale = await getLocale();
|
||||
const theme = (await cookies()).get("theme")?.value === "dark" ? "dark" : "light";
|
||||
const theme = serverTheme(parseThemeMode((await cookies()).get("theme")?.value));
|
||||
|
||||
return (
|
||||
<html lang={locale} data-bs-theme={theme}>
|
||||
// suppressHydrationWarning: skriptet i <head> kan byta tema till mörkt före hydreringen när valet är auto
|
||||
<html lang={locale} data-bs-theme={theme} suppressHydrationWarning>
|
||||
<head>
|
||||
<script dangerouslySetInnerHTML={{ __html: THEME_BOOT_SCRIPT }} />
|
||||
</head>
|
||||
<body>
|
||||
<I18nProvider locale={locale} dict={dictionaries[locale]}>
|
||||
<TablerJs />
|
||||
|
||||
Reference in new issue
Block a user