Off By One UI
← Back to Components

Theme Selector

Dropdown selector for choosing theme presets with color previews.

Installation

npx shadcn@latest add https://ui.offbyone.ai/r/theme-selector.json

Usage

The Theme Selector requires a ThemeProvider wrapper:

import { ThemeProvider } from "@/components/ui/theme-provider"
import { ThemeSelector } from "@/components/ui/theme-selector"

export default function App() {
  return (
    <ThemeProvider defaultPreset="default">
      <ThemeSelector />
    </ThemeProvider>
  )
}

Examples

Default

Full Theme Switcher

Combine with the Mode Toggle for complete theme control:

Color Mode

Theme Preset

Available Presets

PresetDescription
defaultClean and minimal design
forestBold green accents inspired by nature
oceanCalm blues and aqua tones
sunsetWarm oranges and golden hues
lavenderDreamy purples and soft violet tones
roseElegant pinks and romantic hues

Adding Theme CSS Variables

To support theme presets, add CSS variables for each theme in your global styles:

/* Default theme uses the base variables */

[data-theme="forest"] {
  --primary: 160 84% 39%;
  --primary-foreground: 0 0% 98%;
}

[data-theme="ocean"] {
  --primary: 201 96% 32%;
  --primary-foreground: 0 0% 98%;
}

[data-theme="sunset"] {
  --primary: 25 95% 53%;
  --primary-foreground: 0 0% 98%;
}

[data-theme="lavender"] {
  --primary: 263 70% 50%;
  --primary-foreground: 0 0% 98%;
}

[data-theme="rose"] {
  --primary: 347 77% 50%;
  --primary-foreground: 0 0% 98%;
}

API Reference

ThemeSelector

The component has no props - it reads from and writes to the ThemeProvider context.

Theme Presets Type

type ThemePreset =
  | "default"
  | "forest"
  | "ocean"
  | "sunset"
  | "lavender"
  | "rose"

useTheme Hook

const { preset, setPreset } = useTheme()

// Change theme
setPreset("ocean")