-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add actual preferred color theme switch support via cookies⚠️ This commit introduce several issues directly linked to the App Router's current limitations : 1. preferred-color-scheme isn't supported anymore 2. every route is now dynamically rendered by default as we use cookies in the root layout A better approach would be to load a client script as "beforeInteractive" to (1) check if a "color-theme" preferrence has been set in the local storage (2) if not, set it based on preferred-color-scheme and (3) add or remove the 'dark' class on document.documentElement accordingly. Then, the DarkModToggle element could work exactly as it is, but using the local storage instead of a cookie. Unfortunately, this wouldn't be a better approach at the moment as the Next.js Script component isn't supported by the App Router. see vercel/next.js#51242 and https://nextjs.org/docs/app/api-reference/functions/cookies and https://nextjs.org/docs/pages/api-reference/components/script#beforeinteractive inspired by https://michaelangelo.io/blog/darkmode-rsc
- Loading branch information
Showing
3 changed files
with
43 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
import { DarkModeToggle } from './DarkModeToggle'; | ||
import LocaleSwitcher from './LocaleSwitcher'; | ||
import dynamic from 'next/dynamic'; | ||
|
||
export function Header({ author } : { author : string }) { | ||
const DarkModeToggle = dynamic(() => import('./DarkModeToggle'), { | ||
ssr: false, | ||
}); | ||
|
||
export function Header({ author }: { author: string }) { | ||
return ( | ||
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm md:flex"> | ||
<div className="flex h-12 w-full item-start justify-center md:h-auto md:w-auto"> | ||
<LocaleSwitcher /> | ||
</div> | ||
<div className=""> | ||
<DarkModeToggle /> | ||
</div> | ||
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black md:static md:h-auto md:w-auto md:bg-none"> | ||
<a | ||
className="pointer-events-none flex place-items-center gap-2 p-8 md:pointer-events-auto md:p-0" | ||
href="https://nwel.dev" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{author} | ||
</a> | ||
</div> | ||
<div className="flex h-12 w-full item-start justify-center md:h-auto md:w-auto"> | ||
<LocaleSwitcher /> | ||
</div> | ||
) | ||
} | ||
<div className=""> | ||
<DarkModeToggle /> | ||
</div> | ||
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black md:static md:h-auto md:w-auto md:bg-none"> | ||
<a | ||
className="pointer-events-none flex place-items-center gap-2 p-8 md:pointer-events-auto md:p-0" | ||
href="https://nwel.dev" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{author} | ||
</a> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters