Theme selector

A row of miniature app previews, one per theme, with a ring that marks the one you pick.

Interaction Type

Hover a preview and a faint ring shows around it; click it and a solid ring marks it as selected. Arrow keys move between themes and select as they go; Home and End jump to the first and last.

Props

Options you can pass to customize this component.

Prop
Type
Description
themes
ThemeOption[]

The themes to show, each with a value, a label and a palette of six colors for its preview. Defaults to dark and light.

value
stringnull

The selected theme. Pass it to control the selector yourself; leave it out to let the component track its own state. Pass null until your theme is known, like during server rendering, so nothing is selected yet.

defaultValue
string

Starting theme when uncontrolled. Falls back to the first theme.

onChange
(value: string) => void

Fires with the new value when a different theme is picked.

labels
boolean

Shows each theme's label under its preview, brightened on the selected one.

disabled
boolean

Blocks selection and dims every preview.

className
string

Extra classes for the row that wraps the previews.

itemClassName
string

Extra classes for each preview, for sizing. Each one is w-40 at a 4:3 ratio by default, and everything inside scales with it.

Installation

npx shadcn@latest add swamimalode07/rare-ui/theme-selector

How to use

"use client"
import { useSyncExternalStore } from "react"
import { useTheme } from "next-themes"
import ThemeSelector from "@/components/ui/theme-selector"
const subscribe = () => () => {}
export function Demo() {
const { resolvedTheme, setTheme } = useTheme()
// the server can't know the theme, so select nothing until hydration is done
const hydrated = useSyncExternalStore(subscribe, () => true, () => false)
return (
<ThemeSelector
value={hydrated ? (resolvedTheme ?? null) : null}
onChange={setTheme}
/>
)
}
// No theme library? Toggle the class yourself:
// const [theme, setTheme] = useState<string | null>(null)
// useEffect(() => setTheme(localStorage.theme ?? "dark"), [])
// useEffect(() => {
// if (!theme) return
// document.documentElement.classList.toggle("dark", theme === "dark")
// localStorage.theme = theme
// }, [theme])
// <ThemeSelector value={theme} onChange={setTheme} />

Source Code

Click the code icon in the top-right corner to view the source code.

Keep in mind

Most components here are recreations of great work from around the web. I don't claim to be the original creator - this is my attempt to reverse-engineer, replicate, and often add a few extra features. I've tried to credit everyone; if I missed someone, let me know.

Contact

Found a bug or issue? Feel free to drop a DM.

License & Usage

  • •MIT with the Commons Clause and an attribution requirement. Free to use, modify and ship in personal and commercial projects, closed source included. You own the code once it is in your project.
  • •Credit is required. Any project shipping a Rare UI component must credit Rare UI with a visible link back to rareui.com, in a footer, an about page, a credits screen or a README.
  • •Don't strip the credit or the copyright notice from the source you copied.
  • •Don't sell, sublicense or redistribute the components themselves, on their own, bundled into a template, kit, theme or paid course, or ported to another framework.
  • •Don't republish them. No mirrors, no re-uploads, no listing them as your own work.
  • •Don't repackage the registry as a competing component library.
  • •Don't claim authorship of a component or of Rare UI itself.
  • •The LICENSE file in the repository is the full text and governs. Ask first if your use doesn't fit these rules.
Theme selector

Theme

Pick how the interface looks.