Skip to main content
The ThemeSwitcher is a pre-built dropdown component that provides an intuitive UI for users to switch between color themes and toggle between light and dark modes.

Installation

The ThemeSwitcher is automatically included when you install the theme system:

Usage

Add the ThemeSwitcher to your navigation or header:
components/layout/header.tsx

Features

The ThemeSwitcher provides:
  • Mode Toggle: Switch between light and dark modes with visual indicators
  • Color Theme Selection: Browse and select from all installed themes
  • Visual Previews: See color swatches for each theme
  • Current Selection: Check marks show the active theme and mode
  • Scrollable List: Handles large theme collections with a scrollable menu
  • Theme Attribution: Credits tweakcn in the footer

Implementation

components/theme-switcher.tsx

How It Works

Theme Parsing

The component uses a parseTheme helper function to extract the color theme name and mode from the combined theme string:

Mode Switching

When toggling between light and dark modes, the component preserves the current color theme:

Color Theme Switching

When changing color themes, the component preserves the current mode:

Hydration Safety

The component uses a mounted state to prevent hydration mismatches:

Customization

Remove Attribution

If you want to remove the tweakcn attribution, delete lines 144-156 from the component.

Change Button Style

Customize the trigger button appearance:

Adjust Menu Width

Change the dropdown menu width:

Modify Scroll Height

Adjust the scrollable area height:

Filter Themes

Show only specific theme categories:

Dependencies

The ThemeSwitcher requires these shadcn/ui components:
  • button
  • dropdown-menu
  • scroll-area
These are automatically installed with the theme system. Icons are provided by lucide-react.

useTheme Hook

Control themes programmatically

Custom Selector

Build your own theme selector