Theme Toggle Component
Learn how the docs UI switches between light and dark themes.
Theme Toggle Component
The ThemeToggle component provides the light/dark switch in the docs UI.
Where it lives
- File:
components/theme-toggle.tsx
What it does
- Reads the active resolved theme using
useTheme()fromnext-themes. - On click, toggles from
lighttodark(and vice versa) withsetTheme(...). - Renders different SVG icons depending on the current theme:
- Light mode icon is shown with
[html.light_&]:block - Dark mode icon is shown with
[html.dark_&]:block
- Light mode icon is shown with
Accessibility
- Includes
<span className="sr-only">Toggle theme</span>so screen readers have a clear label.
Notes
suppressHydrationWarningis applied to avoid hydration mismatch warnings between server and client theme state.
