Mode Toggle
---import { ModeToggle } from "@/components/ui/mode-toggle"---
<ModeToggle />Installation
Section titled “Installation”To install the mode toggle component, run the following command:
pnpm dlx shadcn@latest add @fulldev-ui/mode-toggleimport { ModeToggle } from "@/components/ui/mode-toggle"<ModeToggle />Features
Section titled “Features”- Automatically detects system preference
- Persists user preference in localStorage
- Smooth transitions between themes
- Accessible with proper aria labels
How it works
Section titled “How it works”The ModeToggle component:
- Detects the user’s system theme preference on first load
- Applies the
darkclass to the<html>element when dark mode is active - Saves the user’s preference to localStorage
- Listens for clicks to toggle between light and dark modes
- Ensures smooth transitions without jarring flashes
The component is intentionally self-contained with inline scripts to avoid flash of unstyled content (FOUC) when the page loads.