Theme toggle

Theme toggle is a neobrutalist React component from Cruise UI. The dark mode control: a button that switches light and dark (default), or variant="menu": a square icon button (sun, moon or monitor) opening a Light / Dark / System menu. It switches .nepa-mode on <html> and saves the choice so CruiseThemeScript restores it on the next visit; System follows the device setting, live. Install it with npx shadcn@latest add @cruiseui/theme-toggle.

Install

Terminal

npx shadcn@latest add @cruiseui/theme-toggle

First time? Installation shows the one-off components.json setup (the @cruiseui registry) and how to turn the theme on.

Example

Corners

Menu

Button

When to use it

When to use

A site header or settings page that offers dark mode.

When not to

Inside the Dashboard layout (it has the same toggle built in).

Props

CruiseThemeToggle

PropTypeDefaultDescription
variant?CruiseButtonVariant | ToggleVariant"button""button" (default): one toggle button. "menu": an icon button with a Light / Dark / System menu. (A button style here, e.g. "ghost", still works as before and means "button" with that style.)
buttonVariant?CruiseButtonVariant—The button's style ("secondary" by default), in both variants.
labels?{ dark: string; light: string; }{ dark: "Dark mode", light: "Light mode" }Button variant. dark: the label while it's light ("Dark mode", or "NEPA mode" in Pidgin mode); light: the label while it's dark.
menuLabels?{ trigger: string; light: string; dark: string; system: string; }{ trigger: "Theme", light: "Light", dark: "Dark", system: "System" }Menu variant: the trigger's name and tooltip, and the three options.
iconOnly?booleanfalseButton variant: a 44px square icon button (the aria-label still names it).
align?"start" | "end""end"Menu variant: which edge the menu lines up with (default "end", for a header's right side).
storageKey?stringCRUISE_THEME_KEYMust match CruiseThemeScript's.
onChange?((on: boolean) => void)—Called with whether dark mode is on, after it's applied and saved.
className?string——

Usage

  • Put CruiseThemeScript in the root layout's <head>, then CruiseThemeToggle wherever the button goes. Every toggle on the page stays in step.
  • `variant="menu"`: a 44px square icon button showing the current choice (sun = light, moon = dark, monitor = system), named "Theme" with a "Theme" tooltip. It opens a Dropdown menu with Light, Dark and System as radio items (the chosen one has a check); arrows, Enter and Esc work. System follows prefers-color-scheme and updates live when the device switches. `align` (default "end") lines the menu up with the trigger; `menuLabels` changes the words.
  • `buttonVariant` sets the button style in both variants (default "secondary"). Older code that passed a style as `variant` (e.g. variant="ghost") still works.
  • `labels` changes the text, e.g. { dark: "NEPA mode", light: "Light mode" } in Pidgin mode. `iconOnly` makes a 44px square icon button.
  • `useCruiseDarkMode()` tells a client component whether dark mode is on; `useCruiseThemeChoice()` gives the saved choice ("light", "dark" or "system"); `setCruiseTheme(choice)` and `setCruiseDarkMode(on)` switch and save it from your own code.

Accessibility

  • Button: the aria-label is always "Toggle dark mode" (spec rule 11) and aria-pressed says whether it's on.
  • Menu: the trigger is named "Theme"; the options are menuitemradio with aria-checked, so the current choice is announced.
  • Icons are hidden from screen readers.