React Theme Toggle

A modern, accessible dark/light theme toggle for React.

Current theme: light

Usage

import { ToggleTheme } from "react-theme-toggle";

function App() {
  const [theme, setTheme] = useState("light");

  return (
    <ToggleTheme
      selectedTheme={theme}
      onChange={setTheme}
    />
  );
}

Props

PropTypeDescription
selectedTheme"light" | "dark"The currently selected theme.
onChange(theme: Theme) => voidCalled with the new theme on toggle.
idstringInput id. Default "toggle-theme-switch".
classNamestringExtra classes for the visual toggle.
sizenumberTrack width in px. Default 70.
disabledbooleanDisables the toggle.
ariaLabelstringAccessible label. Default "Toggle theme".