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 🙏

© 2026 – Pkg Stats / Ryan Hefner

themeflip

v0.2.0

Published

A lightweight React theme toggle for light, dark, and system themes.

Readme

themeflip

A lightweight React theme toggle for light, dark, and system themes.

Requirements

  • React 18+

Install

npm install themeflip

Usage

import { ThemeToggle } from "themeflip";

export default function App() {
  return <ThemeToggle />;
}

For Tailwind dark mode:

<ThemeToggle addDarkClass />

Styling

themeflip is unstyled, so you can use Tailwind, vanilla CSS, CSS Modules, or any other styling system.

<ThemeToggle
  className="theme-toggle"
  buttonClassName="theme-toggle-button"
  activeButtonClassName="active"
/>

Data attributes

The component exposes data attributes so you can style it without depending on a specific CSS framework.

[data-theme-toggle] {
  display: flex;
}

[data-theme-option][data-active="true"] {
  font-weight: bold;
}

[data-theme-indicator][data-theme="dark"] {
  transform: translateX(200%);
}

Available attributes include:

  • data-theme-toggle — root element
  • data-theme-indicator — active-theme indicator
  • data-theme="system | light | dark" — current selected theme
  • data-theme-option="system | light | dark" — individual theme button
  • data-active="true | false" — whether a theme button is selected

Props

  • defaultTheme"light", "dark", or "system"
  • storageKey — localStorage key, defaults to "theme"
  • addDarkClass — adds/removes the dark class on <html>
  • onThemeChange — called when the selected theme changes
  • system, light, dark — customize labels and icons
  • className
  • indicatorClassName
  • buttonClassName
  • activeButtonClassName

Framework notes

Avoiding theme flicker

To apply the correct theme before React loads, you can optionally add this script near the top of your <head>:

<script>
  (function () {
    try {
      var t = localStorage.getItem("theme");
      var d =
        t === "dark" ||
        (t !== "light" &&
          window.matchMedia("(prefers-color-scheme: dark)").matches);

      document.documentElement.classList.toggle("dark", d);
    } catch (e) {}
  })();
</script>

This is useful when using addDarkClass and helps avoid a brief light-theme flash while the page loads.

If you use a custom storageKey, replace "theme" in the script with the same key.

Astro

When using Astro, render the toggle as a client-only React island:

<ThemeToggle client:only="react" />

Breaking changes (v0.2.0)

  • Changed the default theme from "auto" to "system"
  • Renamed the auto prop to system for consistency

License

MIT