---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Color mode toggle

The app's light and dark mode switch, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `ColorModeToggle`.

## Try it

Press the moon or the sun, the labelled toggle, or pick System, Light or Dark in the menu: the sample app beside them switches, and all three controls stay in step; the sample’s line says while the menu is open.

The controls hold the sample’s mode, not the page’s, and keep nothing in storage; a light sample cannot be drawn inside a dark page.

## When to use

- The app's light and dark mode switch.
- Also called: dark mode toggle or theme switcher.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Color mode toggle on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/meadow-color-mode-toggle.json --yes
```

```text
Add the Goop Color mode toggle to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { ColorModeMenu, ColorModeToggle, useColorMode } from '@/components/ui/goop/color-mode-toggle';
import { TopBar, TopBarAction, TopBarGroup, TopBarRow, TopBarTitle } from '@/components/ui/goop/top-bar';

function NotesBar() {
  const { mode } = useColorMode();
  return (
    <TopBar>
      <TopBarRow>
        <TopBarGroup>
          <TopBarTitle>Field notes ({mode})</TopBarTitle>
        </TopBarGroup>
        <TopBarGroup align="end">
          <TopBarAction icon="search" aria-label="Search notes" />
          <ColorModeToggle />
          <ColorModeMenu />
        </TopBarGroup>
      </TopBarRow>
    </TopBar>
  );
}
```

- Fits: frame, settings (their recipes).
- Also known as: ThemeToggle, ModeToggle, DarkModeToggle, ThemeSwitcher.
- Every light/dark control is this one, ColorModeMenu or the account menu's AccountMenuColorMode, never a Switch or an IconButton wired to the class by hand (it would forget the system's setting). In a top bar it stands among the bar's actions (`TopBarAction`s), the same 28 px quiet button.
- width, padding, gap, background, text: add no class for these.

## API reference

### Options

- `aria-label?: string` — The icon toggle's name, the same in both modes (its pressed state says which): "Dark mode" when left out.
- `iconOnly?: boolean` — The icon alone (the default); `false` writes words beside it: the mode a press shows ("Dark" while light, "Light" while dark), which name the button.
- `words?: ColorModeWords` — The words, each replaceable.
- `value?: 'light' | 'dark'` — The mode, held by the caller (with `onValueChange`); with this and `defaultValue` left out, the page's own.
- `defaultValue?: ColorMode` — The page's starting mode while no choice is kept (the system's when left out); a kept choice beats it.
- `onValueChange?: (value: 'light' | 'dark') => void` — Called with the mode a press asks for; the page's mode changes only when the toggle is left to the page.
- `type?: 'button' | 'submit' | 'reset'`
- `onClick?: (event: MouseEvent) => void`
- `disabled?: boolean`

- Takes every prop of IconButton but aria-pressed and children (its page: icon-button.md)
- State: value (value / defaultValue / onValueChange)
- Types: ColorModeWords = { system?: string; light?: string; dark?: string }

### Parts

- `ColorModeMenu` — The three-way choice; its props: color-mode-toggle--color-mode-menu.md

- useColorMode
- data-slot values (to select a part by): color-mode-menu, color-mode-toggle

### ColorModeMenu

The three-way choice.

```tsx
import { ColorModeMenu } from '@/components/ui/goop/color-mode-toggle';
```

### Options

- aria-label?: string — The trigger's name: "Appearance" when left out.
- words?: ColorModeWords — The rows' words, each replaceable.
- value?: 'system' | 'light' | 'dark' — The choice, held by the caller (with `onValueChange`); with this and `defaultValue` left out, the page's own.
- defaultValue?: ColorModeChoice — The page's starting choice while none is kept (`system` when left out); a kept choice beats it.
- onValueChange?: (value: 'system' | 'light' | 'dark') => void — Called with the row picked; the page's mode changes only when the menu is left to the page.
- open?: boolean — The menu open, held by the caller (with `onOpenChange`).
- defaultOpen?: boolean — Open when it first draws.
- onOpenChange?: (open: boolean) => void — Called as the menu opens and closes.
- container?: HTMLElement | null — Where the menu is portalled; the end of `<body>` when left out.
- Also takes: type?: 'button' | 'submit' | 'reset'; onClick?: (event: MouseEvent) => void; disabled?: boolean; tooltip?: string | false; tooltipKeys?: readonly string[]; loading?: boolean = false; loadingLabel?: string = 'Loading'
- Types: ColorModeWords = { system?: string; light?: string; dark?: string }

## Keyboard

- Enter: switch to the other mode (the menu: open it)
- Space: switch to the other mode (the menu: open it)
- ArrowDown / ArrowUp: in the open menu: move between System, Light and Dark
- Escape: close the menu, the focus back on its button

## Accessibility

- The part itself answers the keys above.
- hover, active, focus-within: the browser's own (:hover, :active, :focus-within): write nothing
- pressed: the attribute aria-pressed
- disabled: the prop disabled

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Top bar](/themes/meadow/components/top-bar): The bar across the top of a page, with its breadcrumbs and title at its start and its page-level controls at its end.
- [Menu button](/themes/meadow/components/menu-button): The button a menu opens from, shown as words, a workspace's tile or an icon.
- [Copy button](/themes/meadow/components/copy-button): A button that copies a value such as a link, a key or a command to the clipboard and says it was copied in place.
- [Link](/themes/meadow/components/link): A text link to another page or place.
