A light / dark (and optionally system) switch. It toggles the kit's .dark class on the document or any element, can remember the choice in localStorage, follows the OS live in system mode, and ships a head script so a stored choice never flashes on reload.
Installation
The whole kit as one package — get updates by bumping the version. Add the styles to globals.css: @import "@vamos-ui/react/styles.css";
Usage
import { ModeToggle, modeToggleScript } from "@vamos-ui/react";
// In <head>, before the page paints:
<script dangerouslySetInnerHTML={{ __html: modeToggleScript("site:mode") }} />
<ModeToggle storageKey="site:mode" />
<ModeToggle variant="segmented" modes={["light", "dark", "system"]} showLabel />Nothing is written to the target until the stored mode is read, so a class set by the head script is never flipped off during hydration.
Storage failures (private mode) are ignored; the choice then lasts for the page.
Examples
Light, dark and system
variant="segmented" shows every mode; system follows prefers-color-scheme as it changes.
Controlled (SiteShell, ThemeScope)
target={null} leaves the DOM alone; pass the mode to SiteShell's theme or a ThemeScope.
API
ModeToggle
| Prop | Type | Default |
|---|---|---|
value / defaultValueControlled or initial mode. Uncontrolled default: the stored choice, else what the target already shows. | "light" | "dark" | "system" | — |
onValueChangeThe chosen mode and what it resolves to. | (mode, resolved: "light" | "dark") => void | — |
modesModes offered, in order. | ColorMode[] | ["light", "dark"] |
variantOne icon button (dark-mode toggle with two modes, cycling with three) or one option per mode. | "button" | "segmented" | "button" |
targetWhere the .dark class goes; null only reports. | HTMLElement | (() => HTMLElement | null) | null | document.documentElement |
storageKeyRemember the choice in localStorage. | string | — |
showLabelShow the mode name next to the icon. | boolean | false |
sizeControl size. | "xs" | "sm" | "md" | "sm" |
labelsDictionary namespace "modeToggle": label, light, dark, system, darkMode, current. | Partial<ModeToggleLabels> | — |
modeToggleScript(storageKey, fallback?)
| Prop | Type | Default |
|---|---|---|
returnsInline script for <head> that applies the stored mode before first paint. fallback defaults to "system". | string | — |