Theme Toggle

System, light and dark as one segmented control, plus the round light and dark button ward.so uses; it can apply and remember the choice.

Installation

pnpm dlx shadcn@latest add @ward/theme-toggle

Add the Ward registry to components.json once:

"registries": {
  "@ward": "https://ward.so/r/{name}.json"
}

Or install from the URL with no configuration: npx shadcn@latest add https://ward.so/r/theme-toggle.json

Usage

import ThemeToggle, { ThemeIconToggle } from "@/components/ward/ThemeToggle";
<ThemeToggle apply />
<ThemeIconToggle />

Props

PropTypeDefaultDescription
variant"System" | "Light" | "Dark""System"Appearance selected when the toggle first renders without a value.
value"system" | "light" | "dark"-Selected appearance when the parent controls the toggle.
onChange(theme: "system" | "light" | "dark") => void-Called with the chosen appearance.
applybooleanfalseAlso set data-theme and the .dark class on <html> and remember the choice.
storageKeystring"ward-theme"localStorage key used when apply is on; ThemeIconToggle takes it too.

How to build

Give people a predictable choice between system, light and dark appearance.

Use the original Ward control below when you need a compact appearance setting. Persist the chosen mode in your application, then apply it to the document before hydration to avoid a flash.

Install Ward Theme Toggle →

Ward · Version 2.0.0 · Registry manifest