Light and Dark Mode Switch Toggle Menu
A button is added to the header that opens a menu that allows choosing light and dark mode directly, and default to system.
We use the next-themes
library for managing the theme which switches between light and dark mode.
We add two Shadcn UI components - for a button and for a dropdown menu.
We use the theme provider to create a new provider that manages the theme. src/components/providers.tsx
:
A button that is placed in the header opens a dropdown menu with the options for light, dark, and system-defined mode. src/components/mode-toggle.tsx
:
We wrap the content of the layout in the newly created provider. src/app/layout.tsx
:
We add the new button that opens the theme mode dropdown to the site header. src/components/site-header.tsx
:
Last Updated: