Theme Switcher for shadcn/ui

ColorSwitchCN

A beautiful, accessible theme switcher component for your shadcn/ui projects with instant theme changes and multiple theme presets.

Powered byTweakCN

Interactive Preview

Experience the theme switcher in action. Try switching between themes and color modes.

See instant theme changes as you interact with the component

Features

Designed with developer experience and user interface in mind

Easy Integration

Drop-in replacement for shadcn/ui projects with zero configuration

Theme Presets

Beautiful pre-designed themes for both light and dark modes

Customizable

Fully customizable with simple API and hooks

Installation

Add to your project

Follow these simple steps to integrate the theme switcher

1

Install the package

npx shadcn@latest add https://colorswitchcn.heywinit.me/r/colorswitchcn.json
2

Import and use

import { ThemeSwitcher } from "colorswitchcn"

export function Navbar() {
  return (
    <div className="flex items-center gap-4">
      <nav>{/* Your navigation */}</nav>
      <ThemeSwitcher />
    </div>
  )
}

Theme Preview

Interactive Demo

See how colors change instantly across UI elements

Button (Primary)bg-primary
Button (Secondary)bg-secondary
Card Backgroundbg-card
Card Background
Muted Backgroundbg-muted
Muted Background

useThemeSwitch Hook API

Overview

The useThemeSwitch hook provides a comprehensive way to control theme settings in your application.

This hook handles both light/dark mode toggling and custom color presets. It's inspired by the TweakCN theme system.

Installation

import { useThemeSwitch } from "colorswitchcn";

Basic Usage

const { theme, switchPreset, toggleMode, allPresets } = useThemeSwitch();

// Toggle between light/dark
toggleMode();

// Apply a different color preset
switchPreset('blue');

Live Example

See the hook in action with this interactive example

Theme Mode: light

Current Preset: default

Hook Options

Configure the useThemeSwitch hook with these options

useThemeSwitch({
  defaultPreset: "default",           // Default preset to use
});

defaultPreset

The preset to use when no preset is saved in localStorage.