Skip to content

Commit

Permalink
Fixed dark theme for server-side cookie consent using user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Nov 23, 2024
1 parent 1362541 commit 28173f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

"jsx-a11y/html-has-lang": "off", // Layout avec Google Fonts

"tailwindcss/no-custom-classname": ["warn", { "whitelist": ["toaster"] }], // https://sonner.emilkowal.ski/ + https://ui.shadcn.com/docs/components/sonner
"tailwindcss/no-custom-classname": ["warn", { "whitelist": ["toaster", "cc--darkmode"] }], // https://sonner.emilkowal.ski/ + https://ui.shadcn.com/docs/components/sonner

"@typescript-eslint/no-shadow": "error",

Expand Down
7 changes: 6 additions & 1 deletion app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export default async function Layout( {
const theme = session?.user.preferences?.theme ?? "light";
const color = session?.user.preferences?.color ?? "blue";
const factory = session?.user.preferences?.default ?? true;
const isDarkMode = theme === "dark";

// Affichage du rendu HTML de la page.
return (
Expand All @@ -253,7 +254,7 @@ export default async function Layout( {
"--roboto-font": roboto.style.fontFamily
} as CSSProperties
}
className={`${ font } ${ color } ${ factory ? theme : "light" } antialiased`}
className={`${ font } ${ color } ${ factory ? theme : "light" } antialiased ${ isDarkMode ? "cc--darkmode" : "" }`}
suppressHydrationWarning
>
{/* En-tête de la page */}
Expand All @@ -270,6 +271,10 @@ export default async function Layout( {
element.classList.remove("light", "dark");
element.classList.add(target);
element.style.colorScheme = target;
if (target === "dark") {
element.classList.add("cc--darkmode");
}
`
}}
/>
Expand Down

0 comments on commit 28173f6

Please sign in to comment.