npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@repomadness/theme-toggle

v0.0.4

Published

A custom theme toggle and provider for React apps

Readme

repomadness theme toggle 🌗

theme toggle component image

A lightweight, framework-agnostic custom theme toggle and theme provider for React apps, powered by global CSS variables and the data-theme attribute for easy theming. Designed to isolate styling framework and app logic.

theme toggle demo

features

  • easy plug-and-play in any React app
  • toggles between light and dark modes
  • global CSS variaables via data-theme on document.documentElement
  • shared theme state across components with no need for a global state manager
  • CSS framework agnostic - works with plain CSS or any styling solution

installation

Peer dependencies:

  • react
  • react-dom
  • motion
npm install @repomadness/theme-toggle

usage

This package contains:

  • <ThemeProvider /> - wrapper to apply theme based on the data-theme attribute
  • <ThemeToggle /> - toggle switch that controls the theme state globally
  • useTheme() - hook to programmatically access theme

ThemeProvider

Wrap your app with the ThemeProvider to apply the data-theme attribute (light or dark) to the <html> tag and manage your CSS variable state globally.

// main.tsx or App.tsx
import { ThemeProvider } from "@repomadness/theme-toggle";

<ThemeProvider>
  <App />
</ThemeProvider>;

ThemeToggle

Give your app consumers the ability to control the theme state by adding the ThemeToggle component anywhere in your app.

// Settings.tsx
import { ThemeToggle } from "@repomadness/theme-toggle";

export default function Settings() {
  return (
    <div>
      <h1>App settings</h1>
      <ThemeToggle />
    </div>
  );
}

useTheme()

You can use the useTheme() hook to programmatically access the theme.

import { useTheme } from "@repomadness/theme-toggle";

const { theme, toggleTheme } = useTheme();

console.log(theme); // "light" or "dark"
toggleTheme(); // manually switch theme

style with CSS variables

Use [data-theme="light"] and [data-theme="dark"] to define your themes.

:root {
  --color-bg: white;
  --color-text: black;
}

[data-theme="dark"] {
  --color-bg: black;
  --color-text: white;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
}

development

To run locally:

npm install

To run Storybook dev:

npm run storybook

Component and functional testing with Chromatic configured in chromatic.config.json. Tests can be ran locally via Visual Tests addon in Storybook.

For now, manual publishing to npm through CLI:

npm version patch
npm publish