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

tailwind-theme-cursor-switch

v1.0.0

Published

A Tailwind CSS theme switcher that toggles dark/light mode when clicking in the top-left corner

Readme

tailwind-theme-cursor-switch

A Tailwind CSS theme switcher that toggles dark/light mode when clicking in the top-left corner of the screen. Perfect for creating a subtle, cursor-based theme switching experience in your web applications.

Features

  • 🔄 Toggle theme by clicking in the top-left corner (50x50px zone)
  • 🌓 Automatically syncs with system dark/light mode preference
  • 💾 Persists theme preference in localStorage
  • 🔄 Syncs theme across browser tabs
  • 🎯 Zero dependencies (except Tailwind CSS)
  • 📦 ESM-compatible
  • 🎨 Works with Tailwind CSS's darkMode: 'class' configuration

Installation

npm install tailwind-theme-cursor-switch

Usage

  1. First, ensure your Tailwind CSS configuration has darkMode: 'class':
// tailwind.config.js
module.exports = {
  darkMode: 'class',
  // ... rest of your config
}
  1. Import and initialize the theme switcher in your JavaScript/TypeScript:
// Using ES modules
import { initThemeCursorToggle } from 'tailwind-theme-cursor-switch';

// Initialize the theme switcher
initThemeCursorToggle();

Or using CommonJS:

const { initThemeCursorToggle } = require('tailwind-theme-cursor-switch');

initThemeCursorToggle();
  1. That's it! The theme will now toggle when users click in the top-left corner of the screen.

React Usage

You can use this package in React applications in two ways:

  1. Basic Usage (Recommended)

    Initialize the theme switcher in your app's entry point (e.g., main.tsx or App.tsx):

    // src/main.tsx or src/App.tsx
    import { initThemeCursorToggle } from 'tailwind-theme-cursor-switch';
    import { useEffect } from 'react';
    
    function App() {
      useEffect(() => {
        initThemeCursorToggle();
      }, []);
    
      return (
        // Your app content
      );
    }
  2. Custom Hook Usage

    Create a custom hook for more control:

    // src/hooks/useThemeCursor.ts
    import { useEffect } from 'react';
    import { initThemeCursorToggle, Theme } from 'tailwind-theme-cursor-switch';
    
    export function useThemeCursor() {
      useEffect(() => {
        const cleanup = initThemeCursorToggle();
        return () => {
          // Cleanup event listeners if needed
          cleanup?.();
        };
      }, []);
    }
    
    // Usage in your component:
    function App() {
      useThemeCursor();
      return (
        // Your app content
      );
    }
  3. With Next.js

    For Next.js applications, initialize in your _app.tsx or layout.tsx:

    // src/app/layout.tsx (App Router)
    'use client';
       
    import { useEffect } from 'react';
    import { initThemeCursorToggle } from 'tailwind-theme-cursor-switch';
    
    export default function RootLayout({
      children,
    }: {
      children: React.ReactNode;
    }) {
      useEffect(() => {
        initThemeCursorToggle();
      }, []);
    
      return (
        <html lang="en">
          <body>{children}</body>
        </html>
      );
    }

    Or with Pages Router:

    // src/pages/_app.tsx
    import { useEffect } from 'react';
    import { initThemeCursorToggle } from 'tailwind-theme-cursor-switch';
    
    function MyApp({ Component, pageProps }) {
      useEffect(() => {
        initThemeCursorToggle();
      }, []);
    
      return <Component {...pageProps} />;
    }
    
    export default MyApp;

React + Tailwind Setup

  1. Ensure your Tailwind configuration is set up correctly:

    // tailwind.config.js
    /** @type {import('tailwindcss').Config} */
    module.exports = {
      darkMode: 'class',
      content: [
        './src/**/*.{js,jsx,ts,tsx}',
      ],
      // ... rest of your config
    }
  2. Add dark mode styles to your global CSS:

    /* src/index.css or src/styles/globals.css */
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
    
    /* Optional: Add smooth transitions for theme changes */
    * {
      @apply transition-colors duration-200;
    }

How it Works

  • The package creates a 50x50px trigger zone in the top-left corner of the screen
  • When a user clicks within this zone, the theme toggles between dark and light mode
  • The theme preference is stored in localStorage under the key 'tailwind-theme-preference'
  • On initial load, it checks localStorage for a saved preference, falling back to system preference
  • Theme changes are synced across browser tabs using the storage event
  • The package automatically handles adding/removing the dark class on the documentElement

TypeScript Support

The package includes TypeScript definitions. The main type export is:

type Theme = 'dark' | 'light';

Browser Support

This package works in all modern browsers that support:

  • ES Modules
  • localStorage
  • matchMedia
  • classList

License

MIT