meowerse_
docs menu

ThemeToggle

A 44 px button that switches between the dark and light themes and remembers the choice.

import { ThemeToggle } from "@meowerse/ui"; · source packages/ui/src/components/ThemeToggle.tsx

variants and states

server render — shows the dark-theme icon until it hydrates

try it

switches this whole site's theme, like the one in the header
demo source
tsx
import { ThemeToggle } from "@meowerse/ui";

export default function Demo() {
  return <div className="demo btn-row"><ThemeToggle /><span className="mw-muted">switches this whole site's theme, like the one in the header</span></div>;
}

props

proptypedefaultrequired
classNamestring extra class names to append.—no

css custom properties

variabledarklight
--c-fg#ededeb#1a1a1c
--c-fg-muted#b3b3af#46464a
--c-line#232326#cfcec8
--c-surface#151517#dfded9
--r-m4pxsame

Classes: .mw-themetoggle. Set any of these variables on an ancestor (or wrap a subtree in .mw-theme--dark / .mw-theme--light) to restyle just that part of a page.

usage

server render

tsx
import { ThemeToggle } from "@meowerse/ui";

<ThemeToggle />

accessibility

  • Its name says what pressing it does: "switch to light theme" or "switch to dark theme".
  • The choice is stored per site under mw-theme.
keydoes
Tabfocuses it
Enter or Spaceswitches the theme

do and don't

do

  • Put it in the header, at the end.

don't

  • Don't hide the theme choice in a menu.